You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/01 17:42:49 UTC

[GitHub] [flink] reswqa commented on a diff in pull request #20129: [FLINK-27941][kinesis][test] Migrate tests to junit5

reswqa commented on code in PR #20129:
URL: https://github.com/apache/flink/pull/20129#discussion_r912126079


##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumerMigrationTest.java:
##########
@@ -66,7 +65,6 @@
  * <p>For regenerating the binary snapshot files run {@link #writeSnapshot()} on the corresponding
  * Flink release-* branch.
  */
-@RunWith(Parameterized.class)
 public class FlinkKinesisConsumerMigrationTest {

Review Comment:
   ```suggestion
   class FlinkKinesisConsumerMigrationTest {
   ```



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumerMigrationTest.java:
##########
@@ -66,7 +65,6 @@
  * <p>For regenerating the binary snapshot files run {@link #writeSnapshot()} on the corresponding
  * Flink release-* branch.
  */
-@RunWith(Parameterized.class)
 public class FlinkKinesisConsumerMigrationTest {

Review Comment:
   Test class should be package-private in junit5



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/KinesisConsumerTest.java:
##########
@@ -23,21 +23,19 @@
 import org.apache.flink.util.Collector;
 import org.apache.flink.util.TestLogger;
 
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 
 import java.io.IOException;
 import java.util.Properties;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
 /**
  * Tests for {@link FlinkKinesisConsumer}. In contrast to tests in {@link FlinkKinesisConsumerTest}
  * it does not use power mock, which makes it possible to use e.g. the {@link ExpectedException}.
  */
 public class KinesisConsumerTest extends TestLogger {

Review Comment:
   ```suggestion
   @ExtendWith(TestLoggerExtension.class)
   class KinesisConsumerTest {
   ```



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumerMigrationTest.java:
##########
@@ -131,8 +122,9 @@ public void writeSnapshot() throws Exception {
                 new HashMap<>());
     }
 
-    @Test
-    public void testRestoreWithEmptyState() throws Exception {
+    @ParameterizedTest
+    @MethodSource("flinkVersionProvider")
+    public void testRestoreWithEmptyState(FlinkVersion flinkVersion) throws Exception {

Review Comment:
   ```suggestion
       void testRestoreWithEmptyState(FlinkVersion flinkVersion) throws Exception {
   ```



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumerMigrationTest.java:
##########
@@ -131,8 +122,9 @@ public void writeSnapshot() throws Exception {
                 new HashMap<>());
     }
 
-    @Test
-    public void testRestoreWithEmptyState() throws Exception {
+    @ParameterizedTest
+    @MethodSource("flinkVersionProvider")
+    public void testRestoreWithEmptyState(FlinkVersion flinkVersion) throws Exception {

Review Comment:
   If there is no special reason, the test method should be marked as package-private



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/metrics/PollingRecordPublisherMetricsReporterTest.java:
##########
@@ -37,7 +37,7 @@ public class PollingRecordPublisherMetricsReporterTest {
 
     @Mock private MetricGroup metricGroup;
 
-    @Before
+    @BeforeEach
     public void setUp() {

Review Comment:
   Lifecycle method should marked as package-private also.



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/metrics/PollingRecordPublisherMetricsReporterTest.java:
##########
@@ -37,7 +37,7 @@ public class PollingRecordPublisherMetricsReporterTest {
 
     @Mock private MetricGroup metricGroup;
 
-    @Before
+    @BeforeEach
     public void setUp() {

Review Comment:
   ```suggestion
       void setUp() {
   ```



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/util/KinesisConfigUtilTest.java:
##########
@@ -23,9 +23,7 @@
 import org.apache.flink.streaming.connectors.kinesis.testutils.TestUtils;
 
 import com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
+import org.junit.jupiter.api.Test;
 import org.junit.runner.RunWith;
 import org.powermock.modules.junit4.PowerMockRunner;

Review Comment:
   I'm not sure whether it's reasonable to still use `org.powermock.modules.junit4.PowerMockRunner` here. To be honest, I don't know which class should be used to replace it. You'd better confirm it again.



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/internals/publisher/fanout/FanOutShardSubscriberTest.java:
##########
@@ -23,143 +23,174 @@
 
 import com.amazonaws.http.timers.client.SdkInterruptedException;
 import io.netty.handler.timeout.ReadTimeoutException;
-import org.junit.Rule;
 import org.junit.Test;

Review Comment:
   Why org.junit.Test still exist



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisConsumerMigrationTest.java:
##########
@@ -131,8 +122,9 @@ public void writeSnapshot() throws Exception {
                 new HashMap<>());
     }
 
-    @Test
-    public void testRestoreWithEmptyState() throws Exception {
+    @ParameterizedTest
+    @MethodSource("flinkVersionProvider")
+    public void testRestoreWithEmptyState(FlinkVersion flinkVersion) throws Exception {

Review Comment:
   In JUnit 5, test classes, test methods, and lifecycle methods are not required to be public, but they must not be private. And the [JUnit5 user guide ](https://junit.org/junit5/docs/snapshot/user-guide/#writing-tests-classes-and-methods)recommends omitting the public modifier for them unless there is a technical reason – for example, when a test class is extended by a test class in another package. So please follow this rule in the migration.



##########
flink-connectors/flink-connector-kinesis/src/test/java/org/apache/flink/streaming/connectors/kinesis/FlinkKinesisProducerTest.java:
##########
@@ -62,19 +61,20 @@
 /** Suite of {@link FlinkKinesisProducer} tests. */
 public class FlinkKinesisProducerTest extends TestLogger {
 
-    @Rule public ExpectedException exception = ExpectedException.none();
-
     // ----------------------------------------------------------------------
     // Tests to verify serializability
     // ----------------------------------------------------------------------
 
     @Test
     public void testCreateWithNonSerializableDeserializerFails() {
-        exception.expect(IllegalArgumentException.class);
-        exception.expectMessage("The provided serialization schema is not serializable");
-
-        new FlinkKinesisProducer<>(
-                new NonSerializableSerializationSchema(), TestUtils.getStandardProperties());
+        assertThatThrownBy(
+                        () -> {
+                            new FlinkKinesisProducer<>(
+                                    new NonSerializableSerializationSchema(),
+                                    TestUtils.getStandardProperties());
+                        })

Review Comment:
   ```suggestion
           assertThatThrownBy(
                           () ->
                               new FlinkKinesisProducer<>(
                                       new NonSerializableSerializationSchema(),
                                       TestUtils.getStandardProperties()))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org