|
| 1 | +package com.baeldung.lastdaymonth; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import java.time.LocalDate; |
| 6 | +import java.time.YearMonth; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | + |
| 10 | +class LastDayOfMonthUnitTest { |
| 11 | + |
| 12 | + @Test |
| 13 | + void givenMonth_whenUsingCalendar_thenReturnLastDay() { |
| 14 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingCalendar(0)); |
| 15 | + assertEquals(30, LastDayOfMonth.getLastDayOfMonthUsingCalendar(3)); |
| 16 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingCalendar(9)); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + void givenMonth_whenUsingTemporalAdjusters_thenReturnLastDay() { |
| 21 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingTemporalAdjusters(LocalDate.of(2023, 1, 1))); |
| 22 | + assertEquals(30, LastDayOfMonth.getLastDayOfMonthUsingTemporalAdjusters(LocalDate.of(2023, 4, 1))); |
| 23 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingTemporalAdjusters(LocalDate.of(2023, 10, 1))); |
| 24 | + } |
| 25 | + |
| 26 | + @Test |
| 27 | + void givenMonth_whenUsingYearMonth_thenReturnLastDay() { |
| 28 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingYearMonth(YearMonth.of(2023, 1))); |
| 29 | + assertEquals(30, LastDayOfMonth.getLastDayOfMonthUsingYearMonth(YearMonth.of(2023, 4))); |
| 30 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingYearMonth(YearMonth.of(2023, 10))); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void givenMonth_whenUsingJodaTime_thenReturnLastDay() { |
| 35 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingJodaTime(org.joda.time.LocalDate.parse("2023-1-1"))); |
| 36 | + assertEquals(30, LastDayOfMonth.getLastDayOfMonthUsingJodaTime(org.joda.time.LocalDate.parse("2023-4-1"))); |
| 37 | + assertEquals(31, LastDayOfMonth.getLastDayOfMonthUsingJodaTime(org.joda.time.LocalDate.parse("2023-10-1"))); |
| 38 | + } |
| 39 | + |
| 40 | +} |
0 commit comments