Skip to content

Commit 68ad2a6

Browse files
authored
This PR is related to BAEL-8116 (#17586)
* This commit is related to BAEL-8116 This commit aims to add a Java class to the module. * Update DateTimeCombinationUnitTest.java
1 parent aa03f32 commit 68ad2a6

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.baeldung.datetimecombination;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.time.LocalDate;
6+
import java.time.LocalDateTime;
7+
import java.time.LocalTime;
8+
import java.time.temporal.ChronoField;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
public class DateTimeCombinationUnitTest {
13+
LocalDate date = LocalDate.of(2023, 9, 12);
14+
LocalTime time = LocalTime.of(14, 30);
15+
LocalDateTime expectedDateTime = LocalDateTime.parse("2023-09-12T14:30");
16+
17+
@Test
18+
public void givenDateAndTime_whenUsingLocalDateTimeOf_thenCombined() {
19+
LocalDateTime combinedDateTime = LocalDateTime.of(date, time);
20+
21+
assertEquals(expectedDateTime, combinedDateTime);
22+
}
23+
24+
@Test
25+
public void givenDateAndTime_whenUsingAtTime_thenCombined() {
26+
LocalDateTime combinedDateTime = date.atTime(time);
27+
28+
assertEquals(expectedDateTime, combinedDateTime);
29+
}
30+
31+
@Test
32+
public void givenDateAndTime_whenAdjustingTime_thenCombined() {
33+
LocalDate date = LocalDate.of(2024, 9, 18);
34+
LocalTime originalTime = LocalTime.of(14, 45);
35+
36+
LocalTime adjustedTime = originalTime.with(ChronoField.MINUTE_OF_HOUR, 0);
37+
LocalDateTime expectedAdjustedDateTime = LocalDateTime.of(date, adjustedTime);
38+
39+
LocalDateTime actualDateTime = date.atTime(adjustedTime);
40+
41+
assertEquals(expectedAdjustedDateTime, actualDateTime);
42+
}
43+
}

0 commit comments

Comments
 (0)