Add some unit tests

pull/19/head
Mattia Iavarone 7 years ago
parent c0142c11a9
commit 0a1d4d709d
  1. 3
      .travis.yml
  2. 3
      cameraview/build.gradle
  3. 5
      cameraview/src/main/java/com/otaliastudios/cameraview/ExtraProperties.java
  4. 27
      cameraview/src/test/java/com/otaliastudios/cameraview/ExtraPropertiesTest.java
  5. 54
      cameraview/src/test/java/com/otaliastudios/cameraview/Mapper1Test.java
  6. 37
      cameraview/src/test/java/com/otaliastudios/cameraview/SizeTest.java

@ -18,6 +18,9 @@ android:
- android-26 - android-26
- doc-26 - doc-26
script:
- ./gradlew clean connectedCheck testDebugUnitTest
cache: cache:
directories: directories:
- $HOME/.gradle - $HOME/.gradle

@ -31,6 +31,9 @@ android {
} }
dependencies { dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
compile "com.android.support:exifinterface:$supportLibVersion" compile "com.android.support:exifinterface:$supportLibVersion"
compile "com.android.support:support-annotations:$supportLibVersion" compile "com.android.support:support-annotations:$supportLibVersion"
} }

@ -4,6 +4,7 @@ package com.otaliastudios.cameraview;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraCharacteristics;
import android.util.Log;
import android.util.SizeF; import android.util.SizeF;
/** /**
@ -12,8 +13,8 @@ import android.util.SizeF;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class ExtraProperties { public class ExtraProperties {
float verticalViewingAngle; private float verticalViewingAngle;
float horizontalViewingAngle; private float horizontalViewingAngle;
ExtraProperties(Camera.Parameters params) { ExtraProperties(Camera.Parameters params) {
verticalViewingAngle = params.getVerticalViewAngle(); verticalViewingAngle = params.getVerticalViewAngle();

@ -0,0 +1,27 @@
package com.otaliastudios.cameraview;
import android.annotation.TargetApi;
import android.hardware.Camera;
import android.hardware.camera2.CameraCharacteristics;
import android.util.SizeF;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
public class ExtraPropertiesTest {
@Test
public void testConstructor1() {
Camera.Parameters params = mock(Camera.Parameters.class);
when(params.getVerticalViewAngle()).thenReturn(10f);
when(params.getHorizontalViewAngle()).thenReturn(5f);
ExtraProperties e = new ExtraProperties(params);
assertEquals(e.getVerticalViewingAngle(), 10f, 0f);
assertEquals(e.getHorizontalViewingAngle(), 5f, 0f);
}
}

@ -0,0 +1,54 @@
package com.otaliastudios.cameraview;
import android.hardware.Camera;
import org.junit.Test;
import static org.junit.Assert.*;
public class Mapper1Test {
private Mapper mapper = new Mapper.Mapper1();
@Test
public void testMap() {
assertEquals(mapper.map(Flash.OFF), Camera.Parameters.FLASH_MODE_OFF);
assertEquals(mapper.map(Flash.ON), Camera.Parameters.FLASH_MODE_ON);
assertEquals(mapper.map(Flash.AUTO), Camera.Parameters.FLASH_MODE_AUTO);
assertEquals(mapper.map(Flash.TORCH), Camera.Parameters.FLASH_MODE_TORCH);
assertEquals(mapper.map(Facing.BACK), Camera.CameraInfo.CAMERA_FACING_BACK);
assertEquals(mapper.map(Facing.FRONT), Camera.CameraInfo.CAMERA_FACING_FRONT);
assertEquals(mapper.map(Hdr.OFF), Camera.Parameters.SCENE_MODE_AUTO);
assertEquals(mapper.map(Hdr.ON), Camera.Parameters.SCENE_MODE_HDR);
assertEquals(mapper.map(WhiteBalance.AUTO), Camera.Parameters.WHITE_BALANCE_AUTO);
assertEquals(mapper.map(WhiteBalance.DAYLIGHT), Camera.Parameters.WHITE_BALANCE_DAYLIGHT);
assertEquals(mapper.map(WhiteBalance.CLOUDY), Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT);
assertEquals(mapper.map(WhiteBalance.INCANDESCENT), Camera.Parameters.WHITE_BALANCE_INCANDESCENT);
assertEquals(mapper.map(WhiteBalance.FLUORESCENT), Camera.Parameters.WHITE_BALANCE_FLUORESCENT);
}
@Test
public void testUnmap() {
assertEquals(Flash.OFF, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_OFF));
assertEquals(Flash.ON, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_ON));
assertEquals(Flash.AUTO, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_AUTO));
assertEquals(Flash.TORCH, mapper.unmapFlash(Camera.Parameters.FLASH_MODE_TORCH));
assertEquals(Facing.BACK, mapper.unmapFacing(Camera.CameraInfo.CAMERA_FACING_BACK));
assertEquals(Facing.FRONT, mapper.unmapFacing(Camera.CameraInfo.CAMERA_FACING_FRONT));
assertEquals(Hdr.OFF, mapper.unmapHdr(Camera.Parameters.SCENE_MODE_AUTO));
assertEquals(Hdr.ON, mapper.unmapHdr(Camera.Parameters.SCENE_MODE_HDR));
assertEquals(WhiteBalance.AUTO, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO));
assertEquals(WhiteBalance.DAYLIGHT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_DAYLIGHT));
assertEquals(WhiteBalance.CLOUDY, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT));
assertEquals(WhiteBalance.INCANDESCENT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_INCANDESCENT));
assertEquals(WhiteBalance.FLUORESCENT, mapper.unmapWhiteBalance(Camera.Parameters.WHITE_BALANCE_FLUORESCENT));
}
}

@ -0,0 +1,37 @@
package com.otaliastudios.cameraview;
import org.junit.Test;
import static org.junit.Assert.*;
public class SizeTest {
@Test
public void testDimensions() {
Size size = new Size(10, 20);
assertEquals(size.getWidth(), 10f, 0f);
assertEquals(size.getHeight(), 20f, 0f);
assertEquals("10x20", size.toString());
}
@Test
public void testEquals() {
Size s1 = new Size(10, 20);
Size s2 = new Size(10, 0);
Size s3 = new Size(10, 20);
assertTrue(s1.equals(s3));
assertFalse(s1.equals(s2));
}
@Test
public void testCompare() {
Size s1 = new Size(10, 20);
Size s2 = new Size(10, 0);
Size s3 = new Size(10, 20);
assertTrue(s1.compareTo(s3) == 0);
assertTrue(s1.compareTo(s2) > 0);
assertTrue(s2.compareTo(s1) < 0);
}
}
Loading…
Cancel
Save