harker2015 commented on code in PR #20835:
URL: https://github.com/apache/flink/pull/20835#discussion_r971531077


##########
flink-test-utils-parent/flink-test-utils/src/test/java/org/apache/flink/packaging/PackagingTestUtilsTest.java:
##########
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.packaging;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+class PackagingTestUtilsTest {
+
+    @Test
+    void testAssertJarContainsOnlyFilesMatching(@TempDir Path tmp) throws 
Exception {
+        Path jar = createJar(tmp, Entry.fileEntry("", 
Arrays.asList("META-INF", "NOTICES")));
+
+        PackagingTestUtils.assertJarContainsOnlyFilesMatching(
+                jar, Collections.singleton("META-INF/"));
+        PackagingTestUtils.assertJarContainsOnlyFilesMatching(
+                jar, Collections.singleton("META-INF/NOTICES"));
+
+        assertThatThrownBy(
+                        () ->
+                                
PackagingTestUtils.assertJarContainsOnlyFilesMatching(
+                                        jar, 
Collections.singleton("META-INF")))
+                .isInstanceOf(AssertionError.class);
+        assertThatThrownBy(
+                        () ->
+                                
PackagingTestUtils.assertJarContainsOnlyFilesMatching(
+                                        jar, 
Collections.singleton("META-INF/NOTICE")))
+                .isInstanceOf(AssertionError.class);
+        assertThatThrownBy(
+                        () ->
+                                
PackagingTestUtils.assertJarContainsOnlyFilesMatching(
+                                        jar, 
Collections.singleton("META-INF/NOTICES/")))
+                .isInstanceOf(AssertionError.class);
+    }
+
+    @Test
+    void testAssertJarContainsServiceEntry(@TempDir Path tmp) throws Exception 
{
+        final String service = PackagingTestUtilsTest.class.getName();
+        Path jar =
+                createJar(tmp, Entry.fileEntry("", Arrays.asList("META-INF", 
"services", service)));
+
+        PackagingTestUtils.assertJarContainsServiceEntry(jar, 
PackagingTestUtilsTest.class);
+
+        assertThatThrownBy(
+                        () ->
+                                
PackagingTestUtils.assertJarContainsServiceEntry(
+                                        jar, PackagingTestUtils.class))
+                .isInstanceOf(AssertionError.class);
+    }
+
+    private static class Entry {
+        final String contents;
+        final List<String> path;
+        final boolean isDirectory;
+
+        public static Entry directoryEntry(List<String> path) {
+            return new Entry("", path, true);
+        }
+
+        public static Entry fileEntry(String contents, List<String> path) {
+            return new Entry(contents, path, false);
+        }
+
+        private Entry(String contents, List<String> path, boolean isDirectory) 
{
+            this.contents = contents;
+            this.path = path;
+            this.isDirectory = isDirectory;
+        }
+    }
+
+    private static Path createJar(Path tempDir, Entry... entries) throws 
Exception {
+        final Path path = tempDir.resolve(UUID.randomUUID().toString() + 
".jar");
+
+        final URI uri = path.toUri();
+
+        final URI jarUuri = new URI("jar:file", uri.getHost(), uri.getPath(), 
uri.getFragment());

Review Comment:
   would variable name "jarUri" be better here?



-- 
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]

Reply via email to