[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:
Martin van Wingerden
2019-10-23 11:04:40 +02:00
parent 621d4629e8
commit 1de7b016a8
17 changed files with 330 additions and 43 deletions

View File

@@ -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");
}
}