[JAVA-6221] Test clean up
This commit is contained in:
parent
f9dc97d25e
commit
6f11290160
|
@ -1,12 +1,13 @@
|
|||
package com.baeldung.java9.time;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TimeApiUnitTest {
|
||||
|
||||
|
@ -18,19 +19,18 @@ public class TimeApiUnitTest {
|
|||
Date endDate = endCalendar.getTime();
|
||||
|
||||
List<Date> dates = TimeApi.getDatesBetweenUsingJava7(startDate, endDate);
|
||||
assertEquals(2, dates.size());
|
||||
|
||||
assertThat(dates).hasSize(2);
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
Date date1 = calendar.getTime();
|
||||
assertEquals(date1.getDay(), dates.get(0).getDay());
|
||||
assertEquals(date1.getMonth(), dates.get(0).getMonth());
|
||||
assertEquals(date1.getYear(), dates.get(0).getYear());
|
||||
Date expectedDate1 = calendar.getTime();
|
||||
assertThat(dates.get(0)).isInSameDayAs(expectedDate1);
|
||||
assertThatTimeFieldsAreZero(dates.get(0));
|
||||
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
Date date2 = calendar.getTime();
|
||||
assertEquals(date2.getDay(), dates.get(1).getDay());
|
||||
assertEquals(date2.getMonth(), dates.get(1).getMonth());
|
||||
assertEquals(date2.getYear(), dates.get(1).getYear());
|
||||
Date expectedDate2 = calendar.getTime();
|
||||
assertThat(dates.get(1)).isInSameDayAs(expectedDate2);
|
||||
assertThatTimeFieldsAreZero(dates.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -39,9 +39,8 @@ public class TimeApiUnitTest {
|
|||
LocalDate endDate = LocalDate.now().plusDays(2);
|
||||
|
||||
List<LocalDate> dates = TimeApi.getDatesBetweenUsingJava8(startDate, endDate);
|
||||
assertEquals(dates.size(), 2);
|
||||
assertEquals(dates.get(0), LocalDate.now());
|
||||
assertEquals(dates.get(1), LocalDate.now().plusDays(1));
|
||||
|
||||
assertThat(dates).containsExactly(LocalDate.now(), LocalDate.now().plusDays(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,9 +49,15 @@ public class TimeApiUnitTest {
|
|||
LocalDate endDate = LocalDate.now().plusDays(2);
|
||||
|
||||
List<LocalDate> dates = TimeApi.getDatesBetweenUsingJava9(startDate, endDate);
|
||||
assertEquals(dates.size(), 2);
|
||||
assertEquals(dates.get(0), LocalDate.now());
|
||||
assertEquals(dates.get(1), LocalDate.now().plusDays(1));
|
||||
|
||||
assertThat(dates).containsExactly(LocalDate.now(), LocalDate.now().plusDays(1));
|
||||
}
|
||||
|
||||
private static void assertThatTimeFieldsAreZero(Date date) {
|
||||
assertThat(date).hasHourOfDay(0);
|
||||
assertThat(date).hasMinute(0);
|
||||
assertThat(date).hasSecond(0);
|
||||
assertThat(date).hasMillisecond(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue