MiddlewareService { @Transactional(readOnly = true) public MiddlewarePage list(Long apiId, MiddlewareDTO middlewareDTO, PageableDTO pageableDTO) { Example<Middleware> example = this.createExample(apiId, middlewareDTO); Sort sort = new Sort(new Sort.Order(Sort.Direction.DESC, "creationDate")); Pageable pageable = Pageable.setPageable(pageableDTO.getOffset(), pageableDTO.getLimit(), sort); Page<Middleware> page = middlewareRepository.findAll(example, pageable); MiddlewarePage middlewarePage = new MiddlewarePage(PageDTO.build(page)); return middlewarePage; }  @Transactional(readOnly = true) Middleware find(Long apiId, Long middlewareId); @Transactional(readOnly = true) MiddlewarePage list(Long apiId, MiddlewareDTO middlewareDTO, PageableDTO pageableDTO); @Transactional(readOnly = true) List<Middleware> list(Long apiId, MiddlewareDTO middlewareDTO); @Transactional Middleware save(Long apiId, MiddlewareDTO middlewareDTO, MultipartFile file); @Transactional Middleware update(Long apiId, Long middlewareId, MiddlewareDTO middlewareDTO); @Transactional void delete(Long apiId, Long middlewareId); @Transactional void deleteAll(Long apiId);  }
@Test public void listPageableTest() { Mockito.when(apiRepository.findOne(Mockito.anyLong())).thenReturn(api); Mockito.when(middlewareRepository.findAll(Mockito.any(Example.class), Mockito.any(Pageable.class))).thenReturn(getPageMiddleware()); MiddlewarePage middlewarePage = service.list(1L, new MiddlewareDTO(), new PageableDTO()); assertEquals(middlewareList, middlewarePage.getContent()); }
@Test public void listTest() { Mockito.when(apiRepository.findOne(Mockito.anyLong())).thenReturn(api); Mockito.when(middlewareRepository.findAll(Mockito.any(Example.class))).thenReturn(middlewareList); List<Middleware> middlewareListActual = service.list(1L, new MiddlewareDTO()); assertEquals(middlewareList, middlewareListActual); }