zentol commented on a change in pull request #16286:
URL: https://github.com/apache/flink/pull/16286#discussion_r662100188



##########
File path: 
flink-clients/src/test/java/org/apache/flink/client/deployment/application/FromClasspathEntryClassInformationProviderTest.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.client.deployment.application;
+
+import org.apache.flink.client.testjar.ClasspathProvider;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+
+import org.apache.commons.io.FilenameUtils;
+import org.hamcrest.CoreMatchers;
+import org.hamcrest.collection.IsIterableContainingInAnyOrder;
+import org.hamcrest.core.IsCollectionContaining;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+/**
+ * {@code FromClasspathEntryClassInformationProviderTest} tests {@link
+ * FromClasspathEntryClassInformationProvider}.
+ */
+public class FromClasspathEntryClassInformationProviderTest extends TestLogger 
{
+
+    @Rule public final ClasspathProvider classpathProvider = new 
ClasspathProvider();
+
+    @Test
+    public void testJobClassOnUserClasspathWithExplicitJobClassName()
+            throws MalformedURLException, FlinkException {
+        FromClasspathEntryClassInformationProvider testInstance =
+                FromClasspathEntryClassInformationProvider.create(
+                        classpathProvider.getJobClassName(),
+                        classpathProvider.getURLUserClasspathWithEntryClass());
+
+        assertThat(testInstance.getJobClassName().isPresent(), is(true));
+        assertThat(testInstance.getJobClassName().get(), 
is(classpathProvider.getJobClassName()));
+        assertThat(testInstance.getJarFile().isPresent(), is(false));
+    }
+
+    @Test(expected = FlinkException.class)
+    public void testJobClassOnUserClasspathWithOnlyTestFileOnClasspath()
+            throws MalformedURLException, FlinkException {
+        // we want to check that the right exception is thrown if the user 
classpath is empty
+        FromClasspathEntryClassInformationProvider.create(
+                "SomeJobClassName", 
classpathProvider.getURLUserClasspathWithOnlyTextFile());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testJobClassOnUserClasspathWithMissingJobClassName()
+            throws MalformedURLException, FlinkException {
+        FromClasspathEntryClassInformationProvider.create(
+                null, classpathProvider.getURLUserClasspathWithEntryClass());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testJobClassOnUserClasspathWithMissingUserClasspath() throws 
FlinkException {
+        FromClasspathEntryClassInformationProvider.create("jobClassName", 
null);
+    }
+
+    @Test
+    public void testJobClassOnUserClasspathWithoutExplicitJobClassName() 
throws IOException {
+        FromClasspathEntryClassInformationProvider testInstance =
+                FromClasspathEntryClassInformationProvider.createFromClasspath(
+                        classpathProvider.getURLUserClasspathWithEntryClass());
+
+        assertThat(testInstance.getJobClassName().isPresent(), is(true));
+        assertThat(testInstance.getJobClassName().get(), 
is(classpathProvider.getJobClassName()));
+        assertThat(testInstance.getJarFile().isPresent(), is(false));
+    }
+
+    @Test(expected = NoSuchElementException.class)
+    public void 
testMissingJobClassOnUserClasspathWithoutExplicitJobClassName() throws 
IOException {
+        FromClasspathEntryClassInformationProvider.createFromClasspath(
+                classpathProvider.getURLUserClasspathWithoutEntryClass());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testTooManyMainMethodsOnUserClasspath() throws IOException {
+        FromClasspathEntryClassInformationProvider.createFromClasspath(
+                classpathProvider.getURLUserClasspathWithTwoEntryClasses());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void 
testJobClassOnUserClasspathWithoutExplicitJobClassNameAndMissingUserClasspath()
+            throws IOException {
+        FromClasspathEntryClassInformationProvider.createFromClasspath(null);
+    }
+
+    @Test
+    public void testJobClassNameFromSystemClasspath() throws IOException {
+        classpathProvider.setSystemClasspathWithEntryClass();
+        FromClasspathEntryClassInformationProvider testInstance =
+                
FromClasspathEntryClassInformationProvider.createFromSystemClasspath();
+        assertThat(testInstance.getJobClassName().isPresent(), is(true));
+        assertThat(testInstance.getJobClassName().get(), 
is(classpathProvider.getJobClassName()));
+        assertThat(testInstance.getJarFile().isPresent(), is(false));
+    }
+
+    @Test(expected = NoSuchElementException.class)
+    public void testMissingJobClassNameFromSystemClasspath() throws 
IOException {
+        classpathProvider.setSystemClasspathWithoutEntryClass();
+        FromClasspathEntryClassInformationProvider.createFromSystemClasspath();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testTooManyMainMethodsOnSystemClasspath() throws IOException {
+        classpathProvider.setSystemClasspathWithTwoEntryClasses();
+        FromClasspathEntryClassInformationProvider.createFromSystemClasspath();
+    }
+
+    @Test
+    public void testJarFromSystemClasspathSanityCheck() {

Review comment:
       We can keep it because it already exists, but what I objected to is 
searching for the junit jar on a conceptual level. It is not sound to couple 
the usage of some testing library to the correctness of production code.




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