|
| 1 | +package com.baeldung.datetime; |
| 2 | + |
| 3 | +import java.time.DayOfWeek; |
| 4 | +import java.time.LocalDate; |
| 5 | +import java.time.LocalDateTime; |
| 6 | +import java.time.Month; |
| 7 | + |
| 8 | +import org.junit.Assert; |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +public class UseLocalDateTest { |
| 12 | + |
| 13 | + UseLocalDate useLocalDate = new UseLocalDate(); |
| 14 | + |
| 15 | + @Test |
| 16 | + public void givenValues_whenUsingFactoryOf_thenLocalDate(){ |
| 17 | + Assert.assertEquals("2016-05-10",useLocalDate.getLocalDateUsingFactoryOfMethod(2016,5,10).toString()); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void givenString_whenUsingParse_thenLocalDate(){ |
| 22 | + Assert.assertEquals("2016-05-10",useLocalDate.getLocalDateUsingParseMethod("2016-05-10").toString()); |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + public void whenUsingClock_thenLocalDate(){ |
| 27 | + Assert.assertEquals(LocalDate.now(),useLocalDate.getLocalDateFromClock()); |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + public void givenDate_whenUsingPlus_thenNextDay(){ |
| 32 | + Assert.assertEquals(LocalDate.now().plusDays(1),useLocalDate.getNextDay(LocalDate.now())); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void givenDate_whenUsingMinus_thenPreviousDay(){ |
| 37 | + Assert.assertEquals(LocalDate.now().minusDays(1),useLocalDate.getPreviousDay(LocalDate.now())); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void givenToday_whenUsingGetDayOfWeek_thenDayOfWeek(){ |
| 42 | + Assert.assertEquals(DayOfWeek.SUNDAY,useLocalDate.getDayOfWeek(LocalDate.parse("2016-05-22"))); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void givenToday_whenUsingWithTemporalAdjuster_thenFirstDayOfMonth(){ |
| 47 | + Assert.assertEquals(1,useLocalDate.getFirstDayOfMonth().getDayOfMonth()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void givenLocalDate_whenUsingAtStartOfDay_thenReturnMidnight(){ |
| 52 | + Assert.assertEquals(LocalDateTime.parse("2016-05-22T00:00:00"),useLocalDate.getStartOfDay(LocalDate.parse("2016-05-22"))); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments