DefaultPersistenceManager implements PersistenceManager<T, I> { @Override public PagedResult<T> search(final MultiplePagedQuerySearch<T> request) { verify(DaoMethod.MULTIPLE_GET, request); TypedQuery<T> typedQuery = createQuery(request.getQuery().getQuery(), request.getParameters(), request.getClazz()); typedQuery.setFirstResult(request.getOffset()); typedQuery.setMaxResults(request.getLimit()); Long count = getQueryCount(request.getQuery().getQuery(), request.getParameters(), request.getClazz()); PagedResult<T> result = new PagedResult<T>(request.getOffset(), request.getLimit(), count, typedQuery.getResultList()); return result; }  @Override T create(final T entity); @Override T findById(final Class<T> clazz, final I id); @Override T update(final T entity); @Override void remove(final T entity); @Override PagedResult<T> search(final MultiplePagedQuerySearch<T> request); @Override T getSingleResult(final Query<T> query); @Override List<E> getMultipleResult(final Query<E> query); List<Object[]> executeNativeQuery(String sql); @Override Object[] executeSingleResultNativeQuery(String sql); void setPersistenceChains(final Map<DaoMethod, VerifierChainLink<? super Object>> persistenceChains); void setPersistenceEnhancers(final Map<DaoMethod, Enhancer<? super Object>> persistenceEnhancers);  }
@Test public void testSearch() throws Exception { String querySql = "SELECT d FROM Department d"; Query<Department> query = new Query<Department>(Department.class, querySql); Integer offset = 0; Integer limit = 20; Map<String, Object> parameters = Collections.emptyMap(); Class<Department> clazz = Department.class; MultiplePagedQuerySearch<Department> request = new MultiplePagedQuerySearch<Department>(query, offset, limit, parameters, clazz); long count = 100L; Department entity1 = new Department(); List<Department> entities = Arrays.asList(entity1); PagedResult<Department> expected = new PagedResult<Department>(request.getOffset(), request.getLimit(), count , entities); when(typedQuery.getResultList()).thenReturn(entities); when(typedLongQuery.getSingleResult()).thenReturn(count); when(entityManager.createQuery("SELECT d FROM Department d", Department.class)).thenReturn(typedQuery); when(entityManager.createQuery("SELECT COUNT(*) FROM Department a WHERE a IN(SELECT d FROM Department d) ", Long.class)).thenReturn(typedLongQuery); PagedResult<Department> actual = unit.search(request); verify(typedQuery, times(0)).setParameter(anyString(), any()); verify(typedLongQuery, times(0)).setParameter(anyString(), any()); verify(typedQuery).getResultList(); verify(typedLongQuery).getSingleResult(); verify(typedQuery).setFirstResult(offset); verify(typedQuery).setMaxResults(limit); assertEquals(expected, actual); }