commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1540768 - in /commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4: ./ bidimap/ collection/ list/ map/ queue/ set/
Date Mon, 11 Nov 2013 16:48:36 GMT
Author: tn
Date: Mon Nov 11 16:48:35 2013
New Revision: 1540768

URL: http://svn.apache.org/r1540768
Log:
Added tests for the unmodifiable factory methods.

Modified:
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/BagUtilsTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/QueueUtilsTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableCollectionTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/UnmodifiableListTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSetTest.java
    commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/BagUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/BagUtilsTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/BagUtilsTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/BagUtilsTest.java
Mon Nov 11 16:48:35 2013
@@ -76,6 +76,8 @@ public class BagUtilsTest extends BulkTe
         } catch (final IllegalArgumentException ex) {
             // expected
         }
+        
+        assertSame("UnmodifiableBag shall not be decorated", bag, BagUtils.unmodifiableBag(bag));
     }
 
     public void testPredicatedBag() {
@@ -127,7 +129,7 @@ public class BagUtilsTest extends BulkTe
     }
 
     public void testUnmodifiableSortedBag() {
-        Bag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<Object>());
+        SortedBag<Object> bag = BagUtils.unmodifiableSortedBag(new TreeBag<Object>());
         assertTrue("Returned object should be an UnmodifiableSortedBag.",
             bag instanceof UnmodifiableSortedBag);
         try {
@@ -136,6 +138,8 @@ public class BagUtilsTest extends BulkTe
         } catch (final IllegalArgumentException ex) {
             // expected
         }
+        
+        assertSame("UnmodifiableSortedBag shall not be decorated", bag, BagUtils.unmodifiableSortedBag(bag));
     }
 
     public void testPredicatedSortedBag() {

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/QueueUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/QueueUtilsTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/QueueUtilsTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/QueueUtilsTest.java
Mon Nov 11 16:48:35 2013
@@ -58,6 +58,8 @@ public class QueueUtilsTest extends Bulk
         } catch (final IllegalArgumentException ex) {
             // expected
         }
+        
+        assertSame("UnmodifiableQueue shall not be decorated", queue, QueueUtils.unmodifiableQueue(queue));
     }
 
     public void testPredicatedQueue() {

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableBidiMapTest.java
Mon Nov 11 16:48:35 2013
@@ -20,8 +20,10 @@ import java.util.HashMap;
 import java.util.Map;
 
 import junit.framework.Test;
+
 import org.apache.commons.collections4.BidiMap;
 import org.apache.commons.collections4.BulkTest;
+import org.apache.commons.collections4.Unmodifiable;
 
 /**
  * JUnit tests.
@@ -78,4 +80,21 @@ public class UnmodifiableBidiMapTest<K, 
         return false;
     }
 
+    //-----------------------------------------------------------------------
+
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullMap() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final BidiMap<K, V> map = makeFullMap();
+        assertSame(map, UnmodifiableBidiMap.unmodifiableBidiMap(map));
+
+        try {
+            UnmodifiableBidiMap.unmodifiableBidiMap(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+    
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableOrderedBidiMapTest.java
Mon Nov 11 16:48:35 2013
@@ -20,9 +20,10 @@ import java.util.Map;
 import java.util.TreeMap;
 
 import junit.framework.Test;
-import org.apache.commons.collections4.BidiMap;
+
 import org.apache.commons.collections4.BulkTest;
 import org.apache.commons.collections4.OrderedBidiMap;
+import org.apache.commons.collections4.Unmodifiable;
 
 /**
  * JUnit tests.
@@ -45,7 +46,7 @@ public class UnmodifiableOrderedBidiMapT
     }
 
     @Override
-    public BidiMap<K, V> makeFullMap() {
+    public OrderedBidiMap<K, V> makeFullMap() {
         final OrderedBidiMap<K, V> bidi = new TreeBidiMap<K, V>();
         addSampleMappings(bidi);
         return UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(bidi);
@@ -89,4 +90,20 @@ public class UnmodifiableOrderedBidiMapT
         return false;
     }
 
+    //-----------------------------------------------------------------------
+
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullMap() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final OrderedBidiMap<K, V> map = makeFullMap();
+        assertSame(map, UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(map));
+
+        try {
+            UnmodifiableOrderedBidiMap.unmodifiableOrderedBidiMap(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/bidimap/UnmodifiableSortedBidiMapTest.java
Mon Nov 11 16:48:35 2013
@@ -23,6 +23,7 @@ import junit.framework.Test;
 
 import org.apache.commons.collections4.BulkTest;
 import org.apache.commons.collections4.SortedBidiMap;
+import org.apache.commons.collections4.Unmodifiable;
 
 /**
  * JUnit tests.
@@ -95,4 +96,21 @@ public class UnmodifiableSortedBidiMapTe
         return false;
     }
 
+    //-----------------------------------------------------------------------
+
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullMap() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final SortedBidiMap<K, V> map = makeFullMap();
+        assertSame(map, UnmodifiableSortedBidiMap.unmodifiableSortedBidiMap(map));
+
+        try {
+            UnmodifiableSortedBidiMap.unmodifiableSortedBidiMap(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableCollectionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableCollectionTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableCollectionTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/collection/UnmodifiableCollectionTest.java
Mon Nov 11 16:48:35 2013
@@ -21,6 +21,8 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.commons.collections4.Unmodifiable;
+
 /**
  * Extension of {@link AbstractCollectionTest} for exercising the
  * {@link UnmodifiableCollection} implementation.
@@ -69,6 +71,25 @@ public class UnmodifiableCollectionTest<
         return false;
     }
 
+    //-----------------------------------------------------------------------
+    
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullCollection() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final Collection<E> coll = makeFullCollection();
+        assertSame(coll, UnmodifiableCollection.unmodifiableCollection(coll));
+
+        try {
+            UnmodifiableCollection.unmodifiableCollection(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/UnmodifiableListTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/UnmodifiableListTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/UnmodifiableListTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/list/UnmodifiableListTest.java
Mon Nov 11 16:48:35 2013
@@ -82,6 +82,16 @@ public class UnmodifiableListTest<E> ext
         verifyUnmodifiable(list.subList(0, 2));
     }
 
+    public void testDecorateFactory() {
+        final List<E> list = makeObject();
+        assertSame(list, UnmodifiableList.unmodifiableList(list));
+
+        try {
+            UnmodifiableList.unmodifiableList(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
     @SuppressWarnings("unchecked")
     protected void verifyUnmodifiable(final List<E> list) {
         try {
@@ -161,6 +171,8 @@ public class UnmodifiableListTest<E> ext
         }
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableMapTest.java
Mon Nov 11 16:48:35 2013
@@ -65,6 +65,7 @@ public class UnmodifiableMapTest<K, V> e
     }
 
     //-----------------------------------------------------------------------
+
     public void testUnmodifiable() {
         assertTrue(makeObject() instanceof Unmodifiable);
         assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -80,6 +81,8 @@ public class UnmodifiableMapTest<K, V> e
         } catch (final IllegalArgumentException ex) {}
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableOrderedMapTest.java
Mon Nov 11 16:48:35 2013
@@ -64,6 +64,7 @@ public class UnmodifiableOrderedMapTest<
     }
 
     //-----------------------------------------------------------------------
+
     public void testUnmodifiable() {
         assertTrue(makeObject() instanceof Unmodifiable);
         assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -79,6 +80,8 @@ public class UnmodifiableOrderedMapTest<
         } catch (final IllegalArgumentException ex) {}
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/map/UnmodifiableSortedMapTest.java
Mon Nov 11 16:48:35 2013
@@ -64,6 +64,7 @@ public class UnmodifiableSortedMapTest<K
     }
 
     //-----------------------------------------------------------------------
+
     public void testUnmodifiable() {
         assertTrue(makeObject() instanceof Unmodifiable);
         assertTrue(makeFullMap() instanceof Unmodifiable);
@@ -79,6 +80,8 @@ public class UnmodifiableSortedMapTest<K
         } catch (final IllegalArgumentException ex) {}
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/queue/UnmodifiableQueueTest.java
Mon Nov 11 16:48:35 2013
@@ -21,6 +21,7 @@ import java.util.Collection;
 import java.util.LinkedList;
 import java.util.Queue;
 
+import org.apache.commons.collections4.Unmodifiable;
 import org.apache.commons.collections4.collection.AbstractCollectionTest;
 
 /**
@@ -62,6 +63,11 @@ public class UnmodifiableQueueTest<E> ex
     }
 
     @Override
+    public Queue<E> getCollection() {
+        return super.getCollection();
+    }
+
+    @Override
     public boolean isAddSupported() {
         return false;
     }
@@ -76,6 +82,7 @@ public class UnmodifiableQueueTest<E> ex
         return false;
     }
 
+    //-----------------------------------------------------------------------
     public void testQueueRemove() {
         resetEmpty();
         try {
@@ -84,6 +91,23 @@ public class UnmodifiableQueueTest<E> ex
         } catch (final UnsupportedOperationException ex) {}
     }
 
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullCollection() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final Queue<E> queue = makeFullCollection();
+        assertSame(queue, UnmodifiableQueue.unmodifiableQueue(queue));
+
+        try {
+            UnmodifiableQueue.unmodifiableQueue(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";
@@ -96,11 +120,4 @@ public class UnmodifiableQueueTest<E> ex
 //        writeExternalFormToDisk((java.io.Serializable) getCollection(), "src/test/resources/data/test/UnmodifiableQueue.fullCollection.version4.obj");
 //    }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public Queue<E> getCollection() {
-        return super.getCollection();
-    }
 }

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSetTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSetTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSetTest.java
Mon Nov 11 16:48:35 2013
@@ -23,6 +23,7 @@ import java.util.Set;
 import junit.framework.Test;
 
 import org.apache.commons.collections4.BulkTest;
+import org.apache.commons.collections4.Unmodifiable;
 
 /**
  * Extension of {@link AbstractSetTest} for exercising the
@@ -64,6 +65,25 @@ public class UnmodifiableSetTest<E> exte
         return false;
     }
 
+    //-----------------------------------------------------------------------
+
+    public void testUnmodifiable() {
+        assertTrue(makeObject() instanceof Unmodifiable);
+        assertTrue(makeFullCollection() instanceof Unmodifiable);
+    }
+    
+    public void testDecorateFactory() {
+        final Set<E> set = makeFullCollection();
+        assertSame(set, UnmodifiableSet.unmodifiableSet(set));
+
+        try {
+            UnmodifiableSet.unmodifiableSet(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";

Modified: commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java?rev=1540768&r1=1540767&r2=1540768&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java
(original)
+++ commons/proper/collections/trunk/src/test/java/org/apache/commons/collections4/set/UnmodifiableSortedSetTest.java
Mon Nov 11 16:48:35 2013
@@ -89,6 +89,16 @@ public class UnmodifiableSortedSetTest<E
         verifyUnmodifiable(set.subSet((E) Integer.valueOf(1), (E) Integer.valueOf(3)));
     }
 
+    public void testDecorateFactory() {
+        final SortedSet<E> set = makeFullCollection();
+        assertSame(set, UnmodifiableSortedSet.unmodifiableSortedSet(set));
+
+        try {
+            UnmodifiableSortedSet.unmodifiableSortedSet(null);
+            fail();
+        } catch (final IllegalArgumentException ex) {}
+    }
+
     /**
      * Verifies that a set is not modifiable
      */
@@ -138,6 +148,8 @@ public class UnmodifiableSortedSetTest<E
         assertTrue("natural order, so comparator should be null", c == null);
     }
 
+    //-----------------------------------------------------------------------
+
     @Override
     public String getCompatibilityVersion() {
         return "4";



Mime
View raw message