CameraFlashRequirement implements Requirement { @NonNull @Override public RequirementReport check() { boolean result = true; String details = ""; try { Camera.Parameters parameters = mCameraHolder.getCameraParameters(); if (parameters != null) { List<String> supportedFlashModes = parameters.getSupportedFlashModes(); if (supportedFlashModes == null || !supportedFlashModes.contains( Camera.Parameters.FLASH_MODE_ON)) { result = false; details = "Camera does not support flash"; } } else { result = false; details = "Camera not open"; } } catch (RuntimeException e) { result = false; details = "Camera exception: " + e.getMessage(); } return new RequirementReport(getId(), result, details); } CameraFlashRequirement(CameraHolder cameraHolder); @NonNull @Override RequirementId getId(); @NonNull @Override RequirementReport check();  }
@Test public void should_reportUnfulfilled_ifFlash_isNotSupported() { CameraHolder cameraHolder = getCameraHolder(false); CameraFlashRequirement requirement = new CameraFlashRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); }
@Test public void should_reportFulfilled_ifFlash_isSupported() { CameraHolder cameraHolder = getCameraHolder(true); CameraFlashRequirement requirement = new CameraFlashRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isTrue(); }
@Test public void should_reportUnfulfilled_ifCamera_isNotOpen() { CameraHolder cameraHolder = mock(CameraHolder.class); CameraFlashRequirement requirement = new CameraFlashRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); }