33import static org .hamcrest .Matchers .is ;
44import static org .junit .Assert .assertThat ;
55
6- import java .time .LocalDate ;
76import java .time .LocalDateTime ;
87import java .util .Arrays ;
98import java .util .List ;
@@ -173,17 +172,13 @@ public void dontMoveProjectTest() {
173172 @ Test
174173 public void changeProjectSameDayTest () {
175174 final LocalDateTime firstProjectDateTime = LocalDateTime .now ();
176- final LocalDate firstProjectDate = firstProjectDateTime .toLocalDate ();
177175 final LocalDateTime secondProjectDateTime = LocalDateTime .now ();
178- final LocalDate secondProjectDate = firstProjectDateTime .toLocalDate ();
179176
180177 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (firstProjectDateTime );
181- Mockito .when (mockedDateProvider .dateNow ()).thenReturn (firstProjectDate );
182178 final Project firstProject = new Project ("1st Project" , Color .GREEN , true , 0 );
183179 final Project secondProject = new Project ("2nd Project" , Color .RED , true , 1 );
184180 testee .changeProject (firstProject );
185181 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (secondProjectDateTime );
186- Mockito .when (mockedDateProvider .dateNow ()).thenReturn (secondProjectDate );
187182 testee .changeProject (secondProject );
188183
189184 Mockito .verify (model .getWorkRepository (), Mockito .times (1 )).save (Mockito .argThat ((final Work savedWork ) -> {
@@ -208,17 +203,13 @@ public void changeProjectSameDayTest() {
208203 @ Test
209204 public void changeProjectOtherDayTest () {
210205 final LocalDateTime firstProjectDateTime = LocalDateTime .now ();
211- final LocalDate firstProjectDate = firstProjectDateTime .toLocalDate ();
212206 final LocalDateTime secondProjectDateTime = firstProjectDateTime .plusDays (1 ); // project is create the next day
213- final LocalDate secondProjectDate = secondProjectDateTime .toLocalDate ();
214207
215208 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (firstProjectDateTime );
216- Mockito .when (mockedDateProvider .dateNow ()).thenReturn (firstProjectDate );
217209 final Project firstProject = new Project ("1st Project" , Color .GREEN , true , 0 );
218210 final Project secondProject = new Project ("2nd Project" , Color .RED , true , 1 );
219211 testee .changeProject (firstProject );
220212 Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (secondProjectDateTime );
221- Mockito .when (mockedDateProvider .dateNow ()).thenReturn (secondProjectDate );
222213 testee .changeProject (secondProject );
223214
224215 Mockito .verify (model .getWorkRepository (), Mockito .times (1 )).save (Mockito .argThat ((final Work savedWork ) -> {
@@ -233,11 +224,48 @@ public void changeProjectOtherDayTest() {
233224 }
234225 return true ;
235226 }));
236- assertThat ("One projects should be in the past work items" , model .getPastWorkItems ().size (), is (1 ));
237- assertThat ("The project should be the second work project " , model .getPastWorkItems ().get (0 ).getProject (),
227+ assertThat ("'1st project' should be in the past work items" , model .getPastWorkItems ().size (), is (1 ));
228+ assertThat ("The project should be '2ndProject' " , model .getPastWorkItems ().get (0 ).getProject (),
238229 is (secondProject ));
239- assertThat ("The second project should be the active work project" , model .activeWorkItem .get ().getProject (),
230+ assertThat ("'2ndProject' should be the active work project" , model .activeWorkItem .get ().getProject (),
231+ is (secondProject ));
232+ }
233+
234+ @ Test
235+ public void changeProjectOtherDayWithTimeTest () {
236+ final LocalDateTime firstProjectDateTime = LocalDateTime .of (2018 , 02 , 14 , 14 , 0 );
237+ final LocalDateTime secondProjectDateTime = firstProjectDateTime .plusDays (1 ); // project is create the next day
238+
239+ Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (firstProjectDateTime );
240+ final Project firstProject = new Project ("1st Project" , Color .GREEN , true , 0 );
241+ final Project secondProject = new Project ("2nd Project" , Color .RED , true , 1 );
242+ testee .changeProject (firstProject );
243+ Mockito .when (mockedDateProvider .dateTimeNow ()).thenReturn (secondProjectDateTime );
244+ testee .changeProject (secondProject , 23 * 60 * 60 ); // change with -23 hours
245+
246+ final LocalDateTime firstProjectPlusOneHour = firstProjectDateTime .plusHours (1 );
247+ Mockito .verify (model .getWorkRepository (), Mockito .times (1 )).save (Mockito .argThat ((final Work savedWork ) -> {
248+ if (savedWork .getProject () != firstProject ) {
249+ return false ;
250+ }
251+ if (!savedWork .getStartTime ().equals (firstProjectDateTime )) {
252+ return false ;
253+ }
254+ if (!savedWork .getEndTime ().equals (firstProjectPlusOneHour )) {
255+ return false ;
256+ }
257+ return true ;
258+ }));
259+
260+ assertThat ("Two projects should be in the past work items" , model .getPastWorkItems ().size (), is (2 ));
261+ assertThat ("The first project should be '1st Project'" , model .getPastWorkItems ().get (0 ).getProject (),
262+ is (firstProject ));
263+ assertThat ("The second project should be '2ndProject'" , model .getPastWorkItems ().get (1 ).getProject (),
240264 is (secondProject ));
265+ final Work work = model .activeWorkItem .get ();
266+ assertThat ("'2ndProject' should be the active work project" , work .getProject (), is (secondProject ));
267+ assertThat (work .getCreationDate (), is (firstProjectDateTime .toLocalDate ()));
268+ assertThat (work .getStartTime (), is (firstProjectPlusOneHour ));
241269 }
242270
243271}
0 commit comments