commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwaldh...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestCollectionUtils.java
Date Thu, 09 Oct 2003 11:00:09 GMT
rwaldhoff    2003/10/09 04:00:09

  Modified:    collections/src/test/org/apache/commons/collections
                        TestCollectionUtils.java
  Log:
  scope variables, group assertions into blocks
  
  Revision  Changes    Path
  1.28      +96 -92    jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java
  
  Index: TestCollectionUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- TestCollectionUtils.java	9 Oct 2003 10:48:19 -0000	1.27
  +++ TestCollectionUtils.java	9 Oct 2003 11:00:09 -0000	1.28
  @@ -592,8 +592,8 @@
       }
       
       public void testGet() {     
  -        // Unordered map, entries exist
           {
  +            // Unordered map, entries exist
               Map expected = new HashMap();
               expected.put("zeroKey", "zero");
               expected.put("oneKey", "one");
  @@ -619,108 +619,112 @@
                   // expected
               }
           }
  -        Object test;
  -        // Sorted map, entries exist, should respect order
  -        SortedMap map2 = new TreeMap();
  -        map2.put("zeroKey", "zero");
  -        map2.put("oneKey", "one");
  -        test = CollectionUtils.get(map2, 1);
  -        assertEquals("zeroKey",((Map.Entry) test).getKey());
  -        assertEquals("zero",((Map.Entry) test).getValue());
  -        test = CollectionUtils.get(map2, 0);
  -        assertEquals("oneKey",((Map.Entry) test).getKey());
  -        assertEquals("one",((Map.Entry) test).getValue());
  +
  +        {
  +            // Sorted map, entries exist, should respect order
  +            SortedMap map = new TreeMap();
  +            map.put("zeroKey", "zero");
  +            map.put("oneKey", "one");
  +            Object test = CollectionUtils.get(map, 1);
  +            assertEquals("zeroKey",((Map.Entry) test).getKey());
  +            assertEquals("zero",((Map.Entry) test).getValue());
  +            test = CollectionUtils.get(map, 0);
  +            assertEquals("oneKey",((Map.Entry) test).getKey());
  +            assertEquals("one",((Map.Entry) test).getValue());
  +        }
                   
  -        // List, entry exists
  -        List list = new ArrayList();
  -        list.add("zero");
  -        list.add("one");
  -        test = CollectionUtils.get(list, 0);
  -        assertEquals("zero",test);
  -        test = CollectionUtils.get(list, 1);
  -        assertEquals("one",test);
  -        
  -        // list, non-existent entry -- IndexOutOfBoundsException
  -        try {
  -            test = CollectionUtils.get(list, 2);
  -            fail("Expecting IndexOutOfBoundsException");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  -        }
  -        
  -        // Iterator, entry exists
  -        Iterator iterator = list.iterator();
  -        test = CollectionUtils.get(iterator,0);
  -        assertEquals("zero",test);
  -        iterator = list.iterator();
  -        test = CollectionUtils.get(iterator,1);
  -        assertEquals("one",test);
  -        
  -        // Iterator, non-existent entry 
  -        try {
  -            test = CollectionUtils.get(iterator,3);
  -            fail("Expecting IndexOutOfBoundsException.");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  -        }
  -        assertTrue(!iterator.hasNext());
  -        
  -        // Enumeration, entry exists
  -        Vector vector = new Vector(list);
  -        Enumeration enum = vector.elements();
  -        test = CollectionUtils.get(enum,0);
  -        assertEquals("zero",test);
  -        enum = vector.elements();
  -        test = CollectionUtils.get(enum,1);
  -        assertEquals("one",test);
  -        
  -        // Enumerator, non-existent entry 
  -        try {
  -            test = CollectionUtils.get(enum,3);
  -            fail("Expecting IndexOutOfBoundsException.");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  -        }
  -        assertTrue(!enum.hasMoreElements());
  -        
  -        // Collection, entry exists
  -        Bag bag = new HashBag();
  -        bag.add("element", 1);
  -        test = CollectionUtils.get(bag, 0);
  -        assertEquals("element",test);
  -        
  -        // Collection, non-existent entry
  -        try {
  -            test = CollectionUtils.get(bag, 1);
  -            fail("Expceting IndexOutOfBoundsException.");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  -        }
  -        
  -        // Object array, entry exists
  -        Object[] objArray = new Object[2];
  -        objArray[0] = "zero";
  -        objArray[1] = "one";
  -        test = CollectionUtils.get(objArray,0);
  -        assertEquals("zero",test);
  -        test = CollectionUtils.get(objArray,1);
  -        assertEquals("one",test);
  -        
  -        // Object array, non-existent entry -- ArrayIndexOutOfBoundsException
  -        try {
  -            test = CollectionUtils.get(objArray,2);
  -            fail("Expecting ArrayIndexOutOfBoundsException.");
  -        } catch (ArrayIndexOutOfBoundsException ex) {
  -            // expected
  -        }
  -        
  -        // Invalid object
  -        Object obj = new Object();
  -        try {
  -            test = CollectionUtils.get(obj, 0);
  -            fail("Expecting IllegalArgumentException.");
  -        } catch (IllegalArgumentException e) {
  -            // expected
  +        {
  +            // List, entry exists
  +            List list = new ArrayList();
  +            list.add("zero");
  +            list.add("one");
  +            assertEquals("zero",CollectionUtils.get(list, 0));
  +            assertEquals("one",CollectionUtils.get(list, 1));
  +            // list, non-existent entry -- IndexOutOfBoundsException
  +            try {
  +                CollectionUtils.get(list, 2);
  +                fail("Expecting IndexOutOfBoundsException");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
  +
  +            // Iterator, entry exists
  +            Iterator iterator = list.iterator();
  +            assertEquals("zero",CollectionUtils.get(iterator,0));
  +            iterator = list.iterator();
  +            assertEquals("one",CollectionUtils.get(iterator,1));
  +        
  +            // Iterator, non-existent entry 
  +            try {
  +                CollectionUtils.get(iterator,3);
  +                fail("Expecting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
  +            assertTrue(!iterator.hasNext());
  +        }
  +        
  +        {
  +            // Enumeration, entry exists
  +            Vector vector = new Vector();
  +            vector.addElement("zero");
  +            vector.addElement("one");
  +            Enumeration enum = vector.elements();
  +            assertEquals("zero",CollectionUtils.get(enum,0));
  +            enum = vector.elements();
  +            assertEquals("one",CollectionUtils.get(enum,1));
  +        
  +            // Enumerator, non-existent entry 
  +            try {
  +                CollectionUtils.get(enum,3);
  +                fail("Expecting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
  +            assertTrue(!enum.hasMoreElements());
  +        }
  +        
  +        {
  +            // Collection, entry exists
  +            Bag bag = new HashBag();
  +            bag.add("element", 1);
  +            assertEquals("element",CollectionUtils.get(bag, 0));
  +        
  +            // Collection, non-existent entry
  +            try {
  +                CollectionUtils.get(bag, 1);
  +                fail("Expceting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
  +        }
  +        
  +        {
  +            // Object array, entry exists
  +            Object[] objArray = new Object[2];
  +            objArray[0] = "zero";
  +            objArray[1] = "one";
  +            assertEquals("zero",CollectionUtils.get(objArray,0));
  +            assertEquals("one",CollectionUtils.get(objArray,1));
  +        
  +            // Object array, non-existent entry -- ArrayIndexOutOfBoundsException
  +            try {
  +                CollectionUtils.get(objArray,2);
  +                fail("Expecting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException ex) {
  +                // expected
  +            }
  +        }
  +        
  +        {
  +            // Invalid object
  +            Object obj = new Object();
  +            try {
  +                CollectionUtils.get(obj, 0);
  +                fail("Expecting IllegalArgumentException.");
  +            } catch (IllegalArgumentException e) {
  +                // expected
  +            }
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message