public void testUpdateTask() {
// recherche de la story
Story story = new StoryImpl();
story.setTasks(new HashSet<Task>());
Task task = new TaskImpl();
task.setDaysEstimated(2);
task.setShortDescription("scooby");
task.setPersistanceId(1);
task.setPersistanceVersion(3);
story.getTasks().add(task);
EasyMock.expect(mockStoryRepository.findByPersistanceId(1)).andReturn(story);
// validation (sans erreurs)
EasyMock.expect(mockTaskValidator.validate(EasyMock.isA(Task.class))).andReturn(AgilePlanningObjectFactory.getErrors());
// modification
mockStoryRepository.addOrUpdate(story);
// set mock in replay mode
mocksControl.replay();
Errors errorsFromService = storyService.updateTask(1,5,"doo", 4, 1, 7);
// Vérifie les appels
mocksControl.verify();
// aucune erreur n'est retournée
assertFalse(errorsFromService.hasErrors());
// test de l'ajout de la tâche dans le liste de la story
for (Iterator iterator = story.getTasks().iterator(); iterator.hasNext();) {
Task taskUpdated = (Task) iterator.next();
assertEquals("doo", taskUpdated.getShortDescription());
assertEquals(5.0, taskUpdated.getDaysEstimated());
assertEquals(1, taskUpdated.getPersistanceId());
assertEquals(7, taskUpdated.getPersistanceVersion());
// une seule tâche dans la liste
break;
}