Tibor17 commented on a change in pull request #445:
URL: https://github.com/apache/maven-surefire/pull/445#discussion_r794479343



##########
File path: 
maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoProvidersInfoTest.java
##########
@@ -0,0 +1,172 @@
+package org.apache.maven.plugin.surefire;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.surefire.providerapi.ProviderInfo;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+
+/**
+ * Testing providerInfo applicable behavior.
+ */
+@RunWith( MockitoJUnitRunner.class )
+public class AbstractSurefireMojoProvidersInfoTest
+{
+
+    @Spy
+    private AbstractSurefireMojo mojo;
+
+    @Test
+    public void defaultProviderAreAlwaysAvailable()
+    {
+        ProviderInfo providerInfo = mojo.new JUnit3ProviderInfo();
+        assertThat( providerInfo.isApplicable() ).isTrue();
+    }
+
+    @Test
+    public void dynamicProviderAreAlwaysApplicable()
+    {
+        ProviderInfo providerInfo = mojo.new DynamicProviderInfo( "test" );
+        assertThat( providerInfo.isApplicable() ).isTrue();
+    }
+
+    @Test
+    public void testNgProviderApplicable()
+    {
+        Artifact testNg = mock( Artifact.class );
+        ProviderInfo providerInfo = mojo.new TestNgProviderInfo( testNg );
+
+        assertThat( providerInfo.isApplicable() ).isTrue();
+
+        // no interaction with artifact only reference are checked
+        verifyNoMoreInteractions( testNg );
+    }
+
+    @Test
+    public void testNgProviderNotApplicable()
+    {
+        ProviderInfo providerInfo = mojo.new TestNgProviderInfo( null );
+        assertThat( providerInfo.isApplicable() ).isFalse();
+    }
+
+    //surefire-junit-platform
+
+    @Test
+    public void jUnitPlatformProviderApplicable()
+    {
+        Artifact junitPlatform = mock( Artifact.class );
+        ProviderInfo providerInfo = mojo.new JUnitPlatformProviderInfo( 
junitPlatform, aTestClassPath() );
+
+        assertThat( providerInfo.isApplicable() ).isTrue();
+
+        // no interaction with artifact only reference are checked
+        verifyNoMoreInteractions( junitPlatform );
+    }
+
+    @Test
+    public void jUnitPlatformProviderNotApplicable()
+    {
+        ProviderInfo providerInfo = mojo.new JUnitPlatformProviderInfo( null, 
aTestClassPath() );
+        assertThat( providerInfo.isApplicable() ).isFalse();
+    }
+
+    // surefire-junit4
+
+    @Test
+    public void jUnit4ProviderNullArtifacts()
+    {
+        ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( null, null );
+        assertThat( providerInfo.isApplicable() ).isFalse();
+    }
+
+    @Test
+    public void jUnit4ProviderOnlyJunitDepArtifact()
+    {
+        Artifact junitDep = mock( Artifact.class );
+        ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( null, 
junitDep );
+
+        assertThat( providerInfo.isApplicable() ).isTrue();
+
+        // no interaction with artifact only reference are checked
+        verifyNoMoreInteractions( junitDep );
+    }
+
+
+    @Test
+    public void jUnit4ProviderJunit3WithJDepArtifact()
+    {
+        Artifact junit = aArtifact( "3.8.1" );
+        Artifact junitDep = mock( Artifact.class );
+
+        ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( junit, 
junitDep );
+
+        // ??? only existing for junitDep in any version is checked
+        assertThat( providerInfo.isApplicable() ).isTrue();
+
+        // no interaction with artifact only reference are checked
+        verifyNoMoreInteractions( junitDep );
+    }
+
+    @Test
+    public void jUnit4ProviderJunit3AsDependencyArtifact()
+    {
+        Artifact junit = aArtifact( "3.8.1" );
+        ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( junit, null );
+        assertThat( providerInfo.isApplicable() ).isFalse();
+    }
+
+    @Test
+    public void jUnit4ProviderJunit45AsDependencyArtifact()
+    {
+        Artifact junit = aArtifact( "4.5" );
+        ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( junit, null );
+        assertThat( providerInfo.isApplicable() ).isTrue();

Review comment:
       The purpose of writing the uni tests is hiding your eyes and you should 
write the tests without knowing the implementation, even before the impl 
exists. Here the impl exists, therefore we should hide our eyes. Then new 
issues would rise up.




-- 
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-unsubscr...@maven.apache.org

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


Reply via email to