### Question:
StartCameraRoutine implements Runnable { @Override public void run() { try { tryToStartCamera(); } catch (CameraException e) { cameraErrorCallback.onError(e); } } StartCameraRoutine(CameraDevice cameraDevice,
                              CameraRenderer cameraRenderer,
                              ScaleType scaleType,
                              SelectorFunction<Collection<LensPosition>, LensPosition> lensPositionSelector,
                              ScreenOrientationProvider screenOrientationProvider,
                              InitialParametersProvider initialParametersProvider,
                              CameraErrorCallback cameraErrorCallback); @Override void run();  }### Answer:
@Test public void routine() throws Exception { StartCameraRoutine testee = new StartCameraRoutine( cameraDevice, cameraRenderer, ScaleType.CENTER_INSIDE, lensPositionSelector, screenOrientationProvider, initialParametersProvider, cameraErrorCallback ); List<LensPosition> availableLensPositions = asList( LensPosition.FRONT, LensPosition.BACK ); LensPosition preferredLensPosition = LensPosition.FRONT; ScaleType scaleType = ScaleType.CENTER_INSIDE; givenLensPositionsAvailable(availableLensPositions); givenPositionSelected(preferredLensPosition); givenScreenRotation(); givenInitialParametersAvailable(); testee.run(); InOrder inOrder = inOrder( cameraDevice, cameraRenderer, lensPositionSelector ); inOrder.verify(lensPositionSelector).select(availableLensPositions); inOrder.verify(cameraDevice).open(preferredLensPosition); inOrder.verify(cameraDevice).updateParameters(INITIAL_PARAMETERS); inOrder.verify(cameraDevice).setDisplayOrientation(SCREEN_ROTATION_DEGREES); inOrder.verify(cameraRenderer).setScaleType(scaleType); inOrder.verify(cameraRenderer).attachCamera(cameraDevice); inOrder.verify(cameraDevice).startPreview(); verifyZeroInteractions(cameraErrorCallback); }
@Test public void failedToOpenCamera() throws Exception { List<LensPosition> availableLensPositions = asList( LensPosition.FRONT, LensPosition.BACK ); LensPosition preferredLensPosition = LensPosition.FRONT; givenLensPositionsAvailable(availableLensPositions); givenPositionSelected(preferredLensPosition); doThrow(CAMERA_EXCEPTION) .when(cameraDevice) .open(preferredLensPosition); testee.run(); verify(cameraErrorCallback).onError(CAMERA_EXCEPTION); verify(cameraDevice).getAvailableLensPositions(); verify(cameraDevice).open(preferredLensPosition); verifyNoMoreInteractions(cameraDevice); }