CaseSearchPresenter extends RecordSearchPresenter { @Override protected List<Long> getSearchResult(Map<String, String> searchConditions) { String uniqueId = searchConditions.get(ID); String name = searchConditions.get(NAME); String registrationDate = searchConditions.get(REGISTRATION_DATE); if (PrimeroAppConfiguration.getCurrentUser().getRoleType() == User.Role.CP) { int ageFrom = Integer.valueOf(searchConditions.get(AGE_FROM)); int ageTo = Integer.valueOf(searchConditions.get(AGE_TO)); String caregiver = searchConditions.get(CAREGIVER); return caseService.getCPSearchResult(uniqueId, name, ageFrom, ageTo, caregiver, getDate(registrationDate)); } else { String location = searchConditions.get(LOCATION); return caseService.getGBVSearchResult(uniqueId, name, location, getDate(registrationDate)); } } @Inject  CaseSearchPresenter(CaseService caseService);   }
@Test public void should_get_CP_search_result() throws Exception { List<Long> list = new ArrayList<>(); Map<String, String> searchCondition = mock(Map.class); User user = new User(); user.setRole(User.ROLE_CP); when(PrimeroAppConfiguration.getCurrentUser()).thenReturn(user); when(searchCondition.get(anyString())).thenReturn("0"); when(caseService.getCPSearchResult(anyString(),anyString(),anyInt(),anyInt(),anyString(),any())) .thenReturn(list); assertThat("Should return CP search list", caseSearchPresenter.getSearchResult(searchCondition), is(list)); verify(caseService, times(1)). getCPSearchResult(anyString(), anyString(),anyInt(),anyInt(),anyString(),any()); }
@Test public void should_get_GBV_search_result() throws Exception { List<Long> list = new ArrayList<>(); User user = new User(); user.setRole(User.ROLE_GBV); when(PrimeroAppConfiguration.getCurrentUser()).thenReturn(user); when(caseService.getGBVSearchResult(anyString(),anyString(),anyString(),any())) .thenReturn(list); assertThat("Should return GBV search list", caseSearchPresenter.getSearchResult(Collections.emptyMap()), is(list)); verify(caseService, times(1)).getGBVSearchResult(anyString(),anyString(),anyString(),any()); }