Files
spring-boot-rest/java-dates/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java
Martin van Wingerden 1de7b016a8 [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
2019-10-23 11:04:40 +02:00

36 lines
1.1 KiB
Java

package com.baeldung.datetime;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.FormatStyle;
import java.util.Locale;
import org.junit.Test;
public class UseDateTimeFormatterUnitTest {
private final UseDateTimeFormatter subject = new UseDateTimeFormatter();
private final LocalDateTime localDateTime = LocalDateTime.of(2015, Month.JANUARY, 25, 6, 30);
@Test
public void givenALocalDate_whenFormattingAsIso_thenPass() {
String result = subject.formatAsIsoDate(localDateTime);
assertThat(result).isEqualTo("2015-01-25");
}
@Test
public void givenALocalDate_whenFormattingWithPattern_thenPass() {
String result = subject.formatCustom(localDateTime, "yyyy/MM/dd");
assertThat(result).isEqualTo("2015/01/25");
}
@Test
public void givenALocalDate_whenFormattingWithStyleAndLocale_thenPass() {
String result = subject.formatWithStyleAndLocale(localDateTime, FormatStyle.MEDIUM, Locale.UK);
assertThat(result).isEqualTo("25 Jan 2015, 06:30:00");
}
}