|
21 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
22 | 22 |
|
23 | 23 | import java.time.Instant; |
| 24 | +import java.util.stream.Stream; |
24 | 25 |
|
25 | | -import org.junit.jupiter.api.Test; |
| 26 | +import org.junit.jupiter.params.ParameterizedTest; |
| 27 | +import org.junit.jupiter.params.provider.Arguments; |
| 28 | +import org.junit.jupiter.params.provider.MethodSource; |
26 | 29 |
|
27 | 30 | public class TestHudiInstantUtils { |
28 | 31 |
|
29 | | - @Test |
30 | | - public void testParseCommitTimeToInstant() { |
31 | | - assertEquals( |
32 | | - Instant.parse("2023-01-20T04:43:31.843Z"), |
33 | | - HudiInstantUtils.parseFromInstantTime("20230120044331843")); |
34 | | - assertEquals( |
35 | | - Instant.parse("2023-01-20T04:43:31.999Z"), |
36 | | - HudiInstantUtils.parseFromInstantTime("20230120044331")); |
| 32 | + @ParameterizedTest |
| 33 | + @MethodSource("instantTimeParseTestCases") |
| 34 | + public void testParseCommitTimeToInstant(String commitTime, Instant expectedInstant) { |
| 35 | + assertEquals(expectedInstant, HudiInstantUtils.parseFromInstantTime(commitTime)); |
37 | 36 | } |
38 | 37 |
|
39 | | - @Test |
40 | | - public void testInstantToCommit() { |
41 | | - assertEquals( |
42 | | - "20230120044331843", |
43 | | - HudiInstantUtils.convertInstantToCommit(Instant.parse("2023-01-20T04:43:31.843Z"))); |
44 | | - assertEquals( |
45 | | - "20230120044331000", |
46 | | - HudiInstantUtils.convertInstantToCommit(Instant.parse("2023-01-20T04:43:31Z"))); |
| 38 | + private static Stream<Arguments> instantTimeParseTestCases() { |
| 39 | + return Stream.of( |
| 40 | + // Original test cases |
| 41 | + Arguments.of("20230120044331843", Instant.parse("2023-01-20T04:43:31.843Z")), |
| 42 | + Arguments.of("20230120044331", Instant.parse("2023-01-20T04:43:31.999Z")), |
| 43 | + |
| 44 | + // Additional test cases |
| 45 | + Arguments.of("19700101000000000", Instant.parse("1970-01-01T00:00:00.000Z")), // Unix epoch |
| 46 | + Arguments.of( |
| 47 | + "19700101000000", |
| 48 | + Instant.parse("1970-01-01T00:00:00.999Z")), // Unix epoch without millis |
| 49 | + Arguments.of( |
| 50 | + "20251224235959123", |
| 51 | + Instant.parse("2025-12-24T23:59:59.123Z")), // Future date with millis |
| 52 | + Arguments.of( |
| 53 | + "20251224235959", |
| 54 | + Instant.parse("2025-12-24T23:59:59.999Z")), // Future date without millis |
| 55 | + Arguments.of("20200229235959123", Instant.parse("2020-02-29T23:59:59.123Z")), // Leap year |
| 56 | + Arguments.of( |
| 57 | + "20200229235959", Instant.parse("2020-02-29T23:59:59.999Z")) // Leap year without millis |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + @ParameterizedTest |
| 62 | + @MethodSource("instantToCommitTestCases") |
| 63 | + public void testInstantToCommit(Instant instant, String expectedCommitTime) { |
| 64 | + assertEquals(expectedCommitTime, HudiInstantUtils.convertInstantToCommit(instant)); |
| 65 | + } |
| 66 | + |
| 67 | + private static Stream<Arguments> instantToCommitTestCases() { |
| 68 | + return Stream.of( |
| 69 | + // Original test cases |
| 70 | + Arguments.of(Instant.parse("2023-01-20T04:43:31.843Z"), "20230120044331843"), |
| 71 | + Arguments.of(Instant.parse("2023-01-20T04:43:31Z"), "20230120044331000"), |
| 72 | + |
| 73 | + // Additional test cases |
| 74 | + Arguments.of(Instant.parse("1970-01-01T00:00:00Z"), "19700101000000000"), // Unix epoch |
| 75 | + Arguments.of( |
| 76 | + Instant.parse("1970-01-01T00:00:00.123Z"), |
| 77 | + "19700101000000123"), // Unix epoch with millis |
| 78 | + Arguments.of(Instant.parse("2025-12-24T23:59:59Z"), "20251224235959000"), // Future date |
| 79 | + Arguments.of( |
| 80 | + Instant.parse("2025-12-24T23:59:59.999Z"), |
| 81 | + "20251224235959999"), // Future date with max millis |
| 82 | + Arguments.of(Instant.parse("2020-02-29T23:59:59Z"), "20200229235959000"), // Leap year |
| 83 | + Arguments.of( |
| 84 | + Instant.parse("2021-12-31T23:59:59.555Z"), "20211231235959555") // Year end with millis |
| 85 | + ); |
47 | 86 | } |
48 | 87 | } |
0 commit comments