LogServiceImpl implements LogService { @Override public boolean insertError(Scan scan, Throwable e) { logger.error("An error occurred", e); boolean isScanFound = false; if (scanDAO.getByJobId(scan.getJobId()) != null) { Log log = new Log(scan, LogType.ERROR, new Timestamp(System.currentTimeMillis()), getFullErrorMessage(e)); logDAO.save(log); isScanFound = true; } return isScanFound; } @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 testInsertError(Log log) { Mockito.when(mockScanDAO.getByJobId(log.getScan().getJobId())).thenReturn(log.getScan()); Mockito.when(mockLogDAO.save(log)).thenReturn(log); Assert.assertTrue(logService.insertError(log.getScan(), new Throwable("This is an error log test case. Please ignore the below stacktrace."))); }