### Question:
WorkLogService implements WorkLogServiceI { @Override public WorkLog editWorkLog(Long id, WorkLog workLog) throws BaseException { validateEditWorkLog(workLog); WorkLog workLogFromBase = workLogRepository.findWorkLogById(id); if (workLogFromBase == null) { throw new WorkLogDontExistException("Edited work log dont exists"); } return workLogRepository.updateWorkLog(new WorkLog(id, workLog.getStartDate(), workLog.getTimeSpentInSeconds(), workLogFromBase.getAssociatedWorker(), workLog.getDescription())); } @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 public void editWorkLog_Success() throws BaseException { WorkLog editedWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l); WorkLog result = workLogService.editWorkLog(1l, editedWorkLog); assertEquals(Long.valueOf(1l), result.getWorkLogId()); assertEquals(editedWorkLog.getDescription(), result.getDescription()); assertEquals(editedWorkLog.getStartDate(), result.getStartDate()); assertEquals(editedWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(editedWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(1, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test(expected = WorkLogDontExistException.class) public void editWorkLog_WorkLogDontExist() throws BaseException { WorkLog editedWorkLog = WorkLogRepositoryStub.workLogWithNonExistingWorker(2l); WorkLog result = workLogService.editWorkLog(2l, editedWorkLog); assertEquals(editedWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(editedWorkLog.getDescription(), result.getDescription()); assertEquals(editedWorkLog.getStartDate(), result.getStartDate()); assertEquals(editedWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(editedWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test(expected = WorkLogStartDateException.class) public void editWorkLog_StartDateFromFuture() throws BaseException { WorkLog editedWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l, LocalDate.MAX); WorkLog result = workLogService.editWorkLog(1l, editedWorkLog); assertEquals(editedWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(editedWorkLog.getDescription(), result.getDescription()); assertEquals(editedWorkLog.getStartDate(), result.getStartDate()); assertEquals(editedWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(editedWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }
@Test(expected = WorkLogTimeSpentException.class) public void editWorkLog_NegativeTimeSpent() throws BaseException { WorkLog editedWorkLog = WorkLogRepositoryStub.workLogWithExistingWorker(2l, -1); WorkLog result = workLogService.editWorkLog(1l, editedWorkLog); assertEquals(editedWorkLog.getWorkLogId(), result.getWorkLogId()); assertEquals(editedWorkLog.getDescription(), result.getDescription()); assertEquals(editedWorkLog.getStartDate(), result.getStartDate()); assertEquals(editedWorkLog.getTimeSpentInSeconds(), result.getTimeSpentInSeconds()); assertEquals(editedWorkLog.getAssociatedWorker().getLogin(), result.getAssociatedWorker().getLogin()); assertEquals(2, getWorkLogRepositoryStub().getWorkLogList().size()); }