@Test public void listOperationsWithPageable() { PageableDTO pageableDTO = new PageableDTO(); pageableDTO.setLimit(10); pageableDTO.setOffset(0); ArrayList<Operation> listOperations = new ArrayList<>(); listOperations.add(operation); Page<Operation> page = new PageImpl<>(listOperations); Mockito.when(resourceRepository.findByApiIdAndId(Mockito.anyLong(), Mockito.anyLong())) .thenReturn(res); Mockito.when(this.operationRepository .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))) .thenReturn(page); OperationPage operationPageResp = this.operationService .list(1L, 1L, this.operationDTO, pageableDTO); assertEquals(1L, operationPageResp.getTotalElements()); Mockito.verify(this.operationRepository, Mockito.times(1)) .findAll(Mockito.any(Example.class), Mockito.any(Pageable.class)); }
@Transactional(readOnly = true) public OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO) { Example<Operation> example = this.prepareExample(apiId, resourceId, operationDTO); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Operation> page = operationRepository.findAll(example, pageable); return new OperationPage(PageDTO.build(page)); }
OperationService { @Transactional(readOnly = true) public OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO) { Example<Operation> example = this.prepareExample(apiId, resourceId, operationDTO); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Operation> page = operationRepository.findAll(example, pageable); return new OperationPage(PageDTO.build(page)); } }
OperationService { @Transactional(readOnly = true) public OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO) { Example<Operation> example = this.prepareExample(apiId, resourceId, operationDTO); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Operation> page = operationRepository.findAll(example, pageable); return new OperationPage(PageDTO.build(page)); }  }
OperationService { @Transactional(readOnly = true) public OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO) { Example<Operation> example = this.prepareExample(apiId, resourceId, operationDTO); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Operation> page = operationRepository.findAll(example, pageable); return new OperationPage(PageDTO.build(page)); }  @Transactional(readOnly = true) Operation find(Long apiId, Long resourceId, Long operationId); @Transactional(readOnly = true) OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Operation> list(Long apiId, Long resourceId, OperationDTO operationDTO); @Transactional(readOnly = true) List<Operation> list(final Long apiId); @Transactional Operation save(Long apiId, Long resourceId, Operation operation); @Transactional Operation update(Long apiId, Long resourceId, Long operationId, OperationDTO operationDTO); @Transactional void delete(Long apiId, Long resourceId, Long operationId); @Transactional void deleteAllfromResource(Long apiId, Long resourceId); }
OperationService { @Transactional(readOnly = true) public OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO) { Example<Operation> example = this.prepareExample(apiId, resourceId, operationDTO); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit()); Page<Operation> page = operationRepository.findAll(example, pageable); return new OperationPage(PageDTO.build(page)); }  @Transactional(readOnly = true) Operation find(Long apiId, Long resourceId, Long operationId); @Transactional(readOnly = true) OperationPage list(Long apiId, Long resourceId, OperationDTO operationDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Operation> list(Long apiId, Long resourceId, OperationDTO operationDTO); @Transactional(readOnly = true) List<Operation> list(final Long apiId); @Transactional Operation save(Long apiId, Long resourceId, Operation operation); @Transactional Operation update(Long apiId, Long resourceId, Long operationId, OperationDTO operationDTO); @Transactional void delete(Long apiId, Long resourceId, Long operationId); @Transactional void deleteAllfromResource(Long apiId, Long resourceId);  }