LogServiceImpl implements LogService { @Override public Page<Log> getByScan(Scan scan, Integer pageNumber, Integer pageSize) { Pageable pageable = PageRequest.of(pageNumber, pageSize); return logDAO.getByScanOrderByTimeStampDesc(scan, pageable); } @Autowired  LogServiceImpl(LogDAO logDAO, ScanDAO scanDAO); @Override boolean insertError(Scan scan, Throwable e); @Override boolean insert(Scan scan, LogType type, String message); @Override boolean insert(Scan scan, LogType type, Timestamp timestamp, String message); @Override Page<Log> getByScan(Scan scan, Integer pageNumber, Integer pageSize);  }
@Test(dataProvider = "getLogData", dataProviderClass = ServiceTestDataProvider.class) public void testGetByScan(Log log) { Mockito.when(mockScanDAO.getByJobId(log.getScan().getJobId())).thenReturn(log.getScan()); Mockito.when(mockLogDAO.getByScanOrderByTimeStampDesc(log.getScan(), PageRequest.of(1, 10))).thenReturn(new PageImpl<>(Collections.singletonList(log))); Page retrievedLogsPage = logService.getByScan(log.getScan(), 1, 10); Assert.assertNotNull(retrievedLogsPage); List<Log> retrievedLogs = retrievedLogsPage.getContent(); Assert.assertNotNull(retrievedLogs); Assert.assertFalse(retrievedLogs.isEmpty()); Assert.assertEquals(log.getScan(), retrievedLogs.get(0).getScan()); }