PatientValidator { @NotNull @VisibleForTesting static List<ValidationFinding> validateDrugData(@NotNull String patientIdentifier, @NotNull DrugData drugData, @NotNull FormStatus formStatus) { LocalDate drugStart = drugData.startDate(); List<ValidationFinding> findings = Lists.newArrayList(); if (drugStart == null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Drug start date empty or in wrong format", formStatus)); } else { LocalDate drugEnd = drugData.endDate(); if (drugEnd != null) { if (drugStart.isAfter(drugEnd)) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Drug start date is after drug end date", formStatus)); } } } if (drugData.name() == null) { findings.add(ValidationFinding.of(ECRF_LEVEL, patientIdentifier, "Drug name empty", formStatus)); } return findings; }  @NotNull static List<ValidationFinding> validatePatient(@NotNull Patient patient);  }
@Test public void reportsMissingDrugData() { List<ValidationFinding> findings = PatientValidator.validateDrugData(PATIENT_IDENTIFIER, DRUG_NULL, FormStatus.undefined()); assertEquals(2, findings.size()); findings.stream().map(ValidationFinding::patientIdentifier).forEach(id -> assertEquals(PATIENT_IDENTIFIER, id)); }
@Test public void reportsIncorrectDrugData() { List<ValidationFinding> findings = PatientValidator.validateDrugData(PATIENT_IDENTIFIER, DRUG_WRONG, FormStatus.undefined()); assertEquals(2, findings.size()); findings.stream().map(ValidationFinding::patientIdentifier).forEach(id -> assertEquals(PATIENT_IDENTIFIER, id)); }