maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tibordig...@apache.org
Subject [1/2] maven-surefire git commit: [SUREFIRE-1445] Explicitly define SurefireProperties#putAll
Date Sat, 02 Dec 2017 15:22:14 GMT
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 <acogoluegnes@gmail.com>
Authored: Mon Nov 27 14:54:30 2017 +0100
Committer: Tibor17 <tibordigana@apache.org>
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;
     }
 
 }


Mime
View raw message