DefaultDao implements Dao<ENTITY, ENTITYLIST, KEY> { @Override public PagedResult<ENTITY> getEntities(final MultiplePagedSearch<ENTITYLIST> pagedSearch) { LOG.info("Getting paged result for {}: {}", getEntityClass().getSimpleName(), pagedSearch); String querySql = queryBuilder.build(pagedSearch); Query<ENTITY> queries = new Query<ENTITY>(getEntityClass(), querySql); MultiplePagedQuerySearch<ENTITY> pagedQuerySearch = new MultiplePagedQuerySearch<ENTITY>(queries, pagedSearch.getOffset(), pagedSearch.getLimit(), pagedSearch.getParameters(), getEntityClass()); return persistenceManager.search(pagedQuerySearch); }  @Override ENTITY getEntityById(final KEY id); @Override void save(final ENTITY entity); @Override void update(final ENTITY entity); @Override void delete(final ENTITY entity); @Override ENTITY getByUid(long uid); @Override ENTITY getByUidAndUap(long uid, String uapp); @Override ENTITY getByUidOrUtidAndUap(long uid, String utid, String uapp); @Override ENTITY getByUtid(String utid); @Override PagedResult<ENTITY> getEntities(final MultiplePagedSearch<ENTITYLIST> pagedSearch); ENTITY getSingleResult(Query<ENTITY> query); Class<ENTITY> getEntityClass(); PersistenceManager<ENTITY, KEY> getPersistenceManager(); QueryBuilder<ENTITYLIST> getQueryBuilder(); void setPersistenceManager(final PersistenceManager<ENTITY, KEY> persistenceManager); void setQueryBuilder(final QueryBuilder<ENTITYLIST> queryBuilder); void setEntityClass(final Class<ENTITY> entityClass);  }
@Test public void testGetEntities() throws Exception { Integer offset = 0; Integer limit = 20; Map<String, Object> parameters = Collections.emptyMap(); Class<Department> clazz = Department.class; Department entity1 = new Department(); MultiplePagedSearch<Department> pagedSearch = new MultiplePagedSearch<Department>(offset, limit, parameters, clazz); pagedSearch.setEntity(entity1); long count = 100; List<Department> entities = Arrays.asList(entity1); PagedResult<Department> expected = new PagedResult<Department>(offset, limit, count, entities); String querySql = "query Sql"; Query<Department> queries = new Query<Department>(Department.class, querySql); MultiplePagedQuerySearch<Department> pagedQuerySearch = new MultiplePagedQuerySearch<Department>(queries, pagedSearch.getOffset(), pagedSearch.getLimit(), pagedSearch.getParameters(), Department.class); when(queryBuilder.build(Matchers.<MultiplePagedSearch<Department>>any())).thenReturn(querySql); when(persistenceManager.search(Matchers.<MultiplePagedQuerySearch<Department>>any())).thenReturn(expected); PagedResult<Department> actual = unit.getEntities(pagedSearch); verify(queryBuilder).build(pagedSearch); verify(persistenceManager).search(pagedQuerySearch); assertEquals(expected, actual); }