[1/2] maven-surefire git commit: [SUREFIRE-1445] Explicitly define SurefireProperties#putAll

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] maven-surefire git commit: [SUREFIRE-1445] Explicitly define SurefireProperties#putAll

Tibor Digana
Repository: maven-surefire
Updated Branches:
  refs/heads/master e27b51e90 -> 81b9bbbee


[SUREFIRE-1445] Explicitly define SurefireProperties#putAll

This ensures the overriden put method is called and the items
property is updated.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/302094ef
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/302094ef
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/302094ef

Branch: refs/heads/master
Commit: 302094ef2a7103d1a72b798443995a7d2b3b6702
Parents: e27b51e
Author: Arnaud Cogolu?¨gnes <[hidden email]>
Authored: Mon Nov 27 14:54:30 2017 +0100
Committer: Tibor17 <[hidden email]>
Committed: Sat Dec 2 16:20:50 2017 +0100

----------------------------------------------------------------------
 .../plugin/surefire/SurefireProperties.java     | 11 +++-
 .../plugin/surefire/SurefirePropertiesTest.java | 59 +++++++++++++++++++-
 2 files changed, 67 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/302094ef/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
index 8d080b7..cf19eb0 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireProperties.java
@@ -59,7 +59,7 @@ public class SurefireProperties
     {
         if ( source != null )
         {
-            this.putAll( source );
+            putAll( source );
         }
     }
 
@@ -72,6 +72,15 @@ public class SurefireProperties
     }
 
     @Override
+    public synchronized void putAll( Map<?, ?> t )
+    {
+        for ( Map.Entry<?, ?> entry : t.entrySet() )
+        {
+            put( entry.getKey(), entry.getValue() );
+        }
+    }
+
+    @Override
     public synchronized Object put( Object key, Object value )
     {
         items.add( key );

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/302094ef/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
index af9ee75..480656f 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefirePropertiesTest.java
@@ -19,11 +19,16 @@ package org.apache.maven.plugin.surefire;
  */
 
 import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.Properties;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 import junit.framework.TestCase;
 import org.apache.maven.surefire.booter.KeyValueSource;
 
+import static java.util.Collections.list;
+
 /**
  * Tests the insertion-order preserving properties collection
  */
@@ -43,13 +48,12 @@ public class SurefirePropertiesTest
         assertEquals( "abc", keys.nextElement() );
         assertEquals( "xyz", keys.nextElement() );
         assertEquals( "efg", keys.nextElement() );
-
     }
 
     public void testKeysReinsert()
         throws Exception
     {
-        SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource)null );
+        SurefireProperties orderedProperties = new SurefireProperties( (KeyValueSource) null );
         orderedProperties.setProperty( "abc", "1" );
         orderedProperties.setProperty( "xyz", "1" );
         orderedProperties.setProperty( "efg", "1" );
@@ -70,9 +74,60 @@ public class SurefirePropertiesTest
         src.setProperty( "b", "2" );
         SurefireProperties orderedProperties = new SurefireProperties( src );
         // Cannot make assumptions about insertion order
+        // keys() uses the items property, more reliable to test than size(),
+        // which is based on the Properties class
+        // see https://issues.apache.org/jira/browse/SUREFIRE-1445
+        assertEquals( src.size(), list( orderedProperties.keys() ).size() );
+        assertEquals( src.size(), size( orderedProperties.getStringKeySet().iterator() ) );
+        assertEquals( 2, orderedProperties.size() );
+
+        assertTrue( list( orderedProperties.keys() ).contains( "a" ) );
+        assertTrue( list( orderedProperties.keys() ).contains( "b" ) );
+
+        Iterator it = orderedProperties.getStringKeySet().iterator();
+        SortedSet<Object> keys = new TreeSet<Object>();
+        keys.add( it.next() );
+        keys.add( it.next() );
+        it = keys.iterator();
+        assertEquals( "a", it.next() );
+        assertEquals( "b", it.next() );
+    }
+
+    public void testPutAll()
+    {
+        Properties src = new Properties();
+        src.setProperty( "a", "1" );
+        src.setProperty( "b", "2" );
+        SurefireProperties orderedProperties = new SurefireProperties();
+        orderedProperties.putAll( src );
+        // Cannot make assumptions about insertion order
+        // keys() uses the items property, more reliable to test than size(),
+        // which is based on the Properties class
+        // see https://issues.apache.org/jira/browse/SUREFIRE-1445
+        assertEquals( src.size(), list( orderedProperties.keys() ).size() );
+        assertEquals( src.size(), size( orderedProperties.getStringKeySet().iterator() ) );
         assertEquals( 2, orderedProperties.size() );
 
+        assertTrue( list( orderedProperties.keys() ).contains( "a" ) );
+        assertTrue( list( orderedProperties.keys() ).contains( "b" ) );
+
+        Iterator it = orderedProperties.getStringKeySet().iterator();
+        SortedSet<Object> keys = new TreeSet<Object>();
+        keys.add( it.next() );
+        keys.add( it.next() );
+        it = keys.iterator();
+        assertEquals( "a", it.next() );
+        assertEquals( "b", it.next() );
+    }
 
+    private static int size( Iterator<?> iterator )
+    {
+        int count = 0;
+        while ( iterator.hasNext() ) {
+            iterator.next();
+            count++;
+        }
+        return count;
     }
 
 }

Reply | Threaded
Open this post in threaded view
|

[2/2] maven-surefire git commit: NULL not allowed in unit tests due to jsr305 @Nonnull for SUREFIRE-1262

Tibor Digana
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 <[hidden email]>
Authored: Sat Dec 2 16:21:49 2017 +0100
Committer: Tibor17 <[hidden email]>
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 );