rwaldhoff    2003/10/09 03:48:19

  Modified:    collections/src/test/org/apache/commons/collections
                        TestCollectionUtils.java
  Log:
  fix test so that it doesn't assume the order in which elements are returned from a 
HashMap.iterator
  
  Revision  Changes    Path
  1.27      +28 -26    
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.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- TestCollectionUtils.java  9 Oct 2003 10:39:16 -0000       1.26
  +++ TestCollectionUtils.java  9 Oct 2003 10:48:19 -0000       1.27
  @@ -593,31 +593,33 @@
       
       public void testGet() {     
           // Unordered map, entries exist
  -        Map map = new HashMap();
  -        map.put("zeroKey", "zero");
  -        map.put("oneKey", "one");
  -
  -        Object test = CollectionUtils.get(map, 0);
  -        assertEquals("zeroKey",((Map.Entry) test).getKey());
  -        assertEquals("zero",((Map.Entry) test).getValue());
  -        test = CollectionUtils.get(map, 1);
  -        assertEquals("oneKey",((Map.Entry) test).getKey());
  -        assertEquals("one",((Map.Entry) test).getValue());
  +        {
  +            Map expected = new HashMap();
  +            expected.put("zeroKey", "zero");
  +            expected.put("oneKey", "one");
           
  -        // Map index out of range
  -        try {
  -            test = CollectionUtils.get(map,  2);
  -            fail("Expecting IndexOutOfBoundsException.");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  -        }
  -        try {
  -            test = CollectionUtils.get(map,  -2);
  -            fail("Expecting IndexOutOfBoundsException.");
  -        } catch (IndexOutOfBoundsException e) {
  -            // expected
  +            Map found = new HashMap();
  +            Map.Entry entry = (Map.Entry)(CollectionUtils.get(expected, 0));
  +            found.put(entry.getKey(),entry.getValue());
  +            entry = (Map.Entry)(CollectionUtils.get(expected, 1));
  +            found.put(entry.getKey(),entry.getValue());
  +            assertEquals(expected,found);
  +        
  +            // Map index out of range
  +            try {
  +                CollectionUtils.get(expected,  2);
  +                fail("Expecting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
  +            try {
  +                CollectionUtils.get(expected,  -2);
  +                fail("Expecting IndexOutOfBoundsException.");
  +            } catch (IndexOutOfBoundsException e) {
  +                // expected
  +            }
           }
  -
  +        Object test;
           // Sorted map, entries exist, should respect order
           SortedMap map2 = new TreeMap();
           map2.put("zeroKey", "zero");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to