DefaultService implements Service<ENTITY, ENTITYLIST, KEY> { @Override public PagedResult<ENTITY> getEntities(final MultiplePagedSearch<ENTITYLIST> search) { Map<String, Object> parameters = parametersExtractor.getParameters(search.getEntity()); search.setParameters(parameters); return dao.getEntities(search); }  @Override void createEntity(final ENTITY entity); @Override ENTITY getEntity(final KEY id); @Override void updateEntity(final ENTITY entity); @Override void removeEntity(final ENTITY entity); @Override PagedResult<ENTITY> getEntities(final MultiplePagedSearch<ENTITYLIST> search); void setDao(final DAO defaultDao); void setParametersExtractor(final ParametersExtractor<ENTITYLIST> parametersExtractor); DAO getDao(); ParametersExtractor<ENTITYLIST> getParametersExtractor();  }
@Test public void testGetEntities() throws Exception { Integer offset = 0; Integer limit = 20; Department entity1 = new Department(); Map<String, Object> parameters = Collections.<String, Object>singletonMap("some key", "some value"); Class<Department> clazz = Department.class; MultiplePagedSearch<Department> search = new MultiplePagedSearch<Department>(offset, limit, null, clazz); search.setEntity(entity1); long count = 100; List<Department> entities = Arrays.asList(entity1); PagedResult<Department> expected = new PagedResult<Department>(offset, limit, count, entities); when(parametersExtractor.getParameters(any(Department.class))).thenReturn(parameters); when(defaultDao.getEntities(Matchers.<MultiplePagedSearch<Department>>any())).thenReturn(expected); PagedResult<Department> actual = unit.getEntities(search); verify(parametersExtractor).getParameters(entity1); verify(defaultDao).getEntities(search); assertEquals(expected, actual); }