RequirementsChecker { RequirementsReport checkRequirements() { boolean result = true; List<RequirementReport> requirementsReports = new ArrayList<>(mRequirements.size()); for (Requirement requirement : mRequirements) { RequirementReport report = requirement.check(); result = result && report.isFulfilled(); requirementsReports.add(report); } return new RequirementsReport(result, requirementsReports); } RequirementsChecker(@NonNull List<? extends Requirement> requirements);   }
@Test public void should_reportFulfilled_ifAllRequirements_wereMet() { final RequirementsChecker checker = new RequirementsChecker(Arrays.asList( new FulfilledRequirement(), new FulfilledRequirement(), new FulfilledRequirement() )); assertThat(checker.checkRequirements().isFulfilled()).isTrue(); }
@Test public void should_reportUnfulfilled_ifAtLeastOneRequirement_wasNotMet() { final RequirementsChecker checker = new RequirementsChecker(Arrays.asList( new FulfilledRequirement(), new FulfilledRequirement(), new UnfulfilledRequirement() )); assertThat(checker.checkRequirements().isFulfilled()).isFalse(); }
@Test public void should_returnReports_forCheckedRequirements() { final RequirementsChecker checker = new RequirementsChecker(Arrays.asList( new FulfilledRequirement(), new UnfulfilledRequirement() )); final RequirementsReport report = checker.checkRequirements(); for (final RequirementReport requirementReport : report.getRequirementReports()) { switch (requirementReport.getRequirementId()) { case CAMERA: assertThat(requirementReport.getRequirementId()).isEqualTo( RequirementId.CAMERA); assertThat(requirementReport.isFulfilled()).isTrue(); assertThat(requirementReport.getDetails()).isEqualTo("fulfilled"); break; case CAMERA_PERMISSION: assertThat(requirementReport.getRequirementId()).isEqualTo( RequirementId.CAMERA_PERMISSION); assertThat(requirementReport.isFulfilled()).isFalse(); assertThat(requirementReport.getDetails()).isEqualTo("unfulfilled"); break; } } }