OpaDataFilterRepositoryImpl extends SimpleJpaRepository<T, ID> implements OpaDataFilterRepository<T, ID> { @Override public List<T> findAll() { LOGGER.trace("Entering findAll()"); TypedQuery<T> typedQuery = queryService.getTypedQuery(this.getDomainClass(), Sort.unsorted(), entityManager); List<T> resultList = typedQuery.getResultList(); LOGGER.trace("Result list size: {}", resultList.size()); return resultList; } OpaDataFilterRepositoryImpl(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager, QueryService<T> queryService);  OpaDataFilterRepositoryImpl(Class<T> domainClass, EntityManager em, QueryService<T> queryService); @Override List<T> findAll(); @Override List<T> findAll(Sort sort); @Override Page<T> findAll(Pageable pageable);  }
@Test void shouldListData() { PetEntity petEntity = new PetEntity(); petEntity.setName("browny"); petEntity.setOwner("dodong"); when(queryService.getTypedQuery(PetEntity.class, Sort.unsorted(), entityManager)).thenReturn(query); when(query.getResultList()).thenReturn(List.of(petEntity)); List<PetEntity> result = target.findAll(); assertThat(result.size(), is(1)); }
@Test void shouldListSortedData() { PetEntity petEntity1 = new PetEntity(); petEntity1.setName("browny"); petEntity1.setOwner("dodong"); PetEntity petEntity2 = new PetEntity(); petEntity2.setName("asol"); petEntity2.setOwner("gerry"); when(queryService.getTypedQuery(PetEntity.class, Sort.by("name"), entityManager)).thenReturn(query); when(query.getResultList()).thenReturn(List.of(petEntity2, petEntity1)); List<PetEntity> result = target.findAll(Sort.by("name")); assertThat(result.size(), is(2)); assertThat(result.get(0).getName(), is("asol")); }
@Test public void retrieveObjectsForPageableOutOfRange() { PetEntity petEntity1 = new PetEntity(); petEntity1.setName("browny"); petEntity1.setOwner("dodong"); PetEntity petEntity2 = new PetEntity(); petEntity2.setName("asol"); petEntity2.setOwner("gerry"); when(queryService.getTypedQuery(PetEntity.class, Sort.sort(PetEntity.class), entityManager)).thenReturn(query); when(query.getResultList()).thenReturn(List.of(petEntity2, petEntity1)); Page<PetEntity> all = target.findAll(PageRequest.of(2, 10)); assertThat(all, is(notNullValue())); assertThat(all.getSize(), is(10)); }