3535import org .junit .Test ;
3636import org .mockito .ArgumentCaptor ;
3737import org .mockito .Mockito ;
38- import org .mockito .invocation .InvocationOnMock ;
39- import org .mockito .stubbing .Answer ;
4038import org .springframework .test .util .ReflectionTestUtils ;
4139
4240import de .doubleslash .keeptime .common .DateProvider ;
@@ -337,14 +335,8 @@ public void shouldCalculateSecondsCorrectlyWhenWorkItemsAreGiven() {
337335 @ Test
338336 public void shouldUpdateWorkItemPersistentlyWhenWorkItemIsEdited () {
339337 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (LocalDateTime .now ());
340- Mockito .when (mockedWorkRepository .save (Mockito .any (Work .class ))).thenAnswer (new Answer <Work >() {
341-
342- @ Override
343- public Work answer (final InvocationOnMock invocation ) {
344- final Object [] args = invocation .getArguments ();
345- return (Work ) args [0 ];
346- }
347- });
338+ Mockito .when (mockedWorkRepository .save (Mockito .any (Work .class )))
339+ .thenAnswer (invocation -> invocation .getArguments ()[0 ]);
348340
349341 final Project project1 = new Project ("workProject1" , "Some description" , Color .RED , true , 0 );
350342 model .getAllProjects ().add (project1 );
@@ -362,28 +354,23 @@ public Work answer(final InvocationOnMock invocation) {
362354 testee .editWork (originalWork , newWork );
363355
364356 final Work testWork = model .getPastWorkItems ().get (0 );
365- assertThat ("start time is not updated" , newWork .getStartTime (), equalTo (testWork .getStartTime ()));
366- assertThat ("end time is not updated" , newWork .getEndTime (), equalTo (testWork .getEndTime ()));
367- assertThat ("creation date is not updated" , newWork .getCreationDate (), equalTo (testWork .getCreationDate ()));
368- assertThat ("notes are not updated" , newWork .getNotes (), equalTo (testWork .getNotes ()));
369- assertThat ("project is not updated" , newWork .getProject (), equalTo (testWork .getProject ()));
357+ assertThat ("Start time was not updated" , testWork .getStartTime (), equalTo (newWork .getStartTime ()));
358+ assertThat ("End timewas not updated" , testWork .getEndTime (), equalTo (newWork .getEndTime ()));
359+ assertThat ("CreationDate was not updated" , testWork .getCreationDate (), equalTo (newWork .getCreationDate ()));
360+ assertThat ("Notes were not updated" , testWork .getNotes (), equalTo (newWork .getNotes ()));
361+ assertThat ("Project was not updated" , testWork .getProject (), equalTo (newWork .getProject ()));
370362
371363 final ArgumentCaptor <Work > argument = ArgumentCaptor .forClass (Work .class );
372364 Mockito .verify (mockedWorkRepository , Mockito .times (1 )).save (argument .capture ());
373- assertThat ("not saved Persistent " , originalWork , is ( argument .getValue ()));
365+ assertThat ("Edited work was not saved persistently " , argument .getValue (), is ( originalWork ));
374366
375367 }
376368
377369 @ Test
378370 public void shouldNotUpdateOthersWhenWorkItemIsEdited () {
379371 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (LocalDateTime .now ());
380- Mockito .when (mockedWorkRepository .save (Mockito .any (Work .class ))).thenAnswer (new Answer <Work >() {
381- @ Override
382- public Work answer (final InvocationOnMock invocation ) {
383- final Object [] args = invocation .getArguments ();
384- return (Work ) args [0 ];
385- }
386- });
372+ Mockito .when (mockedWorkRepository .save (Mockito .any (Work .class )))
373+ .thenAnswer (invocation -> invocation .getArguments ()[0 ]);
387374
388375 final Project project1 = new Project ("workProject1" , "Some description" , Color .RED , true , 0 );
389376 model .getAllProjects ().add (project1 );
@@ -407,13 +394,13 @@ public Work answer(final InvocationOnMock invocation) {
407394
408395 testee .editWork (originalWork , newWork );
409396
410- assertThat ("changed amout of WorkItems " , model .getPastWorkItems ().size (), equalTo (2 ));
411- assertThat ("pastWorkItems contains work wich shouldnt be added " , model .getPastWorkItems (),
397+ assertThat ("Too many or too less work items in past work items " , model .getPastWorkItems ().size (), equalTo (2 ));
398+ assertThat ("Work with new values in past work items instead of updatd work " , model .getPastWorkItems (),
412399 not (contains (newWork )));
413400
414401 final ArgumentCaptor <Work > argument = ArgumentCaptor .forClass (Work .class );
415402 Mockito .verify (mockedWorkRepository , Mockito .times (1 )).save (argument .capture ());
416- assertThat ("saved other Work persistently than what should be updated " , argument .getValue (),
403+ assertThat ("Saved other Work persistently than what should be edited " , argument .getValue (),
417404 not (is (notToBeUpdatedWork )));
418405
419406 }
0 commit comments