This is an automated email from the ASF dual-hosted git repository.

chesnay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new cc6d1a27baf [FLINK-27321][ci] Migrate java-ci-tools to JUnit 5
cc6d1a27baf is described below

commit cc6d1a27bafe38e76d6f9f0d480fdcb7e017be3a
Author: Chesnay Schepler <[email protected]>
AuthorDate: Thu Apr 21 15:58:25 2022 +0200

    [FLINK-27321][ci] Migrate java-ci-tools to JUnit 5
---
 .../tools/ci/licensecheck/JarFileCheckerTest.java  | 275 +++++++++++----------
 .../org.junit.jupiter.api.extension.Extension      |  16 ++
 2 files changed, 163 insertions(+), 128 deletions(-)

diff --git 
a/tools/ci/java-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/JarFileCheckerTest.java
 
b/tools/ci/java-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/JarFileCheckerTest.java
index 63c59a0f2eb..b844f755c93 100644
--- 
a/tools/ci/java-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/JarFileCheckerTest.java
+++ 
b/tools/ci/java-ci-tools/src/test/java/org/apache/flink/tools/ci/licensecheck/JarFileCheckerTest.java
@@ -17,12 +17,9 @@
 
 package org.apache.flink.tools.ci.licensecheck;
 
-import org.apache.flink.util.TestLogger;
-
-import org.junit.ClassRule;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
 
 import java.net.URI;
 import java.nio.file.FileSystem;
@@ -36,8 +33,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 
 /**
  * Tests for the {@link JarFileChecker}.
@@ -46,186 +42,209 @@ import static org.junit.Assert.assertThat;
  * 
-DaltDeploymentRepository=snapshot-repo::default::file:/tmp/flink-deployment 
-DskipTests
  * -Drat.skip and add a test checking that directory.
  */
-public class JarFileCheckerTest extends TestLogger {
-
-    @ClassRule public static final TemporaryFolder TMP = new TemporaryFolder();
+class JarFileCheckerTest {
 
     private static final List<String> VALID_NOTICE_PATH = 
Arrays.asList("META-INF", "NOTICE");
     private static final List<String> VALID_LICENSE_PATH = 
Arrays.asList("META-INF", "LICENSE");
 
     @Test
-    public void testValidJarAccepted() throws Exception {
+    void testValidJarAccepted(@TempDir Path tempDir) throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))),
-                is(0));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))))
+                .isEqualTo(0);
     }
 
     @Test
-    public void testRejectedOnMissingNoticeFile() throws Exception {
+    void testRejectedOnMissingNoticeFile(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnInvalidNoticeFile() throws Exception {
+    void testRejectedOnInvalidNoticeFile(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(INVALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        
Entry.fileEntry(INVALID_NOTICE_CONTENTS, VALID_NOTICE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnNoticeFileInRoot() throws Exception {
+    void testRejectedOnNoticeFileInRoot(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        VALID_NOTICE_CONTENTS,
-                                        Arrays.asList("some_custom_notice")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_NOTICE_CONTENTS,
+                                                
Arrays.asList("some_custom_notice")))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnMissingLicenseFile() throws Exception {
+    void testRejectedOnMissingLicenseFile(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnInvalidLicenseFile() throws Exception {
+    void testRejectedOnInvalidLicenseFile(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(INVALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        Entry.fileEntry(
+                                                INVALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnLicenseFileInRoot() throws Exception {
+    void testRejectedOnLicenseFileInRoot(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        VALID_LICENSE_CONTENTS,
-                                        
Arrays.asList("some_custom_license")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS,
+                                                
Arrays.asList("some_custom_license")))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testRejectedOnLicenseFileInSomeDirectory() throws Exception {
+    void testRejectedOnLicenseFileInSomeDirectory(@TempDir Path tempDir) 
throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        VALID_LICENSE_CONTENTS,
-                                        Arrays.asList(
-                                                "some", "directory", 
"some_custom_license")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS,
+                                                Arrays.asList(
+                                                        "some",
+                                                        "directory",
+                                                        
"some_custom_license")))))
+                .isEqualTo(1);
     }
 
-    @Ignore(
+    @Disabled(
             "Currently not checked, but we may want to enforce this in the 
future to reduce ambiguity.")
-    public void testRejectedOnAdditionalLicenseFileInMetaInf() throws 
Exception {
+    void testRejectedOnAdditionalLicenseFileInMetaInf(@TempDir Path tempDir) 
throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        VALID_LICENSE_CONTENTS,
-                                        Arrays.asList("META-INF", 
"LICENSE.txt")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                VALID_LICENSE_CONTENTS,
+                                                Arrays.asList("META-INF", 
"LICENSE.txt")))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void testIgnoreLicenseDirectories() throws Exception {
+    void testIgnoreLicenseDirectories(@TempDir Path tempDir) throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.directoryEntry(
-                                        Arrays.asList("some", "license", 
"directory")))),
-                is(0));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.directoryEntry(
+                                                Arrays.asList("some", 
"license", "directory")))))
+                .isEqualTo(0);
     }
 
     @Test
-    public void testIgnoreClassFiles() throws Exception {
+    void testIgnoreClassFiles(@TempDir Path tempDir) throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        "content", 
Arrays.asList("SomeLicenseClass.class")))),
-                is(0));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                "content",
+                                                
Arrays.asList("SomeLicenseClass.class")))))
+                .isEqualTo(0);
     }
 
     @Test
-    public void testIgnoreFtlFiles() throws Exception {
+    void testIgnoreFtlFiles(@TempDir Path tempDir) throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry("content", 
Arrays.asList("SomeLicenseFile.ftl")))),
-                is(0));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                "content", 
Arrays.asList("SomeLicenseFile.ftl")))))
+                .isEqualTo(0);
     }
 
     @Test
-    public void testIgnoreWebThirdPartyLicenses() throws Exception {
+    void testIgnoreWebThirdPartyLicenses(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        "class contents",
-                                        Arrays.asList("web", 
"3rdpartylicenses.txt")))),
-                is(0));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                "class contents",
+                                                Arrays.asList("web", 
"3rdpartylicenses.txt")))))
+                .isEqualTo(0);
     }
 
     @Test
-    public void testForbiddenLGPLongTextDetected() throws Exception {
+    void testForbiddenLGPLongTextDetected(@TempDir Path tempDir) throws 
Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        "some GNU Lesser General public 
License text",
-                                        
Collections.singletonList("some_file.txt")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                "some GNU Lesser General 
public License text",
+                                                
Collections.singletonList("some_file.txt")))))
+                .isEqualTo(1);
     }
 
     @Test
-    public void 
testForbiddenLGPMultiLineLongTextWithCommentAndLeadingWhitespaceDetected()
-            throws Exception {
+    void 
testForbiddenLGPMultiLineLongTextWithCommentAndLeadingWhitespaceDetected(
+            @TempDir Path tempDir) throws Exception {
         assertThat(
-                JarFileChecker.checkJar(
-                        createJar(
-                                Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
-                                Entry.fileEntry(VALID_LICENSE_CONTENTS, 
VALID_LICENSE_PATH),
-                                Entry.fileEntry(
-                                        "some GNU Lesser General public 
\n\t\t//#License text",
-                                        
Collections.singletonList("some_file.txt")))),
-                is(1));
+                        JarFileChecker.checkJar(
+                                createJar(
+                                        tempDir,
+                                        Entry.fileEntry(VALID_NOTICE_CONTENTS, 
VALID_NOTICE_PATH),
+                                        
Entry.fileEntry(VALID_LICENSE_CONTENTS, VALID_LICENSE_PATH),
+                                        Entry.fileEntry(
+                                                "some GNU Lesser General 
public \n\t\t//#License text",
+                                                
Collections.singletonList("some_file.txt")))))
+                .isEqualTo(1);
     }
 
     private static class Entry {
@@ -248,8 +267,8 @@ public class JarFileCheckerTest extends TestLogger {
         }
     }
 
-    private static Path createJar(Entry... entries) throws Exception {
-        final Path path = 
TMP.getRoot().toPath().resolve(UUID.randomUUID().toString() + ".jar");
+    private static Path createJar(Path tempDir, Entry... entries) throws 
Exception {
+        final Path path = tempDir.resolve(UUID.randomUUID().toString() + 
".jar");
 
         final URI uriWithoutScheme = path.toUri();
 
diff --git 
a/tools/ci/java-ci-tools/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
 
b/tools/ci/java-ci-tools/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
new file mode 100644
index 00000000000..28999133c2b
--- /dev/null
+++ 
b/tools/ci/java-ci-tools/src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+org.apache.flink.util.TestLoggerExtension
\ No newline at end of file

Reply via email to