AppService { @Transactional(readOnly = true) public AppPage list(AppRequestDTO appDTO, PageableDTO pageableDTO) { App app = GenericConverter.mapper(appDTO, App.class); Example<App> example = Example.of(app, ExampleMatcher.matching().withIgnoreCase().withStringMatcher(StringMatcher.CONTAINING)); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<App> page = appRepository.findAll(example, pageable); AppPage appPage = new AppPage(PageDTO.build(page)); return appPage; }  @Transactional(readOnly = true) App find(Long id); @Transactional(readOnly = true) AppPage list(AppRequestDTO appDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<App> list(AppRequestDTO appDTO); App save(AppPersist appDTO); App update(Long id, AppDTO appDTO); void delete(Long id); @Transactional App save(AppCallbackDTO reqBody);  }
@Test public void listAppWithPageableTest() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); List<App> apps = new ArrayList<>(); apps.add(app); AppRequestDTO appRequestDTO = new AppRequestDTO(); Page<App> page = new PageImpl<>(apps); Mockito.when(this.appRepository.findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); AppPage apiPageResp = appService.list(appRequestDTO, pageableDTO); assertEquals(1L, apiPageResp.getTotalElements()); Mockito.verify(this.appRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }
@Test public void listAppWithoutPageableTest() { List<App> apps = new ArrayList<>(); apps.add(app); Mockito.when(this.appRepository.findAll(Mockito.any(Example.class))).thenReturn(apps); AppRequestDTO appRequestDTO = new AppRequestDTO(); List<App> listAppResp = appService.list(appRequestDTO); assertEquals(apps.size(), listAppResp.size()); Mockito.verify(this.appRepository, Mockito.times(1)).findAll(Mockito.any(Example.class)); }