// Copyright (c) 2014 Eugene Zhuk.
// Use of this source code is governed by the MIT license that can be found
// in the LICENSE file.

package com.ezhuk.wear.common;

import com.google.android.gms.wearable.DataEvent;

import junit.framework.TestCase;


public class DataListenerTest extends TestCase {
    private static final String DATA_PATH = "/data";

    private static class MockCallback implements DataListener.Callback {
        @Override
        public void onDataChanged(DataEvent event) {
            // empty
        }
    }

    protected void setUp() {
        // empty
    }

    protected void tearDown() {
        // empty
    }

    public void testAddCallback() {
        DataListener listener = new DataListener();
        listener.addCallback(DATA_PATH, new MockCallback());
        assertNotNull(listener.getCallback(DATA_PATH));
    }

    public void testRemoveCallback() {
        DataListener listener = new DataListener();
        listener.addCallback(DATA_PATH, new MockCallback());
        listener.removeCallback(DATA_PATH);
        assertNull(listener.getCallback(DATA_PATH));
    }
}

@@ -161,16 +161,41 @@
 ommon;%0A%0A
+import android.net.Uri;%0A%0A
 import c
@@ -235,16 +235,65 @@
 taEvent;
+%0Aimport com.google.android.gms.wearable.DataItem;
 %0A%0Aimport
@@ -320,16 +320,45 @@
 tCase;%0A%0A
+import org.mockito.Mockito;%0A%0A
 %0Apublic 
@@ -457,190 +457,8 @@
 %22;%0A%0A
-    private static class MockCallback implements DataListener.Callback %7B%0A        @Override%0A        public void onDataChanged(DataEvent event) %7B%0A            // empty%0A        %7D%0A    %7D%0A%0A
     
@@ -642,32 +642,86 @@
 DataListener();%0A
+        assertNull(listener.getCallback(DATA_PATH));%0A%0A
         listener
@@ -744,32 +744,50 @@
 A_PATH, 
-new 
 Mock
+ito.mock(DataListener.
 Callback
 ());%0A   
@@ -770,33 +770,38 @@
 istener.Callback
-(
+.class
 ));%0A        asse
@@ -954,61 +954,195 @@
     
-listener.addCallback(DATA_PATH, new MockCallback(
+assertNull(listener.getCallback(DATA_PATH));%0A%0A        listener.addCallback(DATA_PATH, Mockito.mock(DataListener.Callback.class));%0A        assertNotNull(listener.getCallback(DATA_PATH
 ));%0A
+%0A
     
@@ -1239,11 +1239,683 @@
 );%0A    %7D
+%0A%0A    public void testDataChanged() %7B%0A        DataItem item = Mockito.mock(DataItem.class);%0A        Mockito.when(item.getUri()).thenReturn(Uri.parse(DATA_PATH));%0A%0A        DataEvent event = Mockito.mock(DataEvent.class);%0A        Mockito.when(event.getType()).thenReturn(DataEvent.TYPE_CHANGED);%0A        Mockito.when(event.getDataItem()).thenReturn(item);%0A%0A        DataListener listener = new DataListener();%0A        DataListener.Callback callback = Mockito.mock(DataListener.Callback.class);%0A        listener.addCallback(DATA_PATH, callback);%0A%0A        // TODO%0A%0A        Mockito.verify(callback).onDataChanged(event);%0A        Mockito.verifyNoMoreInteractions(callback);%0A    %7D
 %0A%7D%0A

Use mockito in data listener tests.