CameraRequirement implements Requirement { @NonNull @Override public RequirementReport check() { boolean result = true; String details = ""; try { if (!mCameraHolder.hasCamera()) { result = false; details = "No back-facing camera found"; } } catch (RuntimeException e) { result = false; details = "Camera could not be opened: " + e.getMessage(); } return new RequirementReport(getId(), result, details); } CameraRequirement(CameraHolder cameraHolder); @NonNull @Override RequirementId getId(); @NonNull @Override RequirementReport check();  }
@Test public void should_reportUnfulfilled_ifCamera_couldNotBeOpened() { CameraHolder cameraHolder = mock(CameraHolder.class); doThrow(new RuntimeException()).when(cameraHolder).hasCamera(); CameraRequirement cameraRequirement = new CameraRequirement(cameraHolder); assertThat(cameraRequirement.check().isFulfilled()).isFalse(); }
@Test public void should_reportUnfulfilled_ifCamera_isNull() { CameraHolder cameraHolder = mock(CameraHolder.class); when(cameraHolder.hasCamera()).thenReturn(false); CameraRequirement cameraRequirement = new CameraRequirement(cameraHolder); assertThat(cameraRequirement.check().isFulfilled()).isFalse(); }
@Test public void should_reportFulfilled_ifCamera_couldBeOpened_andIsNotNull() { CameraHolder cameraHolder = mock(CameraHolder.class); when(cameraHolder.hasCamera()).thenReturn(true); CameraRequirement cameraRequirement = new CameraRequirement(cameraHolder); assertThat(cameraRequirement.check().isFulfilled()).isTrue(); }