|
1 | 1 | package com.cloud.chatbot; |
2 | 2 |
|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
4 | 5 |
|
5 | 6 | import java.time.Instant; |
| 7 | +import java.util.Arrays; |
6 | 8 |
|
7 | 9 | import org.junit.jupiter.api.Test; |
8 | 10 |
|
9 | 11 |
|
10 | 12 |
|
11 | | -// Assuming the "user" is on a GMT+8 system |
| 13 | +// Assuming the "user" is on a GMT+8 or GMT/UTC system |
12 | 14 | public class DateConverterTest { |
13 | 15 | @Test |
14 | 16 | public void timestampToInstant() { |
15 | 17 | Instant instantExpected = Instant.parse("2023-01-31T20:56:00Z"); |
16 | 18 | Instant instantActual = DateConverter.timestampToInstant("1 2 23 456"); |
| 19 | + Instant instantActual2 = DateConverter.timestampToInstant("1 1 31 2056"); |
17 | 20 | assertEquals(instantExpected, instantActual); |
| 21 | + assertTrue( |
| 22 | + Arrays.asList(instantActual, instantActual2) |
| 23 | + .contains(instantExpected) |
| 24 | + ); |
18 | 25 | } |
19 | 26 |
|
20 | 27 | @Test |
21 | 28 | public void instantToPrettyTimestamp_nonZeroMinutes() { |
22 | 29 | Instant instant = Instant.parse("2023-01-31T20:56:00Z"); |
23 | 30 | String timestamp = DateConverter.instantToPrettyTimestamp(instant); |
24 | | - assertEquals("1 Feb '23, 4:56am", timestamp); |
| 31 | + assertTrue( |
| 32 | + Arrays.asList("1 Feb '23, 4:56am", "31 Jan '23, 8:56pm") |
| 33 | + .contains(timestamp) |
| 34 | + ); |
25 | 35 | } |
26 | 36 |
|
27 | 37 | @Test |
28 | 38 | public void instantToPrettyTimestamp_zeroMinutes() { |
29 | 39 | Instant instant = Instant.parse("2023-09-14T13:00:00Z"); |
30 | 40 | String timestamp = DateConverter.instantToPrettyTimestamp(instant); |
31 | | - assertEquals("14 Sep '23, 9pm", timestamp); |
| 41 | + assertTrue( |
| 42 | + Arrays.asList("14 Sep '23, 9pm", "14 Sep '23, 1pm") |
| 43 | + .contains(timestamp) |
| 44 | + ); |
32 | 45 | } |
33 | 46 | } |
0 commit comments