### Question:
WorkLogService implements WorkLogServiceI { @Override public WorkLog logWork(WorkLog workLog) throws BaseException { validateWorkLog(workLog); return workLogRepository.createWorkLog(workLog); } @Inject  WorkLogService(WorkLogRepositoryI workLogRepository, WorkerRepositoryI workerRepository); @Override WorkLog logWork(WorkLog workLog); @Override WorkLog editWorkLog(Long id, WorkLog workLog); @Override WorkLog deleteWorkLog(Long workLogId); @Override List<WorkLog> reportWorkerWork(Worker worker); @Override WorkLog findWorkLogById(Long id);  }### Answer:
@Test(expected = WorkLogStartDateException.class) public void logWork_StartDateFromFuture() throws BaseException { WorkLog newWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l, LocalDate.MAX); WorkLog result = workLogService.logWork(newWorkLog); assertEquals(newWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(newWorkLog.getDescription(), result.getDescription()); assertEquals(newWorkLog.getStartDate(), result.getStartDate()); assertEquals(newWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(newWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test(expected = WorkLogTimeSpentException.class) public void logWork_NegativeTimeSpent() throws BaseException { WorkLog newWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l, -1); WorkLog result = workLogService.logWork(newWorkLog); assertEquals(newWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(newWorkLog.getDescription(), result.getDescription()); assertEquals(newWorkLog.getStartDate(), result.getStartDate()); assertEquals(newWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(newWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test public void logWork_Success() throws BaseException { WorkLog newWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l); WorkLog result = workLogService.logWork(newWorkLog); assertEquals(newWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(newWorkLog.getDescription(), result.getDescription()); assertEquals(newWorkLog.getStartDate(), result.getStartDate()); assertEquals(newWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(newWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test(expected = WorkerDontExistsException.class) public void logWork_WorkerDontExist() throws BaseException { WorkLog newWorkLog = WorkLogRepositoryStub.workLogWithNonExistingWorker(2l); WorkLog result = workLogService.logWork(newWorkLog); assertEquals(newWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(newWorkLog.getDescription(), result.getDescription()); assertEquals(newWorkLog.getStartDate(), result.getStartDate()); assertEquals(newWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(newWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }