EnvironmentService { public EnvironmentPage list(EnvironmentDTO environmentDTO, PageableDTO pageableDTO) { Environment environment = GenericConverter.mapper(environmentDTO, Environment.class); Example<Environment> example = Example.of(environment, ExampleMatcher.matching().withIgnoreCase().withStringMatcher(StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Environment> page = environmentRepository.findAll(example, pageable); return new EnvironmentPage(PageDTO.build(page)); }  Environment find(Long id); EnvironmentPage list(EnvironmentDTO environmentDTO, PageableDTO pageableDTO); List<Environment> list(EnvironmentDTO environmentDTO); @Transactional Environment save(EnvironmentDTO environmentDTO); @Transactional Environment update(Long id, EnvironmentDTO environmentDTO); @Transactional void delete(Long id);  }
@Test public void listEnvironments() { List<Environment> environments = new ArrayList<>(); environments.add(environment); Mockito.when(this.environmentRepository.findAll(Mockito.any(Example.class))) .thenReturn(environments); List<Environment> environmentResp = this.environmentService.list(this.environmentDTO); assertEquals(environments.size(), environmentResp.size()); Mockito.verify(this.environmentRepository, Mockito.times(1)).findAll(Mockito.any(Example.class)); }
@Test public void listEnvironmentsWithPageable() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); ArrayList<Environment> environments = new ArrayList<>(); environments.add(environment); Page<Environment> page = new PageImpl<>(environments); Mockito.when(this.environmentRepository .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); EnvironmentPage environmentPageResp = this.environmentService .list(this.environmentDTO, pageableDTO); assertEquals(1L, environmentPageResp.getTotalElements()); Mockito.verify(this.environmentRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }