37 lines
1.4 KiB
Java
Raw Normal View History

2016-10-28 07:29:07 +02:00
package com.baeldung.datetime;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
2016-10-28 07:29:07 +02:00
import java.time.LocalDate;
import java.time.LocalDateTime;
2016-10-28 07:29:07 +02:00
import java.time.LocalTime;
import java.time.Month;
import org.junit.Test;
2016-10-29 11:50:29 +02:00
public class UseLocalDateTimeUnitTest {
2016-11-03 18:04:09 +02:00
2016-10-28 07:29:07 +02:00
UseLocalDateTime useLocalDateTime = new UseLocalDateTime();
2016-11-03 18:04:09 +02:00
2016-10-28 07:29:07 +02:00
@Test
2016-11-03 18:04:09 +02:00
public void givenString_whenUsingParse_thenLocalDateTime() {
2017-08-24 13:11:52 +03:00
assertEquals(LocalDate.of(2016, Month.MAY, 10), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
.toLocalDate());
assertEquals(LocalTime.of(6, 30), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
.toLocalTime());
2016-10-28 07:29:07 +02:00
}
@Test
public void givenLocalDateTime_whenSettingEndOfDay_thenReturnLastMomentOfDay() {
LocalDateTime givenTimed = LocalDateTime.parse("2018-06-23T05:55:55");
LocalDateTime endOfDayFromGivenDirectly = useLocalDateTime.getEndOfDayFromLocalDateTimeDirectly(givenTimed);
LocalDateTime endOfDayFromGiven = useLocalDateTime.getEndOfDayFromLocalDateTime(givenTimed);
assertThat(endOfDayFromGivenDirectly).isEqualTo(endOfDayFromGiven);
assertThat(endOfDayFromGivenDirectly.toLocalTime()).isEqualTo(LocalTime.MAX);
assertThat(endOfDayFromGivenDirectly.toString()).isEqualTo("2018-06-23T23:59:59.999999999");
}
2016-10-28 07:29:07 +02:00
}