DeviceMemoryRequirement implements Requirement { @NonNull @Override public RequirementReport check() { boolean result = true; String details = ""; try { final Camera.Parameters parameters = mCameraHolder.getCameraParameters(); if (parameters != null) { final Size pictureSize = SizeSelectionHelper.getLargestAllowedSize( parameters.getSupportedPictureSizes(), CameraResolutionRequirement.MAX_PICTURE_AREA); if (pictureSize == null) { result = false; details = "Cannot determine memory requirement as the camera has no picture resolution with a 4:3 aspect ratio"; } else if (!sufficientMemoryAvailable(pictureSize)) { result = false; details = "Insufficient memory available"; } } else { result = false; details = "Camera not open"; } } catch (final RuntimeException e) { result = false; details = "Camera exception: " + e.getMessage(); } return new RequirementReport(getId(), result, details); } DeviceMemoryRequirement(final CameraHolder cameraHolder); @NonNull @Override RequirementId getId(); @NonNull @Override RequirementReport check();  }
@Test public void should_reportUnfulfilled_ifCamera_isNotOpen() { CameraHolder cameraHolder = mock(CameraHolder.class); DeviceMemoryRequirement requirement = new DeviceMemoryRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isFalse(); }
@Test public void should_reportFulfilled_ifEnoughMemory_isAvailable() { CameraHolder cameraHolder = getCameraHolder( Collections.singletonList(createSize(800, 600))); DeviceMemoryRequirement requirement = new DeviceMemoryRequirement(cameraHolder); assertThat(requirement.check().isFulfilled()).isTrue(); }