CameraFocusRequirement implements Requirement { @NonNull @Override public RequirementReport check() { boolean fulfilled = true; String details = ""; try { Camera.Parameters parameters = mCameraHolder.getCameraParameters(); if (parameters != null) { List<String> supportedFocusModes = parameters.getSupportedFocusModes(); if (supportedFocusModes == null || !supportedFocusModes.contains( Camera.Parameters.FOCUS_MODE_AUTO)) { fulfilled = false; details = "Camera does not support auto-focus"; } } else { fulfilled = false; details = "Camera not open"; } } catch (RuntimeException e) { fulfilled = false; details = "Camera exception: " + e.getMessage(); } return new RequirementReport(getId(), fulfilled, details); } CameraFocusRequirement(CameraHolder cameraHolder); @NonNull @Override RequirementId getId(); @NonNull @Override RequirementReport check();  }
@Test public void should_reportUnfulfilled_ifAutoFocus_isNotSupported() { CameraHolder cameraHolder = getCameraHolder(false); CameraFocusRequirement requirement = new CameraFocusRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); }
@Test public void should_reportFulfilled_ifAutoFocus_isSupported() { CameraHolder cameraHolder = getCameraHolder(true); CameraFocusRequirement requirement = new CameraFocusRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isTrue(); }
@Test public void should_reportUnfulfilled_ifCamera_isNotOpen() { CameraHolder cameraHolder = mock(CameraHolder.class); CameraFocusRequirement requirement = new CameraFocusRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); }