[BAEL-3315] Added missing code snippets from the Java 8 Date/Time article
Also: - formatted changed files with Eclipse profile - corrected failing test: givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.datetime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class UseToInstantUnitTest {
|
||||
|
||||
private UseToInstant subject = new UseToInstant();
|
||||
|
||||
@Test
|
||||
public void givenAGregorianCalenderDate_whenConvertingToLocalDate_thenAsExpected() {
|
||||
GregorianCalendar givenCalender = new GregorianCalendar(2018, Calendar.JULY, 28);
|
||||
|
||||
LocalDateTime localDateTime = subject.convertDateToLocalDate(givenCalender);
|
||||
|
||||
assertThat(localDateTime).isEqualTo("2018-07-28T00:00:00");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenADate_whenConvertingToLocalDate_thenAsExpected() {
|
||||
Date givenDate = new Date(1465817690000L);
|
||||
|
||||
LocalDateTime localDateTime = subject.convertDateToLocalDate(givenDate);
|
||||
|
||||
assertThat(localDateTime).isEqualTo("2016-06-13T13:34:50");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user