package io.fotoapparat.hardware.v2.selection;

import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.hardware.camera2.CameraMetadata;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;

import io.fotoapparat.hardware.CameraException;
import io.fotoapparat.parameter.LensPosition;

import static junit.framework.Assert.assertEquals;
import static org.mockito.BDDMockito.given;

@SuppressWarnings("NewApi")
@RunWith(MockitoJUnitRunner.class)
public class CameraSelectorTest {

	@Mock(answer = Answers.RETURNS_DEEP_STUBS)
	CameraManager manager;
	@InjectMocks
	CameraSelector testee;

	@Before
	public void setUp() throws Exception {
		given(manager.getCameraCharacteristics("0").get(CameraCharacteristics.LENS_FACING))
				.willReturn(CameraMetadata.LENS_FACING_BACK);

		given(manager.getCameraCharacteristics("1").get(CameraCharacteristics.LENS_FACING))
				.willReturn(CameraMetadata.LENS_FACING_FRONT);
	}

	@Test(expected = CameraException.class)
	public void noCameraFound() throws Exception {
		// Given
		given(manager.getCameraIdList())
				.willReturn(new String[]{"0"});

		// When
		testee.findCameraId(LensPosition.EXTERNAL);

		// Then
		// exception
	}

	@Test
	public void getFrontCamera() throws Exception {
		// Given
		given(manager.getCameraIdList())
				.willReturn(new String[]{"0", "1"});

		// When
		String cameraId = testee.findCameraId(LensPosition.FRONT);

		// Then
		assertEquals("1", cameraId);
	}

}
@@ -36,24 +36,79 @@
 selection;%0A%0A
+import android.hardware.camera2.CameraAccessException;%0A
 import andro
@@ -150,16 +150,16 @@
 istics;%0A
-
 import a
@@ -549,24 +549,99 @@
 sPosition;%0A%0A
+import static android.hardware.camera2.CameraAccessException.CAMERA_ERROR;%0A
 import stati
@@ -1193,32 +1193,32 @@
 s.LENS_FACING))%0A
-
 %09%09%09%09.willReturn(
@@ -1252,24 +1252,308 @@
 FRONT);%0A%09%7D%0A%0A
+%09@Test(expected = CameraException.class)%0A%09public void cameraNotAvailable() throws Exception %7B%0A%09%09// Given%0A%09%09given(manager.getCameraIdList())%0A%09%09%09%09.willThrow(new CameraAccessException(CAMERA_ERROR));%0A%0A%09%09// When%0A%09%09testee.findCameraId(LensPosition.EXTERNAL);%0A%0A%09%09// Then%0A%09%09// exception%0A%09%7D%0A%0A
 %09@Test(expec

Add test in camera selector