HospitalModelFactory { @VisibleForTesting static boolean validateModelIntegrity(@NotNull HospitalModel hospitalModel) { Set<String> hospitalIdsInAddressList = hospitalModel.hospitalAddressMap().keySet(); Set<String> keyCPCT = hospitalModel.hospitalPersonsCPCT().keySet(); Set<String> keyDRUP = hospitalModel.hospitalPersonsDRUP().keySet(); Set<String> keyWIDE = hospitalModel.hospitalPersonsWIDE().keySet(); Set<String> keySampleMapping = Sets.newHashSet(hospitalModel.sampleToHospitalMapping().values()); boolean allCorrect = true; for (String CPCT : keyCPCT) { if (!hospitalIdsInAddressList.contains(CPCT)) { allCorrect = false; LOGGER.warn("CPCT hospital ID is not present in hospital address list: '{}'", CPCT); } } for (String DRUP : keyDRUP) { if (!hospitalIdsInAddressList.contains(DRUP)) { allCorrect = false; LOGGER.warn("DRUP hospital ID is not present in hospital address list: '{}'", DRUP); } } for (String WIDE : keyWIDE) { if (!hospitalIdsInAddressList.contains(WIDE)) { allCorrect = false; LOGGER.warn("WIDE hospital ID is not present in hospital address list: '{}'", WIDE); } } for (String sampleMapping : keySampleMapping) { if (!hospitalIdsInAddressList.contains(sampleMapping)) { allCorrect = false; LOGGER.warn("Sample mapping hospital ID is not present in hospital address list: '{}'", sampleMapping); } } return allCorrect; } private  HospitalModelFactory(); @NotNull static HospitalModel fromLimsDirectory(@NotNull String limsDirectory);  }
@Test public void canValidateIntegrityCorrectly() { HospitalModel emptyModel = ImmutableHospitalModel.builder().build(); assertTrue(HospitalModelFactory.validateModelIntegrity(emptyModel)); HospitalModel noAddressModel = ImmutableHospitalModel.builder() .putHospitalPersonsCPCT("HOSP", ImmutableHospitalPersons.builder() .hospitalPI("Test") .requesterName("Test") .requesterEmail("Test") .build()) .build(); assertFalse(HospitalModelFactory.validateModelIntegrity(noAddressModel)); }