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/08/06 08:50:23 UTC

[maven-surefire] branch master updated: 100% coverage of ImmutableMap

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 5711f97  100% coverage of ImmutableMap
5711f97 is described below

commit 5711f97243e1574ccc08e896c7c559d9f9eeb725
Author: tibordigana <ti...@apache.org>
AuthorDate: Tue Aug 6 10:50:11 2019 +0200

    100% coverage of ImmutableMap
---
 .../surefire/util/internal/ImmutableMapTest.java   | 88 ++++++++++++++++++++--
 1 file changed, 83 insertions(+), 5 deletions(-)

diff --git a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ImmutableMapTest.java b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ImmutableMapTest.java
index 0cfe918..1da1e22 100644
--- a/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ImmutableMapTest.java
+++ b/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ImmutableMapTest.java
@@ -23,7 +23,9 @@ import org.apache.maven.surefire.util.internal.ImmutableMap.Node;
 import org.junit.Before;
 import org.junit.Test;
 
-import java.util.HashMap;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
@@ -31,6 +33,8 @@ import java.util.Set;
 import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
 
 /**
@@ -41,9 +45,9 @@ public class ImmutableMapTest
     private ImmutableMap<String, String> map;
 
     @Before
-    public void setUp() throws Exception
+    public void setUp()
     {
-        Map<String, String> backingMap = new HashMap<>();
+        Map<String, String> backingMap = new LinkedHashMap<>();
         backingMap.put( "a", "1" );
         backingMap.put( "x", null );
         backingMap.put( "b", "2" );
@@ -54,7 +58,7 @@ public class ImmutableMapTest
     }
 
     @Test
-    public void testEntrySet() throws Exception
+    public void testEntrySet()
     {
         Set<Entry<String, String>> entries = map.entrySet();
         assertThat( entries, hasSize( 6 ) );
@@ -83,4 +87,78 @@ public class ImmutableMapTest
     {
         map.entrySet().clear();
     }
-}
\ No newline at end of file
+
+    @Test
+    public void shouldSafelyEnumerateEntries()
+    {
+        Iterator<Entry<String, String>> it = map.entrySet().iterator();
+
+        assertThat( it.hasNext(), is( true ) );
+        Entry<String, String> val = it.next();
+        assertThat( val.getKey(), is( "a" ) );
+        assertThat( val.getValue(), is( "1" ) );
+
+        assertThat( it.hasNext(), is( true ) );
+        val = it.next();
+        assertThat( val.getKey(), is( "x" ) );
+        assertThat( val.getValue(), is( nullValue() ) );
+
+        assertThat( it.hasNext(), is( true ) );
+        val = it.next();
+        assertThat( val.getKey(), is( "b" ) );
+        assertThat( val.getValue(), is( "2" ) );
+
+        assertThat( it.hasNext(), is( true ) );
+        val = it.next();
+        assertThat( val.getKey(), is( "c" ) );
+        assertThat( val.getValue(), is( "3" ) );
+
+        assertThat( it.hasNext(), is( true ) );
+        val = it.next();
+        assertThat( val.getKey(), is( "" ) );
+        assertThat( val.getValue(), is( "" ) );
+
+        assertThat( it.hasNext(), is( true ) );
+        val = it.next();
+        assertThat( val.getKey(), is( nullValue() ) );
+        assertThat( val.getValue(), is( "1" ) );
+
+        assertThat( it.hasNext(), is( false ) );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotSetEntries()
+    {
+        map.entrySet().iterator().next().setValue( "" );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotRemove()
+    {
+        map.remove( "a" );
+    }
+
+    @Test( expected = UnsupportedOperationException.class )
+    public void shouldNotRemoveNull()
+    {
+        map.remove( null );
+    }
+
+    @Test
+    public void shouldNotHaveEqualEntry()
+    {
+        Map<String, String> map = new ImmutableMap<>( Collections.singletonMap( "k", "v" ) );
+        Entry<String, String> e = map.entrySet().iterator().next();
+        assertThat( e, is( not( (Entry<String, String>) null ) ) );
+        assertThat( e, is( not( new Object() ) ) );
+    }
+
+    @Test
+    public void shouldHaveEqualEntry()
+    {
+        Map<String, String> map = new ImmutableMap<>( Collections.singletonMap( "k", "v" ) );
+        Entry<String, String> e = map.entrySet().iterator().next();
+        assertThat( e, is( e ) );
+        assertThat( e, is( (Entry<String, String>) new Node<>( "k", "v" ) ) );
+    }
+}