Fix old tests

pull/37/head
Mattia Iavarone 8 years ago
parent adb65deceb
commit 86aaf5e536
  1. 8
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraControllerIntegrationTest.java
  2. 30
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraViewTest.java
  3. 5
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/MockCameraController.java

@ -318,4 +318,12 @@ public class CameraControllerIntegrationTest extends BaseTest {
} }
//endregion //endregion
// TODO: startVideo, endVideo
// TODO: startAutoFocus
// TODO: capturePicture
// TODO: captureSnapshot
} }

@ -1,16 +1,11 @@
package com.otaliastudios.cameraview; package com.otaliastudios.cameraview;
import android.app.Instrumentation;
import android.content.Context; import android.content.Context;
import android.hardware.Camera;
import android.location.Location; import android.location.Location;
import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.junit.After; import org.junit.After;
@ -34,7 +29,6 @@ public class CameraViewTest extends BaseTest {
private Preview mockPreview; private Preview mockPreview;
private boolean hasPermissions; private boolean hasPermissions;
@Before @Before
public void setUp() { public void setUp() {
ui(new Runnable() { ui(new Runnable() {
@ -107,23 +101,6 @@ public class CameraViewTest extends BaseTest {
assertEquals(cameraView.getGestureAction(Gesture.SCROLL_VERTICAL), GestureAction.DEFAULT_SCROLL_VERTICAL); assertEquals(cameraView.getGestureAction(Gesture.SCROLL_VERTICAL), GestureAction.DEFAULT_SCROLL_VERTICAL);
} }
@Test
public void testStartWithPermissions() {
hasPermissions = true;
cameraView.start();
assertTrue(cameraView.isStarted());
cameraView.stop();
assertFalse(cameraView.isStarted());
}
@Test
public void testStartWithoutPermissions() {
hasPermissions = false;
cameraView.start();
assertFalse(cameraView.isStarted());
}
//endregion //endregion
//region testGesture //region testGesture
@ -177,6 +154,7 @@ public class CameraViewTest extends BaseTest {
@Test @Test
public void testGestureAction_capture() { public void testGestureAction_capture() {
mockController.mockStarted(true);
MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0); MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0);
ui(new Runnable() { ui(new Runnable() {
@Override @Override
@ -195,6 +173,7 @@ public class CameraViewTest extends BaseTest {
@Test @Test
public void testGestureAction_focus() { public void testGestureAction_focus() {
mockController.mockStarted(true);
MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0); MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0);
ui(new Runnable() { ui(new Runnable() {
@Override @Override
@ -219,6 +198,7 @@ public class CameraViewTest extends BaseTest {
@Test @Test
public void testGestureAction_zoom() { public void testGestureAction_zoom() {
mockController.mockStarted(true);
MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0); MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0);
ui(new Runnable() { ui(new Runnable() {
@Override @Override
@ -242,6 +222,7 @@ public class CameraViewTest extends BaseTest {
when(o.getExposureCorrectionMinValue()).thenReturn(-10f); when(o.getExposureCorrectionMinValue()).thenReturn(-10f);
when(o.getExposureCorrectionMaxValue()).thenReturn(10f); when(o.getExposureCorrectionMaxValue()).thenReturn(10f);
mockController.setMockCameraOptions(o); mockController.setMockCameraOptions(o);
mockController.mockStarted(true);
MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0); MotionEvent event = MotionEvent.obtain(0L, 0L, 0, 0f, 0f, 0);
ui(new Runnable() { ui(new Runnable() {
@ -551,7 +532,4 @@ public class CameraViewTest extends BaseTest {
//endregion //endregion
// TODO: test permissions // TODO: test permissions
// TODO: test CameraCallbacks
} }

@ -17,7 +17,6 @@ public class MockCameraController extends CameraController {
MockCameraController(CameraView.CameraCallbacks callback, Preview preview) { MockCameraController(CameraView.CameraCallbacks callback, Preview preview) {
super(callback, preview); super(callback, preview);
mState = CameraController.STATE_STARTED;
} }
void setMockCameraOptions(CameraOptions options) { void setMockCameraOptions(CameraOptions options) {
@ -28,6 +27,10 @@ public class MockCameraController extends CameraController {
mPreviewSize = size; mPreviewSize = size;
} }
void mockStarted(boolean started) {
mState = started ? STATE_STARTED : STATE_STOPPED;
}
@Override @Override
void onStart() throws Exception { void onStart() throws Exception {
} }

Loading…
Cancel
Save