ApiService { public ApiPage list(ApiDTO apiDTO, PageableDTO pageableDTO) { Api api = GenericConverter.mapper(apiDTO, Api.class); Example<Api> example = Example.of(api, ExampleMatcher.matching().withIgnorePaths("cors").withIgnoreCase().withStringMatcher(StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Api> page = apiRepository.findAll(example, pageable); ApiPage apiPage = new ApiPage(PageDTO.build(page)); return apiPage; }  Api find(Long id); Swagger findSwaggerByApi(Long id); ApiPage list(ApiDTO apiDTO, PageableDTO pageableDTO); List<Api> list(ApiDTO apiDTO); Api save(ApiDTO apiDTO); Api update(Long id, ApiDTO apiDTO); Api updateBySwagger(Long id, String swagger, boolean override); void delete(Long id); @Transactional(readOnly = true) List<Plan> plansByApi(Long id);  }
@Test public void listApiWithoutPageableTest() { List<Api> apis = new ArrayList<>(); apis.add(api); Mockito.when(this.apiRepository.findAll(Mockito.any(Example.class))).thenReturn(apis); List<Api> listApiResp = apiService.list(apiDTO); assertEquals(apis.size(), listApiResp.size()); Mockito.verify(this.apiRepository, Mockito.times(1)).findAll(Mockito.any(Example.class)); }
@Test public void listApiWithPageableTest() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); List<Api> apis = new ArrayList<>(); apis.add(api); Page<Api> page = new PageImpl<>(apis); Mockito.when(this.apiRepository.findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); ApiPage apiPageResp = apiService.list(apiDTO, pageableDTO); assertEquals(1L, apiPageResp.getTotalElements()); Mockito.verify(this.apiRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }