pull/695/head
Mattia Iavarone 6 years ago
parent f2593d4061
commit b2fd6f3f8a
  1. 4
      .github/workflows/build.yml
  2. 31
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/markers/MarkerLayoutTest.java

@ -39,8 +39,8 @@ jobs:
strategy: strategy:
matrix: matrix:
# TODO 28 fails in MarkerLayoutTest.testOnEvent() - weird FrameLayout.onMeasure crash # TODO 28 fails in MarkerLayoutTest.testOnEvent() - weird FrameLayout.onMeasure crash
# 22, 23, 24, 25, 27, 28 # 22, 23, 24, 25, 27, 28? 26? 29?
EMULATOR_API: [26, 29] EMULATOR_API: [29]
EMULATOR_ARCH: [x86_64] EMULATOR_ARCH: [x86_64]
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1

@ -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());
} }
});
}
} }

Loading…
Cancel
Save