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 2019/07/21 09:56:12 UTC
[maven-surefire] 01/02: fixed collisions between test methods in
ForkConfigurationTest
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch SUREFIRE-1675
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 8efc9038ad298b5271b5b681fb8e80bd0a6a8caf
Author: tibordigana <ti...@apache.org>
AuthorDate: Sun Jul 21 01:30:22 2019 +0200
fixed collisions between test methods in ForkConfigurationTest
---
...ooterDeserializerProviderConfigurationTest.java | 26 +++++-
...BooterDeserializerStartupConfigurationTest.java | 29 ++++++-
.../booterclient/ForkConfigurationTest.java | 93 ++++++++++++----------
3 files changed, 100 insertions(+), 48 deletions(-)
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
index 7750c93..3869911 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
@@ -21,11 +21,14 @@ package org.apache.maven.plugin.surefire.booterclient;
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
import org.apache.maven.surefire.booter.*;
import org.apache.maven.surefire.cli.CommandLineOption;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.testset.*;
import org.apache.maven.surefire.util.RunOrder;
+import org.junit.After;
+import org.junit.Before;
import java.io.File;
import java.io.FileInputStream;
@@ -45,7 +48,7 @@ public class BooterDeserializerProviderConfigurationTest
extends TestCase
{
- public static final TypeEncodedValue aTestTyped = new TypeEncodedValue( String.class.getName(), "aTest" );
+ static final TypeEncodedValue aTestTyped = new TypeEncodedValue( String.class.getName(), "aTest" );
private static final String aUserRequestedTest = "aUserRequestedTest";
@@ -53,9 +56,28 @@ public class BooterDeserializerProviderConfigurationTest
private static final int rerunFailingTestsCount = 3;
+ private static int idx = 0;
+
+ private File basedir;
+
private final List<CommandLineOption> cli =
Arrays.asList( LOGGING_LEVEL_DEBUG, SHOW_ERRORS, REACTOR_FAIL_FAST );
+ @Before
+ public void setupDirectories() throws IOException
+ {
+ File target = new File( System.getProperty( "user.dir" ), "target" );
+ basedir = new File( target, "BooterDeserializerProviderConfigurationTest-" + ++idx );
+ FileUtils.deleteDirectory( basedir );
+ assertTrue( basedir.mkdirs() );
+ }
+
+ @After
+ public void deleteDirectories() throws IOException
+ {
+ FileUtils.deleteDirectory( basedir );
+ }
+
private static ClassLoaderConfiguration getForkConfiguration()
{
return new ClassLoaderConfiguration( true, false );
@@ -207,7 +229,7 @@ public class BooterDeserializerProviderConfigurationTest
boolean readTestsFromInStream )
throws IOException
{
- final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( (String) null );
+ final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( basedir, null );
PropertiesWrapper props = new PropertiesWrapper( new HashMap<String, String>() );
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
Object test;
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
index 7a1a7e2..e170a45 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
@@ -20,11 +20,14 @@ package org.apache.maven.plugin.surefire.booterclient;
*/
import junit.framework.TestCase;
+import org.apache.commons.io.FileUtils;
import org.apache.maven.surefire.booter.*;
import org.apache.maven.surefire.cli.CommandLineOption;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.testset.*;
import org.apache.maven.surefire.util.RunOrder;
+import org.junit.After;
+import org.junit.Before;
import java.io.File;
import java.io.FileInputStream;
@@ -46,11 +49,31 @@ import static org.apache.maven.surefire.cli.CommandLineOption.SHOW_ERRORS;
public class BooterDeserializerStartupConfigurationTest
extends TestCase
{
+
+ private static int idx = 0;
+
+ private File basedir;
+
private final ClasspathConfiguration classpathConfiguration = createClasspathConfiguration();
private final List<CommandLineOption> cli =
Arrays.asList( LOGGING_LEVEL_DEBUG, SHOW_ERRORS, REACTOR_FAIL_FAST );
+ @Before
+ public void setupDirectories() throws IOException
+ {
+ File target = new File( System.getProperty( "user.dir" ), "target" );
+ basedir = new File( target, "BooterDeserializerProviderConfigurationTest-" + ++idx );
+ FileUtils.deleteDirectory( basedir );
+ assertTrue( basedir.mkdirs() );
+ }
+
+ @After
+ public void deleteDirectories() throws IOException
+ {
+ FileUtils.deleteDirectory( basedir );
+ }
+
public void testProvider()
throws IOException
{
@@ -100,12 +123,12 @@ public class BooterDeserializerStartupConfigurationTest
return new ClasspathConfiguration( testClassPath, providerClasspath, Classpath.emptyClasspath(), true, true );
}
- public static ClassLoaderConfiguration getSystemClassLoaderConfiguration()
+ private static ClassLoaderConfiguration getSystemClassLoaderConfiguration()
{
return new ClassLoaderConfiguration( true, false );
}
- public static ClassLoaderConfiguration getManifestOnlyJarForkConfiguration()
+ private static ClassLoaderConfiguration getManifestOnlyJarForkConfiguration()
{
return new ClassLoaderConfiguration( true, true );
}
@@ -121,7 +144,7 @@ public class BooterDeserializerStartupConfigurationTest
private StartupConfiguration saveAndReload( StartupConfiguration startupConfiguration )
throws IOException
{
- final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( (String) null );
+ final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( basedir, null );
PropertiesWrapper props = new PropertiesWrapper( new HashMap<String, String>() );
BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
String aTest = "aTest";
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 575c0fd..3fe0ecd 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
@@ -20,7 +20,6 @@ package org.apache.maven.plugin.surefire.booterclient;
*/
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.plugin.surefire.JdkAttributes;
import org.apache.maven.plugin.surefire.log.api.NullConsoleLogger;
@@ -31,6 +30,8 @@ import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.StartupConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import java.io.File;
@@ -39,7 +40,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Properties;
-import static java.io.File.createTempFile;
import static java.util.Collections.singletonList;
import static org.apache.maven.surefire.booter.Classpath.emptyClasspath;
import static org.fest.util.Files.temporaryFolder;
@@ -55,11 +55,30 @@ public class ForkConfigurationTest
false,
false );
+ private static int idx = 0;
+
+ private File basedir;
+
+ @Before
+ public void setupDirectories() throws IOException
+ {
+ File target = new File( System.getProperty( "user.dir" ), "target" );
+ basedir = new File( target, "SUREFIRE-1136-" + ++idx );
+ FileUtils.deleteDirectory( basedir );
+ assertTrue( basedir.mkdirs() );
+ }
+
+ @After
+ public void deleteDirectories() throws IOException
+ {
+ FileUtils.deleteDirectory( basedir );
+ }
+
@Test
public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
throws IOException, SurefireBooterForkException
{
- ForkConfiguration config = getForkConfiguration( (String) null );
+ ForkConfiguration config = getForkConfiguration( basedir, null );
File cpElement = getTempClasspathFile();
List<String> cp = singletonList( cpElement.getAbsolutePath() );
@@ -79,7 +98,7 @@ public class ForkConfigurationTest
throws IOException, SurefireBooterForkException
{
// SUREFIRE-657
- ForkConfiguration config = getForkConfiguration( "abc\ndef" );
+ ForkConfiguration config = getForkConfiguration( basedir, "abc\ndef" );
File cpElement = getTempClasspathFile();
List<String> cp = singletonList( cpElement.getAbsolutePath() );
@@ -96,13 +115,7 @@ public class ForkConfigurationTest
public void testCurrentWorkingDirectoryPropagationIncludingForkNumberExpansion()
throws IOException, SurefireBooterForkException
{
- // SUREFIRE-1136
- File baseDir =
- new File( FileUtils.getTempDirectory(), "SUREFIRE-1136-" + RandomStringUtils.randomAlphabetic( 3 ) );
- assertTrue( baseDir.mkdirs() );
- baseDir.deleteOnExit();
-
- File cwd = new File( baseDir, "fork_${surefire.forkNumber}" );
+ File cwd = new File( basedir, "fork_${surefire.forkNumber}" );
ClasspathConfiguration cpConfig = new ClasspathConfiguration( emptyClasspath(), emptyClasspath(),
emptyClasspath(), true, true );
@@ -111,8 +124,7 @@ public class ForkConfigurationTest
ForkConfiguration config = getForkConfiguration( cwd.getCanonicalFile() );
Commandline commandLine = config.createCommandLine( startup, 1, temporaryFolder() );
- File forkDirectory = new File( baseDir, "fork_1" );
- forkDirectory.deleteOnExit();
+ File forkDirectory = new File( basedir, "fork_1" );
String shellWorkDir = commandLine.getShell().getWorkingDirectory().getCanonicalPath();
assertEquals( shellWorkDir, forkDirectory.getCanonicalPath() );
@@ -122,29 +134,25 @@ public class ForkConfigurationTest
public void testExceptionWhenCurrentDirectoryIsNotRealDirectory()
throws IOException
{
- // SUREFIRE-1136
- File baseDir =
- new File( FileUtils.getTempDirectory(), "SUREFIRE-1136-" + RandomStringUtils.randomAlphabetic( 3 ) );
- assertTrue( baseDir.mkdirs() );
- baseDir.deleteOnExit();
-
- File cwd = new File( baseDir, "cwd.txt" );
+ File cwd = new File( basedir, "cwd.txt" );
FileUtils.touch( cwd );
- cwd.deleteOnExit();
-
- ForkConfiguration config = getForkConfiguration( cwd.getCanonicalFile() );
try
{
+ ForkConfiguration config = getForkConfiguration( cwd.getCanonicalFile() );
config.createCommandLine( STARTUP_CONFIG, 1, temporaryFolder() );
}
- catch ( SurefireBooterForkException sbfe )
+ catch ( SurefireBooterForkException e )
{
// To handle issue with ~ expansion on Windows
String absolutePath = cwd.getCanonicalPath();
- assertEquals( "WorkingDirectory " + absolutePath + " exists and is not a directory", sbfe.getMessage() );
+ assertEquals( "WorkingDirectory " + absolutePath + " exists and is not a directory", e.getMessage() );
return;
}
+ finally
+ {
+ assertTrue( cwd.delete() );
+ }
fail();
}
@@ -153,19 +161,14 @@ public class ForkConfigurationTest
public void testExceptionWhenCurrentDirectoryCannotBeCreated()
throws IOException
{
- // SUREFIRE-1136
- File baseDir =
- new File( FileUtils.getTempDirectory(), "SUREFIRE-1136-" + RandomStringUtils.randomAlphabetic( 3 ) );
- assertTrue( baseDir.mkdirs() );
- baseDir.deleteOnExit();
-
- // NULL is invalid for JDK starting from 1.7.60 - https://github.com/openjdk-mirror/jdk/commit/e5389115f3634d25d101e2dcc71f120d4fd9f72f
+ // 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( cwd.getAbsoluteFile() );
+ File cwd = new File( basedir, "?\u0000InvalidDirectoryName" );
try
{
+ ForkConfiguration config = getForkConfiguration( cwd.getAbsoluteFile() );
config.createCommandLine( STARTUP_CONFIG, 1, temporaryFolder() );
}
catch ( SurefireBooterForkException sbfe )
@@ -173,6 +176,10 @@ public class ForkConfigurationTest
assertEquals( "Cannot create workingDirectory " + cwd.getAbsolutePath(), sbfe.getMessage() );
return;
}
+ finally
+ {
+ FileUtils.deleteDirectory( cwd );
+ }
if ( SystemUtils.IS_OS_WINDOWS || isJavaVersionAtLeast7u60() )
{
@@ -183,31 +190,31 @@ public class ForkConfigurationTest
private File getTempClasspathFile()
throws IOException
{
- File cpElement = createTempFile( "ForkConfigurationTest.", ".file" );
- cpElement.deleteOnExit();
+ File cpElement = new File( basedir, "ForkConfigurationTest." + idx + ".file" );
+ FileUtils.deleteDirectory( cpElement );
return cpElement;
}
- static ForkConfiguration getForkConfiguration( String argLine )
+ static ForkConfiguration getForkConfiguration( File basedir, String argLine )
throws IOException
{
File jvm = new File( new File( System.getProperty( "java.home" ), "bin" ), "java" );
- return getForkConfiguration( argLine, jvm.getAbsolutePath(), new File( "." ).getCanonicalFile() );
+ return getForkConfiguration( basedir, argLine, jvm.getAbsolutePath(), new File( "." ).getCanonicalFile() );
}
- private static ForkConfiguration getForkConfiguration( File cwd )
+ private ForkConfiguration getForkConfiguration( File cwd )
throws IOException
{
File jvm = new File( new File( System.getProperty( "java.home" ), "bin" ), "java" );
- return getForkConfiguration( null, jvm.getAbsolutePath(), cwd );
+ return getForkConfiguration( basedir, null, jvm.getAbsolutePath(), cwd );
}
- private static ForkConfiguration getForkConfiguration( String argLine, String jvm, File cwd )
+ private static ForkConfiguration getForkConfiguration( File basedir, String argLine, String jvm, File cwd )
throws IOException
{
Platform platform = new Platform().withJdkExecAttributesForTests( new JdkAttributes( jvm, false ) );
- File tmpDir = createTempFile( "target", "surefire" );
- assertTrue( tmpDir.delete() );
+ File tmpDir = new File( new File( basedir, "target" ), "surefire" );
+ FileUtils.deleteDirectory( tmpDir );
assertTrue( tmpDir.mkdirs() );
return new JarManifestForkConfiguration( emptyClasspath(), tmpDir, null,
cwd, new Properties(), argLine, Collections.<String, String>emptyMap(), false, 1, false,