DiseaseConfigurationFacadeEjb implements DiseaseConfigurationFacade { @Override public List<Disease> getAllDiseases(Boolean active, Boolean primary, Boolean caseBased) { User currentUser = userService.getCurrentUser(); Set<Disease> diseases = new HashSet<>(); if (currentUser.getLimitedDisease() == null) { if (Boolean.TRUE.equals(active)) { diseases.addAll(activeDiseases); } else if (Boolean.FALSE.equals(active)) { diseases.addAll(inactiveDiseases); } if (Boolean.TRUE.equals(primary)) { diseases.retainAll(primaryDiseases); } else if (Boolean.FALSE.equals(primary)) { diseases.retainAll(nonPrimaryDiseases); } if (Boolean.TRUE.equals(caseBased)) { diseases.retainAll(caseBasedDiseases); } else if (Boolean.FALSE.equals(caseBased)) { diseases.retainAll(aggregateDiseases); } } else if (active != null || primary != null || caseBased != null) { Disease limitedDisease = currentUser.getLimitedDisease(); if ((active == null || (Boolean.TRUE.equals(active) && activeDiseases.contains(limitedDisease)) || (Boolean.FALSE.equals(active) && inactiveDiseases.contains(limitedDisease))) && (primary == null || (Boolean.TRUE.equals(primary) && primaryDiseases.contains(limitedDisease)) || (Boolean.FALSE.equals(primary) && nonPrimaryDiseases.contains(limitedDisease))) && (caseBased == null || (Boolean.TRUE.equals(caseBased) && caseBasedDiseases.contains(limitedDisease)) || (Boolean.FALSE.equals(caseBased) && aggregateDiseases.contains(limitedDisease)))) { diseases.add(limitedDisease); } } List<Disease> diseaseList = new ArrayList<>(diseases); diseaseList.sort((d1, d2) -> d1.toString().compareTo(d2.toString())); return diseaseList; }  @Override List<DiseaseConfigurationDto> getAllAfter(Date date); @Override List<DiseaseConfigurationDto> getByUuids(List<String> uuids); @Override List<String> getAllUuids(); @Override boolean isActiveDisease(Disease disease); @Override List<Disease> getAllDiseases(Boolean active, Boolean primary, Boolean caseBased); @Override List<Disease> getAllDiseasesWithFollowUp(Boolean active, Boolean primary, Boolean caseBased); @Override List<Disease> getAllActiveDiseases(); @Override boolean isPrimaryDisease(Disease disease); @Override List<Disease> getAllPrimaryDiseases(); @Override boolean hasFollowUp(Disease disease); @Override List<Disease> getAllDiseasesWithFollowUp(); @Override int getFollowUpDuration(Disease disease); @Override void saveDiseaseConfiguration(DiseaseConfigurationDto configuration); @Override Disease getDefaultDisease(); static DiseaseConfigurationDto toDto(DiseaseConfiguration source); DiseaseConfiguration fromDto(@NotNull DiseaseConfigurationDto source); DiseaseConfigurationDto getDiseaseConfiguration(Disease disease); @PostConstruct void loadData();  }
@Test public void testGetAllDiseases() { creator.updateDiseaseConfiguration(Disease.EVD, true, true, true); creator.updateDiseaseConfiguration(Disease.CHOLERA, true, false, true); creator.updateDiseaseConfiguration(Disease.DENGUE, false, true, true); creator.updateDiseaseConfiguration(Disease.LASSA, false, false, false); creator.updateDiseaseConfiguration(Disease.DIPHTERIA, true, false, false); creator.updateDiseaseConfiguration(Disease.MALARIA, true, true, false); getBean(DiseaseConfigurationFacadeEjbLocal.class).loadData(); List<Disease> diseases = getDiseaseConfigurationFacade().getAllDiseases(true, true, true); assertTrue(diseases.contains(Disease.EVD)); assertFalse(diseases.contains(Disease.CHOLERA)); assertFalse(diseases.contains(Disease.DENGUE)); assertFalse(diseases.contains(Disease.LASSA)); assertFalse(diseases.contains(Disease.DIPHTERIA)); assertFalse(diseases.contains(Disease.MALARIA)); diseases = getDiseaseConfigurationFacade().getAllDiseases(true, true, null); assertTrue(diseases.contains(Disease.EVD)); assertFalse(diseases.contains(Disease.CHOLERA)); assertFalse(diseases.contains(Disease.DENGUE)); assertFalse(diseases.contains(Disease.LASSA)); assertFalse(diseases.contains(Disease.DIPHTERIA)); assertTrue(diseases.contains(Disease.MALARIA)); diseases = getDiseaseConfigurationFacade().getAllDiseases(true, false, null); assertFalse(diseases.contains(Disease.EVD)); assertTrue(diseases.contains(Disease.CHOLERA)); assertFalse(diseases.contains(Disease.DENGUE)); assertFalse(diseases.contains(Disease.LASSA)); assertTrue(diseases.contains(Disease.DIPHTERIA)); assertFalse(diseases.contains(Disease.MALARIA)); diseases = getDiseaseConfigurationFacade().getAllDiseases(false, true, null); assertFalse(diseases.contains(Disease.EVD)); assertFalse(diseases.contains(Disease.CHOLERA)); assertTrue(diseases.contains(Disease.DENGUE)); assertFalse(diseases.contains(Disease.LASSA)); assertFalse(diseases.contains(Disease.DIPHTERIA)); assertFalse(diseases.contains(Disease.MALARIA)); diseases = getDiseaseConfigurationFacade().getAllDiseases(true, null, true); assertTrue(diseases.contains(Disease.EVD)); assertTrue(diseases.contains(Disease.CHOLERA)); assertFalse(diseases.contains(Disease.DENGUE)); assertFalse(diseases.contains(Disease.LASSA)); assertFalse(diseases.contains(Disease.DIPHTERIA)); assertFalse(diseases.contains(Disease.MALARIA)); diseases = getDiseaseConfigurationFacade().getAllDiseases(null, null, null); assertTrue(diseases.isEmpty()); }