This is an automated email from the ASF dual-hosted git repository. fanrui pushed a commit to branch release-1.18 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 6675de8210647038ef8f12dd538a7af189d77f49 Author: Rui Fan <[email protected]> AuthorDate: Tue Dec 5 19:48:54 2023 +0800 [FLINK-33752][JUnit5 migration] Migrate TimeUtilsPrettyPrintingTest to Junit5 and Assertj --- .../flink/util/TimeUtilsPrettyPrintingTest.java | 46 ++++++++++------------ 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/flink-core/src/test/java/org/apache/flink/util/TimeUtilsPrettyPrintingTest.java b/flink-core/src/test/java/org/apache/flink/util/TimeUtilsPrettyPrintingTest.java index 1572c92b8e0..9862e993b74 100644 --- a/flink-core/src/test/java/org/apache/flink/util/TimeUtilsPrettyPrintingTest.java +++ b/flink-core/src/test/java/org/apache/flink/util/TimeUtilsPrettyPrintingTest.java @@ -18,38 +18,32 @@ package org.apache.flink.util; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import java.time.Duration; +import java.util.stream.Stream; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** Tests for {@link TimeUtils#formatWithHighestUnit(Duration)}. */ -@RunWith(Parameterized.class) -public class TimeUtilsPrettyPrintingTest extends TestLogger { - @Parameterized.Parameters - public static Object[][] parameters() { - return new Object[][] { - new Object[] {Duration.ofMinutes(3).plusSeconds(30), "210 s"}, - new Object[] {Duration.ofNanos(100), "100 ns"}, - new Object[] {Duration.ofSeconds(120), "2 min"}, - new Object[] {Duration.ofMillis(200), "200 ms"}, - new Object[] {Duration.ofHours(1).plusSeconds(3), "3603 s"}, - new Object[] {Duration.ofSeconds(0), "0 ms"}, - new Object[] {Duration.ofMillis(60000), "1 min"} - }; +class TimeUtilsPrettyPrintingTest { + + private static Stream<Arguments> testDurationAndExpectedString() { + return Stream.of( + Arguments.of(Duration.ofMinutes(3).plusSeconds(30), "210 s"), + Arguments.of(Duration.ofNanos(100), "100 ns"), + Arguments.of(Duration.ofSeconds(120), "2 min"), + Arguments.of(Duration.ofMillis(200), "200 ms"), + Arguments.of(Duration.ofHours(1).plusSeconds(3), "3603 s"), + Arguments.of(Duration.ofSeconds(0), "0 ms"), + Arguments.of(Duration.ofMillis(60000), "1 min")); } - @Parameterized.Parameter public Duration duration; - - @Parameterized.Parameter(1) - public String expectedString; - - @Test - public void testFormatting() { - assertThat(TimeUtils.formatWithHighestUnit(duration), is(expectedString)); + @ParameterizedTest + @MethodSource("testDurationAndExpectedString") + void testFormatting(Duration duration, String expectedString) { + assertThat(TimeUtils.formatWithHighestUnit(duration)).isEqualTo(expectedString); } }
