-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SUREFIRE-1962] Unit test for ProviderInfo#isApplicable
- Loading branch information
1 parent
d3dafe4
commit 0097a41
Showing
3 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
...java/org/apache/maven/plugin/surefire/AbstractSurefireMojoJunitCoreProvidersInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
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 java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
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.junit.runners.Parameterized; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* Testing JUnitCoreProviderInfo applicable behavior. | ||
*/ | ||
@RunWith( Parameterized.class ) | ||
public class AbstractSurefireMojoJunitCoreProvidersInfoTest | ||
{ | ||
private final Artifact junitArtifact; | ||
private final Artifact junitDepArtifact; | ||
private final boolean isParallel; | ||
private final boolean hasGroups; | ||
|
||
private final boolean isApplicable; | ||
|
||
|
||
@Parameterized.Parameters( | ||
name = "{index}: junit={0}, junitDep={1}, parallel={2}, groups={3} then isApplicable={4}" ) | ||
public static Collection<Object[]> data() | ||
{ | ||
return Arrays.asList( new Object[][] { | ||
// junit and junitDep are null | ||
{null, null, false, false, false}, | ||
{null, null, true, false, false}, | ||
{null, null, false, true, false}, | ||
{null, null, true, true, false}, | ||
|
||
// only junit artifact | ||
// without parallel and groups | ||
{"4.5", null, false, false, false}, | ||
{"4.7", null, false, false, false}, | ||
|
||
// with parallel | ||
{"4.5", null, true, false, false}, | ||
{"4.7", null, true, false, true}, | ||
|
||
// with groups | ||
{"4.5", null, false, true, false}, | ||
{"4.7", null, false, true, true}, | ||
|
||
// only junitDep artifact | ||
// without parallel and groups | ||
{null, "4.5", false, false, false}, | ||
{null, "4.7", false, false, false}, | ||
|
||
// with parallel | ||
{null, "4.5", true, false, false}, | ||
{null, "4.7", true, false, true}, | ||
|
||
// with groups | ||
{null, "4.5", false, true, false}, | ||
{null, "4.7", false, true, true} | ||
} ); | ||
} | ||
|
||
public AbstractSurefireMojoJunitCoreProvidersInfoTest( String junitVersion, String junitDepVersion, | ||
boolean isParallel, boolean hasGroups, | ||
boolean isApplicable ) | ||
{ | ||
this.junitArtifact = junitVersion != null ? aArtifact( junitVersion ) : null; | ||
this.junitDepArtifact = junitDepVersion != null ? aArtifact( junitDepVersion ) : null; | ||
this.isParallel = isParallel; | ||
this.hasGroups = hasGroups; | ||
this.isApplicable = isApplicable; | ||
} | ||
|
||
private Artifact aArtifact( String version ) | ||
{ | ||
return new DefaultArtifact( "test", "test", version, "test", "jar", "", null ); | ||
} | ||
|
||
@Test | ||
public void test() | ||
{ | ||
AbstractSurefireMojo mojo = spy( AbstractSurefireMojo.class ); | ||
|
||
when( mojo.isAnyConcurrencySelected() ).thenReturn( isParallel ); | ||
when( mojo.isAnyGroupsSelected() ).thenReturn( hasGroups ); | ||
|
||
ProviderInfo providerInfo = mojo.new JUnitCoreProviderInfo( junitArtifact, junitDepArtifact ); | ||
|
||
assertThat( providerInfo.isApplicable() ).isEqualTo( isApplicable ); | ||
} | ||
} |
185 changes: 185 additions & 0 deletions
185
...src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoProvidersInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
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.assertj.core.api.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( null, 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, null, aTestClassPath() ); | ||
assertThat( providerInfo.isApplicable() ).isFalse(); | ||
} | ||
|
||
@Test | ||
public void jUnitPlatformProviderNotApplicableForPlatformRunner() | ||
{ | ||
// not applicable if junit-platform-runner is on classpath | ||
Artifact junitPlatformRunnerArtifact = mock( Artifact.class ); | ||
ProviderInfo providerInfo = mojo.new JUnitPlatformProviderInfo( | ||
junitPlatformRunnerArtifact, null, aTestClassPath() ); | ||
assertThat( providerInfo.isApplicable() ).isFalse(); | ||
|
||
// no interaction with artifact only reference are checked | ||
verifyNoMoreInteractions( junitPlatformRunnerArtifact ); | ||
} | ||
|
||
// 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(); | ||
} | ||
|
||
@Test | ||
public void jUnit4ProviderJunit47AsDependencyArtifact() | ||
{ | ||
Artifact junit = aArtifact( "4.7" ); | ||
ProviderInfo providerInfo = mojo.new JUnit4ProviderInfo( junit, null ); | ||
// ??? it is ok for 4.7 ??? | ||
assertThat( providerInfo.isApplicable() ).isTrue(); | ||
} | ||
|
||
|
||
private TestClassPath aTestClassPath() | ||
{ | ||
return new TestClassPath( null, null, null, null ); | ||
} | ||
|
||
private Artifact aArtifact( String version ) | ||
{ | ||
return new DefaultArtifact( "test", "test", version, "test", "jar", "", null ); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters