LogServiceImpl implements LogService { @Override public boolean insert(Scan scan, LogType type, String message) { return insert(scan, type, new Timestamp(System.currentTimeMillis()), message); } @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 testInsert(Log log) { Mockito.when(mockScanDAO.getByJobId(log.getScan().getJobId())).thenReturn(log.getScan()); Mockito.when(mockLogDAO.save(log)).thenReturn(log); Assert.assertTrue(logService.insert(log.getScan(), log.getType(), log.getTimeStamp(), log.getMessage())); }
@Test(dataProvider = "getLogData", dataProviderClass = ServiceTestDataProvider.class) public void testInsertWithoutTimestamp(Log log) { Mockito.when(mockScanDAO.getByJobId(log.getScan().getJobId())).thenReturn(log.getScan()); Mockito.when(mockLogDAO.save(log)).thenReturn(log); Assert.assertTrue(logService.insert(log.getScan(), log.getType(), log.getMessage())); }