BaseServiceImpl implements BaseService<ID, T> { @Override public List<T> fetch(Filter filter, FetchJoinInformation... joins) { return getDao().fetch(filter, joins); }  @Override long count(); @Override long count(Filter filter, boolean distinct); @Override T createNewEntity(); @Override @Transactional void delete(List<T> list); @Override @Transactional void delete(T t); @Override List<T> fetch(Filter filter, FetchJoinInformation... joins); @Override List<T> fetch(Filter filter, int pageNumber, int pageSize, FetchJoinInformation... joins); @Override List<T> fetch(Filter filter, int pageNumber, int pageSize, SortOrders sortOrders, FetchJoinInformation... joins); @Override List<T> fetch(Filter filter, SortOrders orders, FetchJoinInformation... joins); @Override T fetchById(ID id, FetchJoinInformation... joins); @Override List<T> fetchByIds(List<ID> ids, FetchJoinInformation... joins); @Override List<T> fetchByIds(List<ID> ids, SortOrders sortOrders, FetchJoinInformation... joins); @Override T fetchByUniqueProperty(String propertyName, Object value, boolean caseSensitive, FetchJoinInformation... joins); @Override List<T> find(Filter filter); @Override List<T> find(Filter filter, SortOrder... orders); @Override List<T> findAll(); @Override List<T> findAll(SortOrder... orders); @Override T findById(ID id); @Override T findByUniqueProperty(String propertyName, Object value, boolean caseSensitive); @Override List<S> findDistinct(Filter filter, String distinctField, Class<S> elementType, SortOrder... orders); @Override List<S> findDistinctInCollectionTable(String tableName, String distinctField, Class<S> elementType); @Override List<ID> findIds(Filter filter, Integer maxResults, SortOrder... orders); @Override List<ID> findIds(Filter filter, SortOrder... orders); @Override List<?> findSelect(Filter filter, String[] selectProperties, int pageNumber, int pageSize, SortOrders sortOrders); @Override List<?> findSelect(Filter filter, String[] selectProperties, SortOrders sortOrders); @Override Class<T> getEntityClass(); MessageService getMessageService(); @Override @Transactional List<T> save(List<T> list); @Override @Transactional T save(T t); @Override void validate(T t);  }
@Test public void testCreatePageable() { Filter filter = new Compare.Equal("name", "Piet"); SortOrder order = new SortOrder("name", Direction.ASC); SortOrder order2 = new SortOrder("age", Direction.DESC); service.fetch(filter, 2, 10, new SortOrders(order, order2)); ArgumentCaptor<Pageable> captor = ArgumentCaptor.forClass(Pageable.class); verify(dao).fetch(any(Filter.class), captor.capture()); Pageable p = captor.getValue(); Direction dir = p.getSortOrders().getOrderFor("name").getDirection(); assertEquals(Direction.ASC, dir); Direction dir2 = p.getSortOrders().getOrderFor("age").getDirection(); assertEquals(Direction.DESC, dir2); assertEquals(2, p.getPageNumber()); assertEquals(20, p.getOffset()); assertEquals(10, p.getPageSize()); }
@Test public void testFetchFilter() { Filter filter = new Compare.Equal("property1", 1); service.fetch(filter, new FetchJoinInformation("testEntities")); verify(dao).fetch(filter, new FetchJoinInformation("testEntities")); service.fetch(filter); verify(dao).fetch(filter); }
@Test public void testFetchFilterPageable() { Filter filter = new Compare.Equal("property1", 1); service.fetch(filter, 2, 10, new FetchJoinInformation("testEntities")); ArgumentCaptor<Pageable> captor = ArgumentCaptor.forClass(Pageable.class); verify(dao).fetch(eq(filter), captor.capture(), eq(new FetchJoinInformation("testEntities"))); Pageable pb = captor.getValue(); assertEquals(20, pb.getOffset()); assertEquals(10, pb.getPageSize()); assertEquals(2, pb.getPageNumber()); }
@Test public void testFetchSortOrderJoins() { Filter filter = new Compare.Equal("property1", 1); SortOrders orders = new SortOrders(new SortOrder("property2")); FetchJoinInformation[] joins = new FetchJoinInformation[] { new FetchJoinInformation("testEntities") }; service.fetch(filter, orders, joins); verify(dao).fetch(filter, orders, joins); }