Skip to content

Commit 3dd2f4b

Browse files
authored
Improved all tests in TestHudiInstantUtils by parameterising and adding more test cases (#703)
* imprved 2 tests in TestHudiInstantUtils by parameterizing and adding more test cases * fixed style issues
1 parent aa31ae8 commit 3dd2f4b

1 file changed

Lines changed: 56 additions & 17 deletions

File tree

xtable-core/src/test/java/org/apache/xtable/hudi/TestHudiInstantUtils.java

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,67 @@
2121
import static org.junit.jupiter.api.Assertions.assertEquals;
2222

2323
import java.time.Instant;
24+
import java.util.stream.Stream;
2425

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;
2629

2730
public class TestHudiInstantUtils {
2831

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));
3736
}
3837

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+
);
4786
}
4887
}

0 commit comments

Comments
 (0)