1717package de .doubleslash .keeptime .controller ;
1818
1919import static org .hamcrest .Matchers .contains ;
20- import static org .hamcrest .Matchers .equalTo ;
21- import static org .hamcrest .Matchers .is ;
22- import static org .hamcrest .Matchers .not ;
23- import static org .junit .Assert .assertEquals ;
24- import static org .junit .Assert .assertThat ;
25- import static org .junit .Assert .assertTrue ;
20+ import static org .junit .jupiter .api .Assertions .assertEquals ;
21+ import static org .junit .jupiter .api .Assertions .assertNotEquals ;
22+
2623
2724import java .time .LocalDateTime ;
2825import java .util .ArrayList ;
2926import java .util .Arrays ;
3027import java .util .List ;
3128import java .util .concurrent .TimeUnit ;
3229
33- import org .hamcrest .Matchers ;
34- import org .junit .Before ;
35- import org .junit .Test ;
30+
31+ import org .junit .jupiter .api .Assertions ;
32+ import org .junit .jupiter .api .BeforeEach ;
33+ import org .junit .jupiter .api .Test ;
3634import org .mockito .ArgumentCaptor ;
3735import org .mockito .Mockito ;
3836import org .springframework .test .util .ReflectionTestUtils ;
@@ -55,8 +53,8 @@ public class ControllerTest {
5553
5654 private WorkRepository mockedWorkRepository ;
5755
58- @ Before
59- public void beforeTest () {
56+ @ BeforeEach
57+ void beforeTest () {
6058 mockedWorkRepository = Mockito .mock (WorkRepository .class );
6159 model = new Model (Mockito .mock (ProjectRepository .class ), mockedWorkRepository ,
6260 Mockito .mock (SettingsRepository .class ));
@@ -87,7 +85,7 @@ public void moveProjectFromEndToStart() {
8785 testee .resortProjectIndexes (projectList , project3 , oldIndex , newIndex );
8886
8987 for (int i = 0 ; i < projectList .size (); i ++) {
90- assertThat (projectList .get (i ).getIndex (), Matchers . is ( expectedOrderAfter .get (i ) ));
88+ assertEquals (projectList .get (i ).getIndex (), expectedOrderAfter .get (i ));
9189 }
9290
9391 }
@@ -114,7 +112,7 @@ public void moveProjectFromStartToEnd() {
114112 testee .resortProjectIndexes (projectList , project0 , oldIndex , newIndex );
115113
116114 for (int i = 0 ; i < projectList .size (); i ++) {
117- assertThat (projectList .get (i ).getIndex (), Matchers . is ( expectedOrderAfter .get (i ) ));
115+ assertEquals (projectList .get (i ).getIndex (), expectedOrderAfter .get (i ));
118116 }
119117
120118 }
@@ -141,7 +139,7 @@ public void moveProjectForward() {
141139 testee .resortProjectIndexes (projectList , project1 , oldIndex , newIndex );
142140
143141 for (int i = 0 ; i < projectList .size (); i ++) {
144- assertThat (projectList .get (i ).getIndex (), Matchers . is ( expectedOrderAfter .get (i ) ));
142+ assertEquals (projectList .get (i ).getIndex (), expectedOrderAfter .get (i ));
145143 }
146144
147145 }
@@ -168,7 +166,7 @@ public void moveProjectBackward() {
168166 testee .resortProjectIndexes (projectList , project2 , oldIndex , newIndex );
169167
170168 for (int i = 0 ; i < projectList .size (); i ++) {
171- assertThat (projectList .get (i ).getIndex (), is ( expectedOrderAfter .get (i ) ));
169+ assertEquals (projectList .get (i ).getIndex (), expectedOrderAfter .get (i ));
172170 }
173171 }
174172
@@ -193,7 +191,7 @@ public void dontMoveProjectTest() {
193191 }
194192
195193 for (int i = 0 ; i < projectList .size (); i ++) {
196- assertThat (projectList .get (i ).getIndex (), is ( expectedOrderAfter .get (i ) ));
194+ assertEquals (projectList .get (i ).getIndex (), expectedOrderAfter .get (i ));
197195 }
198196 }
199197
@@ -221,11 +219,11 @@ public void changeProjectSameDayTest() {
221219 }
222220 return true ;
223221 }));
224- assertThat ( "Two project should be in the past work items" , model . getPastWorkItems (). size (), is ( 2 ) );
225- assertThat ( "The first project should be the past work project" , model .getPastWorkItems ().get (0 ).getProject (),
226- is ( firstProject ) );
227- assertThat ( "The second project should be the active work project" , model .activeWorkItem .get ().getProject (),
228- is ( secondProject ) );
222+ assertEquals ( model . getPastWorkItems (). size (), 2 , "Two project should be in the past work items" );
223+ assertEquals ( model .getPastWorkItems ().get (0 ).getProject (),
224+ firstProject , "The first project should be the past work project" );
225+ assertEquals ( model .activeWorkItem .get ().getProject (),
226+ secondProject , "The second project should be the active work project" );
229227 }
230228
231229 @ Test
@@ -253,11 +251,11 @@ public void changeProjectOtherDayTest() {
253251 }
254252 return true ;
255253 }));
256- assertThat ( "'2nd project' should be in the past work items" , model . getPastWorkItems (). size (), is ( 1 ) );
257- assertThat ( "The project should be '2ndProject'" , model .getPastWorkItems ().get (0 ).getProject (),
258- is ( secondProject ) );
259- assertThat ( "'2ndProject' should be the active work project" , model .activeWorkItem .get ().getProject (),
260- is ( secondProject ) );
254+ assertEquals ( model . getPastWorkItems (). size (), 1 , "'2nd project' should be in the past work items" );
255+ assertEquals ( model .getPastWorkItems ().get (0 ).getProject (),
256+ secondProject , "The project should be '2ndProject'" );
257+ assertEquals ( model .activeWorkItem .get ().getProject (),
258+ secondProject , "'2ndProject' should be the active work project" );
261259 }
262260
263261 @ Test
@@ -286,15 +284,15 @@ public void changeProjectOtherDayWithTimeTest() {
286284 return true ;
287285 }));
288286
289- assertThat ( "Two projects should be in the past work items" , model . getPastWorkItems (). size (), is ( 2 ) );
290- assertThat ( "The first project should be '1st Project'" , model .getPastWorkItems ().get (0 ).getProject (),
291- is ( firstProject ) );
292- assertThat ( "The second project should be '2ndProject'" , model .getPastWorkItems ().get (1 ).getProject (),
293- is ( secondProject ) );
287+ assertEquals ( model . getPastWorkItems (). size (), 2 , "Two projects should be in the past work items" );
288+ assertEquals ( model .getPastWorkItems ().get (0 ).getProject (),
289+ firstProject , "The first project should be '1st Project'" );
290+ assertEquals ( model .getPastWorkItems ().get (1 ).getProject (),
291+ secondProject , "The second project should be '2ndProject'" );
294292 final Work work = model .activeWorkItem .get ();
295- assertThat ( "'2ndProject' should be the active work project" , work . getProject (), is ( secondProject ) );
296- assertThat (work .getStartTime ().toLocalDate (), is ( firstProjectDateTime .toLocalDate () ));
297- assertThat (work .getStartTime (), is ( firstProjectPlusOneHour ) );
293+ assertEquals ( work . getProject (), secondProject , "'2ndProject' should be the active work project" );
294+ assertEquals (work .getStartTime ().toLocalDate (), firstProjectDateTime .toLocalDate ());
295+ assertEquals (work .getStartTime (), firstProjectPlusOneHour );
298296 }
299297
300298 @ Test
@@ -318,10 +316,10 @@ public void shouldCalculateSecondsCorrectlyWhenWorkItemsAreGiven() {
318316 model .getPastWorkItems ().addAll (workItems );
319317
320318 final long totalSeconds = testee .calcSeconds (workItems );
321- assertEquals ("Seconds were not calculated correctly." , TimeUnit . HOURS . toSeconds ( 4 ), totalSeconds );
319+ assertEquals (TimeUnit . HOURS . toSeconds ( 4 ), totalSeconds , "Seconds were not calculated correctly." );
322320
323321 final long todaysSeconds = testee .calcTodaysSeconds ();
324- assertEquals ("Todays seconds were not calulated correctly." , TimeUnit . HOURS . toSeconds ( 4 ), todaysSeconds );
322+ assertEquals (TimeUnit . HOURS . toSeconds ( 4 ), todaysSeconds , "Todays seconds were not calulated correctly." );
325323
326324 // final long todaysWorkSeconds = testee.calcTodaysWorkSeconds();
327325 // assertEquals("Todays work seconds were not calculated correctly.",TimeUnit.HOURS.toSeconds(2),
@@ -351,14 +349,15 @@ public void shouldUpdateWorkItemPersistentlyWhenWorkItemIsEdited() {
351349 testee .editWork (originalWork , newWork );
352350
353351 final Work testWork = model .getPastWorkItems ().get (0 );
354- assertThat ("Start time was not updated" , testWork .getStartTime (), equalTo (newWork .getStartTime ()));
355- assertThat ("End timewas not updated" , testWork .getEndTime (), equalTo (newWork .getEndTime ()));
356- assertThat ("Notes were not updated" , testWork .getNotes (), equalTo (newWork .getNotes ()));
357- assertThat ("Project was not updated" , testWork .getProject (), equalTo (newWork .getProject ()));
352+
353+ assertEquals (testWork .getStartTime (), newWork .getStartTime (),"Start time was not updated" );
354+ assertEquals (testWork .getEndTime (), newWork .getEndTime (), "End timewas not updated" );
355+ assertEquals (testWork .getNotes (), newWork .getNotes (),"Notes were not updated" );
356+ assertEquals (testWork .getProject (), newWork .getProject (),"Project was not updated" );
358357
359358 final ArgumentCaptor <Work > argument = ArgumentCaptor .forClass (Work .class );
360359 Mockito .verify (mockedWorkRepository , Mockito .times (1 )).save (argument .capture ());
361- assertThat ( "Edited work was not saved persistently" , argument . getValue (), is ( originalWork ) );
360+ assertEquals ( argument . getValue (), originalWork , "Edited work was not saved persistently" );
362361
363362 }
364363
@@ -389,14 +388,14 @@ public void shouldNotUpdateOthersWhenWorkItemIsEdited() {
389388
390389 testee .editWork (originalWork , newWork );
391390
392- assertThat ( "Too many or too less work items in past work items" , model . getPastWorkItems (). size (), equalTo ( 2 ) );
393- assertThat ( "Work with new values in past work items instead of updatd work" , model .getPastWorkItems (),
394- not ( contains (newWork )) );
391+ assertEquals ( 2 , model . getPastWorkItems (). size (), "Too many or too less work items in past work items" );
392+ assertNotEquals ( model .getPastWorkItems (),
393+ contains (newWork ), "Work with new values in past work items instead of updatd work" );
395394
396395 final ArgumentCaptor <Work > argument = ArgumentCaptor .forClass (Work .class );
397396 Mockito .verify (mockedWorkRepository , Mockito .times (1 )).save (argument .capture ());
398- assertThat ( "Saved other Work persistently than what should be edited" , argument .getValue (),
399- not ( is ( notToBeUpdatedWork )) );
397+ assertNotEquals ( argument .getValue (),
398+ notToBeUpdatedWork , "Saved other Work persistently than what should be edited" );
400399
401400 }
402401
@@ -416,7 +415,7 @@ public void shouldDeleteWorkPersistentlyWhenWorkIsDeleted() {
416415
417416 final ArgumentCaptor <Work > argument = ArgumentCaptor .forClass (Work .class );
418417 Mockito .verify (mockedWorkRepository , Mockito .times (1 )).delete (argument .capture ());
419- assertThat ( "Edited work was not deleted persistently" , argument . getValue (), is ( work ) );
418+ assertEquals ( argument . getValue (), work , "Edited work was not deleted persistently" );
420419
421420 }
422421
@@ -433,8 +432,7 @@ public void shouldRemoveWorkFromPastWorkItemsWhenWorkIsDeleted() {
433432 model .getPastWorkItems ().add (work );
434433
435434 testee .deleteWork (work );
436-
437- assertTrue ("work Items contain work when it should have been deleted" , model .getPastWorkItems ().isEmpty ());
435+ Assertions .assertTrue (model .getPastWorkItems ().isEmpty (),"work Items contain work when it should have been deleted" );
438436
439437 }
440438
0 commit comments