ResourceService { public ResourcePage list(Long apiId, ResourceDTO resourceDTO, PageableDTO pageableDTO) { Api api = apiRepository.findOne(apiId); HeimdallException.checkThrow(api == null, GLOBAL_RESOURCE_NOT_FOUND); Resource resource = GenericConverter.mapper(resourceDTO, Resource.class); resource.setApi(api); Example<Resource> example = Example.of(resource, ExampleMatcher.matching().withIgnorePaths("api.creationDate").withIgnoreCase().withStringMatcher(StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Resource> page = resourceRepository.findAll(example, pageable); ResourcePage resourcePage = new ResourcePage(PageDTO.build(page)); return resourcePage; }  @Transactional(readOnly = true) Resource find(Long apiId, Long resourceId); ResourcePage list(Long apiId, ResourceDTO resourceDTO, PageableDTO pageableDTO); List<Resource> list(Long apiId, ResourceDTO resourceDTO); Resource save(Long apiId, ResourceDTO resourceDTO); Resource save(Long apiId, Resource resource); Resource update(Long apiId, Long resourceId, ResourceDTO resourceDTO); void delete(Long apiId, Long resourceId); void deleteAllFromApi(Long apiId);  }
@Test public void listResources() { List<Resource> resources = new ArrayList<>(); resources.add(resource); Mockito.when(this.apiRepository.findOne(1L)).thenReturn(api); Mockito.when(this.resourceRepository.findAll(Mockito.any(Example.class))).thenReturn(resources); List<Resource> environmentResp = this.resourceService.list(1L, this.resourceDTO); assertEquals(resources.size(), environmentResp.size()); Mockito.verify(this.resourceRepository, Mockito.times(1)).findAll(Mockito.any(Example.class)); }
@Test public void listResourcesWithPageable() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); ArrayList<Resource> listResources = new ArrayList<>(); this.resource.setName("Resource Name"); listResources.add(resource); Page<Resource> page = new PageImpl<>(listResources); Mockito.when(apiRepository.findOne(Mockito.anyLong())).thenReturn(api); Mockito.when(this.resourceRepository .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); ResourcePage resourcePageResp = this.resourceService.list(1L, this.resourceDTO, pageableDTO); assertEquals(1L, resourcePageResp.getTotalElements()); Mockito.verify(this.resourceRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }