|
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"); |
17 | | - assertEquals(instantExpected, instantActual); |
| 19 | + Instant instantActual2 = DateConverter.timestampToInstant("1 1 31 2056"); |
| 20 | + assertTrue( |
| 21 | + Arrays.asList(instantActual, instantActual2) |
| 22 | + .contains(instantExpected) |
| 23 | + ); |
18 | 24 | } |
19 | 25 |
|
20 | 26 | @Test |
21 | 27 | public void instantToPrettyTimestamp_nonZeroMinutes() { |
22 | 28 | Instant instant = Instant.parse("2023-01-31T20:56:00Z"); |
23 | 29 | String timestamp = DateConverter.instantToPrettyTimestamp(instant); |
24 | | - assertEquals("1 Feb '23, 4:56am", timestamp); |
| 30 | + assertTrue( |
| 31 | + Arrays.asList("1 Feb '23, 4:56am", "31 Jan '23, 8:56pm") |
| 32 | + .contains(timestamp) |
| 33 | + ); |
25 | 34 | } |
26 | 35 |
|
27 | 36 | @Test |
28 | 37 | public void instantToPrettyTimestamp_zeroMinutes() { |
29 | 38 | Instant instant = Instant.parse("2023-09-14T13:00:00Z"); |
30 | 39 | String timestamp = DateConverter.instantToPrettyTimestamp(instant); |
31 | | - assertEquals("14 Sep '23, 9pm", timestamp); |
| 40 | + assertTrue( |
| 41 | + Arrays.asList("14 Sep '23, 9pm", "14 Sep '23, 1pm") |
| 42 | + .contains(timestamp) |
| 43 | + ); |
32 | 44 | } |
33 | 45 | } |
0 commit comments