package io.fotoapparat.routine;

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

import io.fotoapparat.hardware.CameraDevice;
import io.fotoapparat.photo.Photo;

import static io.fotoapparat.lens.FocusResultState.FAILURE;
import static io.fotoapparat.lens.FocusResultState.SUCCESS;
import static io.fotoapparat.lens.FocusResultState.SUCCESS_NEEDS_EXPOSURE_MEASUREMENT;
import static io.fotoapparat.test.TestUtils.resultOf;
import static junit.framework.Assert.assertEquals;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.times;

@RunWith(MockitoJUnitRunner.class)
public class TakePictureTaskTest {

    static final Photo PHOTO = Photo.empty();

    @Mock
    CameraDevice cameraDevice;

    @InjectMocks
    TakePictureTask testee;

    @Before
    public void setUp() throws Exception {
        given(cameraDevice.takePicture())
                .willReturn(PHOTO);
    }

    @Test
    public void noFocusAfter3Attempts_takePicture() throws Exception {
        // Given
        given(cameraDevice.autoFocus())
                .willReturn(FAILURE);

        // When
        Photo result = resultOf(testee);

        // Then
        InOrder inOrder = inOrder(cameraDevice);
        inOrder.verify(cameraDevice, times(3)).autoFocus();
        inOrder.verify(cameraDevice).takePicture();
        inOrder.verify(cameraDevice).startPreview();

        assertEquals(result, PHOTO);
    }

    @Test
    public void exposureMeasurementRequired_takePhoto() throws Exception {
        // Given
        given(cameraDevice.autoFocus())
                .willReturn(SUCCESS_NEEDS_EXPOSURE_MEASUREMENT);

        // When
        Photo result = resultOf(testee);

        // Then
        InOrder inOrder = inOrder(cameraDevice);
        inOrder.verify(cameraDevice).autoFocus();
        inOrder.verify(cameraDevice).measureExposure();
        inOrder.verify(cameraDevice).takePicture();
        inOrder.verify(cameraDevice).startPreview();

        assertEquals(result, PHOTO);
    }

    @Test
    public void takePhoto() throws Exception {
        // Given
        given(cameraDevice.autoFocus())
                .willReturn(SUCCESS);

        // When
        Photo result = resultOf(testee);

        // Then
        InOrder inOrder = inOrder(cameraDevice);
        inOrder.verify(cameraDevice).autoFocus();
        inOrder.verify(cameraDevice).takePicture();
        inOrder.verify(cameraDevice).startPreview();

        assertEquals(result, PHOTO);
    }
}
@@ -294,51 +294,8 @@
 ort 
-io.fotoapparat.photo.Photo;%0A%0Aimport static 
 io.f
@@ -330,16 +330,8 @@
 tate
-.FAILURE
 ;%0Aim
@@ -327,39 +327,32 @@
 ltState;%0Aimport 
-static 
 io.fotoapparat.l
@@ -354,125 +354,21 @@
 rat.
-lens.FocusResultState.SUCCESS;%0Aimport static io.fotoapparat.lens.FocusResultState.SUCCESS_NEEDS_EXPOSURE_MEASUREMENT;
+photo.Photo;%0A
 %0Aimp
@@ -1114,15 +1114,41 @@
 urn(
-FAILURE
+new FocusResultState(false, true)
 );%0A%0A
@@ -1654,42 +1654,40 @@
 urn(
-SUCCESS_NEEDS_EXPOSURE_MEASUREMENT
+new FocusResultState(true, true)
 );%0A%0A
@@ -2211,15 +2211,41 @@
 urn(
-SUCCESS
+new FocusResultState(true, false)
 );%0A%0A

Fix test