|
|
@ -18,22 +18,17 @@ import org.junit.Test; |
|
|
|
import org.mockito.Mockito; |
|
|
|
import org.mockito.Mockito; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.Nullable; |
|
|
|
|
|
|
|
import androidx.test.annotation.UiThreadTest; |
|
|
|
|
|
|
|
import androidx.test.rule.ActivityTestRule; |
|
|
|
import androidx.test.rule.ActivityTestRule; |
|
|
|
|
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.anyFloat; |
|
|
|
import static org.mockito.ArgumentMatchers.anyFloat; |
|
|
|
import static org.mockito.Mockito.doReturn; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.reset; |
|
|
|
import static org.mockito.Mockito.reset; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
import static org.mockito.Mockito.times; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
import static org.mockito.Mockito.when; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Not clear why, but for some reason on API 28 the UiThreadTests here crash for an internal NPE |
|
|
|
* Not clear why, but for some reason on API 28 the UiThreadTests here crash for an internal NPE |
|
|
|
* in FrameLayout.onMeasure. |
|
|
|
* in FrameLayout.onMeasure. Trying with uiSync. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@SdkExclude(minSdkVersion = 28, maxSdkVersion = 28) |
|
|
|
@SdkExclude(minSdkVersion = 28, maxSdkVersion = 28) |
|
|
|
@TargetApi(17) |
|
|
|
@TargetApi(17) |
|
|
@ -60,25 +55,35 @@ public class MarkerLayoutTest extends BaseTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@UiThreadTest |
|
|
|
|
|
|
|
public void testOnMarker_callsOnAttach() { |
|
|
|
public void testOnMarker_callsOnAttach() { |
|
|
|
|
|
|
|
uiSync(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
Mockito.verify(autoFocusMarker, times(1)).onAttach( |
|
|
|
Mockito.verify(autoFocusMarker, times(1)).onAttach( |
|
|
|
Mockito.any(Context.class), |
|
|
|
Mockito.any(Context.class), |
|
|
|
Mockito.eq(markerLayout)); |
|
|
|
Mockito.eq(markerLayout)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@UiThreadTest |
|
|
|
|
|
|
|
public void testOnMarker_addsView() { |
|
|
|
public void testOnMarker_addsView() { |
|
|
|
|
|
|
|
uiSync(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 0); |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 0); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 1); |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@UiThreadTest |
|
|
|
|
|
|
|
public void testOnMarker_removesView() { |
|
|
|
public void testOnMarker_removesView() { |
|
|
|
|
|
|
|
uiSync(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 1); |
|
|
|
Assert.assertEquals(markerLayout.getChildCount(), 1); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
|
markerLayout.onMarker(MarkerLayout.TYPE_AUTOFOCUS, autoFocusMarker); |
|
|
@ -90,10 +95,14 @@ public class MarkerLayoutTest extends BaseTest { |
|
|
|
Mockito.any(Context.class), |
|
|
|
Mockito.any(Context.class), |
|
|
|
Mockito.eq(markerLayout)); |
|
|
|
Mockito.eq(markerLayout)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@UiThreadTest |
|
|
|
|
|
|
|
public void testOnEvent() { |
|
|
|
public void testOnEvent() { |
|
|
|
|
|
|
|
uiSync(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
final View mockView = spy(new View(getContext())); |
|
|
|
final View mockView = spy(new View(getContext())); |
|
|
|
// These fail, however it's not really needed.
|
|
|
|
// These fail, however it's not really needed.
|
|
|
|
// when(mockView.getWidth()).thenReturn(50);
|
|
|
|
// when(mockView.getWidth()).thenReturn(50);
|
|
|
@ -114,4 +123,6 @@ public class MarkerLayoutTest extends BaseTest { |
|
|
|
verify(mockView, times(1)).setTranslationX(anyFloat()); |
|
|
|
verify(mockView, times(1)).setTranslationX(anyFloat()); |
|
|
|
verify(mockView, times(1)).setTranslationY(anyFloat()); |
|
|
|
verify(mockView, times(1)).setTranslationY(anyFloat()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|