Jiabao-Sun commented on code in PR #23960:
URL: https://github.com/apache/flink/pull/23960#discussion_r1496101020
##########
flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/EnumSerializerTest.java:
##########
@@ -27,24 +27,23 @@
import org.apache.flink.util.InstantiationUtil;
import org.apache.flink.util.TestLogger;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class EnumSerializerTest extends TestLogger {
+class EnumSerializerTest extends TestLogger {
Review Comment:
```suggestion
class EnumSerializerTest {
```
Already exists in
src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
##########
flink-core/src/test/java/org/apache/flink/api/common/typeutils/base/EnumSerializerCompatibilityTest.java:
##########
@@ -24,21 +24,23 @@
import org.apache.flink.core.memory.DataInputViewStreamWrapper;
import org.apache.flink.core.memory.DataOutputViewStreamWrapper;
import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.junit.utils.TempDirUtils;
import org.apache.flink.util.TestLogger;
-import org.junit.Assert;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.nio.file.Path;
-public class EnumSerializerCompatibilityTest extends TestLogger {
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
- @ClassRule public static TemporaryFolder temporaryFolder = new
TemporaryFolder();
+class EnumSerializerCompatibilityTest extends TestLogger {
Review Comment:
```suggestion
class EnumSerializerCompatibilityTest {
```
##########
flink-core/src/test/java/org/apache/flink/api/common/operators/DualInputSemanticPropertiesTest.java:
##########
@@ -20,16 +20,15 @@
import org.apache.flink.api.common.operators.util.FieldSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
Review Comment:
```suggestion
import static org.assertj.core.api.Assertions.assertThatThrownBy;
```
##########
flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java:
##########
@@ -33,42 +33,46 @@
import org.apache.flink.api.java.typeutils.TypeExtractor;
import org.apache.commons.lang3.ArrayUtils;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
+import static org.assertj.core.api.Assertions.assertThat;
+import static
org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
Review Comment:
```suggestion
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
```
##########
flink-core/src/test/java/org/apache/flink/api/common/operators/ExpressionKeysTest.java:
##########
@@ -148,24 +152,25 @@ public void testInvalidTuple() throws Throwable {
} catch (Throwable t) {
e = t;
}
- Assert.assertNotNull(e);
+ assertThat(e).isNotNull();
Review Comment:
It looks like it was overlooked.
##########
flink-core/src/test/java/org/apache/flink/api/common/io/GlobFilePathFilterTest.java:
##########
@@ -21,43 +21,41 @@
import org.apache.flink.core.testutils.CommonTestUtils;
import org.apache.flink.util.OperatingSystem;
-import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
Review Comment:
```suggestion
import static org.assertj.core.api.Assertions.assertThatThrownBy;
```
##########
flink-core/src/test/java/org/apache/flink/api/common/io/FileOutputFormatTest.java:
##########
@@ -24,620 +24,617 @@
import org.apache.flink.core.fs.Path;
import org.apache.flink.types.IntValue;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
-import static org.junit.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatNoException;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
-public class FileOutputFormatTest {
+class FileOutputFormatTest {
@Test
- public void testCreateNonParallelLocalFS() throws IOException {
+ void testCreateNonParallelLocalFS() throws IOException {
File tmpOutPath = File.createTempFile("fileOutputFormatTest", "Test1");
File tmpOutFile = new File(tmpOutPath.getAbsolutePath() + "/1");
String tmpFilePath = tmpOutPath.toURI().toString();
// check fail if file exists
- DummyFileOutputFormat dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
-
- dfof.configure(new Configuration());
-
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new
DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+
dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+
+ dfof.configure(new Configuration());
+
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutPath.delete();
// check fail if directory exists
- Assert.assertTrue("Directory could not be created.",
tmpOutPath.mkdir());
+ assertThat(tmpOutPath.mkdir()).as("Directory could not be
created.").isTrue();
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
+ assertThatThrownBy(
+ () -> {
+ DummyFileOutputFormat dfof = new
DummyFileOutputFormat();
+ dfof.setOutputFilePath(new Path(tmpFilePath));
+ dfof.setWriteMode(WriteMode.NO_OVERWRITE);
+
dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
- dfof.configure(new Configuration());
+ dfof.configure(new Configuration());
- try {
- dfof.open(0, 1);
- dfof.close();
- fail();
- } catch (Exception e) {
- // exception expected
- }
+ dfof.open(0, 1);
+ dfof.close();
+ })
+ .isInstanceOf(Exception.class);
tmpOutPath.delete();
// check success
- dfof = new DummyFileOutputFormat();
- dfof.setOutputFilePath(new Path(tmpFilePath));
- dfof.setWriteMode(WriteMode.NO_OVERWRITE);
- dfof.setOutputDirectoryMode(OutputDirectoryMode.PARONLY);
-
- dfof.configure(new Configuration());
-
- try {
- dfof.open(0, 1);
- dfof.close();
- } catch (Exception e) {
- fail();
- }
- Assert.assertTrue(tmpOutPath.exists() && tmpOutPath.isFile());
+ assertThatNoException()
Review Comment:
Nit: this may be unnecessary.
##########
flink-core/src/test/java/org/apache/flink/api/common/typeutils/SerializerTestBase.java:
##########
@@ -100,29 +96,24 @@ protected boolean allowNullInstances(TypeSerializer<T>
serializer) {
@Test
protected void testInstantiate() {
- try {
- TypeSerializer<T> serializer = getSerializer();
- T instance = serializer.createInstance();
- if (instance == null && allowNullInstances(serializer)) {
- return;
- }
- assertNotNull("The created instance must not be null.", instance);
-
- Class<T> type = getTypeClass();
- assertNotNull("The test is corrupt: type class is null.", type);
-
- if (!type.isAssignableFrom(instance.getClass())) {
- fail(
- "Type of the instantiated object is wrong. "
- + "Expected Type: "
- + type
- + " present type "
- + instance.getClass());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- e.printStackTrace();
- fail("Exception in test: " + e.getMessage());
+
+ TypeSerializer<T> serializer = getSerializer();
+ T instance = serializer.createInstance();
+ if (instance == null && allowNullInstances(serializer)) {
+ return;
+ }
+ assertThat(instance).as("The created instance must not be
null.").isNotNull();
+
+ Class<T> type = getTypeClass();
+ assertThat(type).as("The test is corrupt: type class is
null.").isNotNull();
+
+ if (!type.isAssignableFrom(instance.getClass())) {
Review Comment:
How about instanceOf
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]