You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2017/12/02 15:22:15 UTC
[2/2] maven-surefire git commit: NULL not allowed in unit tests due
to jsr305 @Nonnull for SUREFIRE-1262
NULL not allowed in unit tests due to jsr305 @Nonnull for SUREFIRE-1262
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/81b9bbbe
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/81b9bbbe
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/81b9bbbe
Branch: refs/heads/master
Commit: 81b9bbbeea702b1186142559e59bdd5267cc056b
Parents: 302094e
Author: Tibor17 <ti...@apache.org>
Authored: Sat Dec 2 16:21:49 2017 +0100
Committer: Tibor17 <ti...@apache.org>
Committed: Sat Dec 2 16:21:49 2017 +0100
----------------------------------------------------------------------
.../DefaultForkConfigurationTest.java | 10 +++-
.../booterclient/ForkConfigurationTest.java | 59 ++++++++++----------
.../ModularClasspathForkConfigurationTest.java | 5 +-
3 files changed, 41 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81b9bbbe/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfigurationTest.java
index 338a46c..5995750 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/DefaultForkConfigurationTest.java
@@ -22,7 +22,9 @@ package org.apache.maven.plugin.surefire.booterclient;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.util.Relocator;
+import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.ForkedBooter;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
@@ -291,8 +293,10 @@ public class DefaultForkConfigurationTest
@Test
public void shouldRelocateBooterClassWhenShadefire() throws Exception
{
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
+ ClasspathConfiguration cc = new ClasspathConfiguration( true, true );
StartupConfiguration conf =
- new StartupConfiguration( "org.apache.maven.surefire.shadefire.MyProvider", null, null, false, false );
+ new StartupConfiguration( "org.apache.maven.surefire.shadefire.MyProvider", cc, clc, false, false );
StartupConfiguration confMock = spy( conf );
mockStatic( Relocator.class );
when( Relocator.relocate( anyString() ) ).thenCallRealMethod();
@@ -310,8 +314,10 @@ public class DefaultForkConfigurationTest
@Test
public void shouldNotRelocateBooterClass() throws Exception
{
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
+ ClasspathConfiguration cc = new ClasspathConfiguration( true, true );
StartupConfiguration conf =
- new StartupConfiguration( "org.apache.maven.surefire.MyProvider", null, null, false, false );
+ new StartupConfiguration( "org.apache.maven.surefire.MyProvider", cc, clc, false, false );
StartupConfiguration confMock = spy( conf );
mockStatic( Relocator.class );
when( Relocator.relocate( anyString() ) ).thenCallRealMethod();
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81b9bbbe/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
index 2d7f335..0067a06 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
@@ -26,6 +26,7 @@ import org.apache.maven.plugin.surefire.JdkAttributes;
import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
import org.apache.maven.shared.utils.StringUtils;
import org.apache.maven.shared.utils.cli.Commandline;
+import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
@@ -46,7 +47,11 @@ import static org.junit.Assert.fail;
public class ForkConfigurationTest
{
- private static final StartupConfiguration STARTUP_CONFIG = new StartupConfiguration( "", null, null, false, false );
+ private static final StartupConfiguration STARTUP_CONFIG = new StartupConfiguration( "",
+ new ClasspathConfiguration( true, true ),
+ new ClassLoaderConfiguration( true, true ),
+ false,
+ false );
@Test
public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
@@ -56,8 +61,10 @@ public class ForkConfigurationTest
File cpElement = getTempClasspathFile();
List<String> cp = singletonList( cpElement.getAbsolutePath() );
- ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), null, null, true, true );
- StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), emptyClasspath(),
+ emptyClasspath(), true, true );
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, clc, false, false );
Commandline cli = config.createCommandLine( startup, 1 );
@@ -74,8 +81,10 @@ public class ForkConfigurationTest
File cpElement = getTempClasspathFile();
List<String> cp = singletonList( cpElement.getAbsolutePath() );
- ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), null, null, true, true );
- StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( new Classpath( cp ), emptyClasspath(),
+ emptyClasspath(), true, true );
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, clc, false, false );
Commandline commandLine = config.createCommandLine( startup, 1 );
assertTrue( commandLine.toString().contains( "abc def" ) );
@@ -93,9 +102,11 @@ public class ForkConfigurationTest
File cwd = new File( baseDir, "fork_${surefire.forkNumber}" );
- ClasspathConfiguration cpConfig = new ClasspathConfiguration( emptyClasspath(), null, null, true, true );
- StartupConfiguration startup = new StartupConfiguration( "", cpConfig, null, false, false );
- ForkConfiguration config = getForkConfiguration( null, cwd.getCanonicalFile() );
+ ClasspathConfiguration cpConfig = new ClasspathConfiguration( emptyClasspath(), emptyClasspath(),
+ emptyClasspath(), true, true );
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
+ StartupConfiguration startup = new StartupConfiguration( "", cpConfig, clc, false, false );
+ ForkConfiguration config = getForkConfiguration( cwd.getCanonicalFile() );
Commandline commandLine = config.createCommandLine( startup, 1 );
File forkDirectory = new File( baseDir, "fork_1" );
@@ -119,7 +130,7 @@ public class ForkConfigurationTest
FileUtils.touch( cwd );
cwd.deleteOnExit();
- ForkConfiguration config = getForkConfiguration( null, cwd.getCanonicalFile() );
+ ForkConfiguration config = getForkConfiguration( cwd.getCanonicalFile() );
try
{
@@ -149,7 +160,7 @@ public class ForkConfigurationTest
// NULL is invalid for JDK starting from 1.7.60 - https://github.com/openjdk-mirror/jdk/commit/e5389115f3634d25d101e2dcc71f120d4fd9f72f
// ? character is invalid on Windows, seems to be imposable to create invalid directory using Java on Linux
File cwd = new File( baseDir, "?\u0000InvalidDirectoryName" );
- ForkConfiguration config = getForkConfiguration( null, cwd.getAbsoluteFile() );
+ ForkConfiguration config = getForkConfiguration( cwd.getAbsoluteFile() );
try
{
@@ -161,7 +172,7 @@ public class ForkConfigurationTest
return;
}
- if ( SystemUtils.IS_OS_WINDOWS || isJavaVersionAtLeast( 7, 60 ) )
+ if ( SystemUtils.IS_OS_WINDOWS || isJavaVersionAtLeast7u60() )
{
fail();
}
@@ -175,24 +186,18 @@ public class ForkConfigurationTest
return cpElement;
}
- public static ForkConfiguration getForkConfiguration( File javaExec )
- throws IOException
- {
- return getForkConfiguration( null, javaExec.getAbsolutePath(), new File( "." ).getCanonicalFile() );
- }
-
- public static ForkConfiguration getForkConfiguration( String argLine )
+ static ForkConfiguration getForkConfiguration( String argLine )
throws IOException
{
File jvm = new File( new File( System.getProperty( "java.home" ), "bin" ), "java" );
return getForkConfiguration( argLine, jvm.getAbsolutePath(), new File( "." ).getCanonicalFile() );
}
- public static ForkConfiguration getForkConfiguration( String argLine, File cwd )
+ private static ForkConfiguration getForkConfiguration( File cwd )
throws IOException
{
File jvm = new File( new File( System.getProperty( "java.home" ), "bin" ), "java" );
- return getForkConfiguration( argLine, jvm.getAbsolutePath(), cwd );
+ return getForkConfiguration( null, jvm.getAbsolutePath(), cwd );
}
private static ForkConfiguration getForkConfiguration( String argLine, String jvm, File cwd )
@@ -200,23 +205,17 @@ public class ForkConfigurationTest
{
Platform platform = new Platform().withJdkExecAttributesForTests( new JdkAttributes( jvm, false ) );
File tmpDir = File.createTempFile( "target", "surefire" );
- tmpDir.delete();
- tmpDir.mkdirs();
+ assertTrue( tmpDir.delete() );
+ assertTrue( tmpDir.mkdirs() );
return new JarManifestForkConfiguration( emptyClasspath(), tmpDir, null,
cwd, new Properties(), argLine, Collections.<String, String>emptyMap(), false, 1, false,
platform, new NullConsoleLogger() );
-
- /*
- return new ClasspathForkConfiguration( emptyClasspath(), null, null,
- cwd, new Properties(), argLine, null, false, 1, false, platform, new NullConsoleLogger() );
- */
}
// based on http://stackoverflow.com/questions/2591083/getting-version-of-java-in-runtime
- private boolean isJavaVersionAtLeast( int major, int update )
+ private static boolean isJavaVersionAtLeast7u60()
{
String[] javaVersionElements = System.getProperty( "java.runtime.version" ).split( "\\.|_|-b" );
- return Integer.valueOf( javaVersionElements[1] ) >= major
- && Integer.valueOf( javaVersionElements[3] ) >= update;
+ return Integer.valueOf( javaVersionElements[1] ) >= 7 && Integer.valueOf( javaVersionElements[3] ) >= 60;
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/81b9bbbe/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java
index cb999d3..ce384fe 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ModularClasspathForkConfigurationTest.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugin.surefire.booterclient;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.OutputStreamFlushableCommandline;
import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
+import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ForkedBooter;
import org.apache.maven.surefire.booter.ModularClasspath;
@@ -50,6 +51,7 @@ import static org.fest.assertions.Assertions.assertThat;
public class ModularClasspathForkConfigurationTest
{
@Test
+ @SuppressWarnings( "ResultOfMethodCallIgnored" )
public void shouldCreateModularArgsFile() throws Exception
{
Classpath booter = new Classpath( asList( "booter.jar", "non-modular.jar" ) );
@@ -105,8 +107,9 @@ public class ModularClasspathForkConfigurationTest
ModularClasspathConfiguration modularClasspathConfiguration =
new ModularClasspathConfiguration( modularClasspath, testClasspathUrls, surefireClasspathUrls,
true, true );
+ ClassLoaderConfiguration clc = new ClassLoaderConfiguration( true, true );
StartupConfiguration startupConfiguration =
- new StartupConfiguration( "JUnitCoreProvider", modularClasspathConfiguration, null, true, true );
+ new StartupConfiguration( "JUnitCoreProvider", modularClasspathConfiguration, clc, true, true );
OutputStreamFlushableCommandline cli = new OutputStreamFlushableCommandline();
config.resolveClasspath( cli, ForkedBooter.class.getName(), startupConfiguration );