fix test so that it doesn't assume the order in which elements are returned from a HashMap.iterator
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131260 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8dbaeed44c
commit
0f57fa8e8c
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v 1.26 2003/10/09 10:39:16 rwaldhoff Exp $
|
||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/TestCollectionUtils.java,v 1.27 2003/10/09 10:48:19 rwaldhoff Exp $
|
||||
* ====================================================================
|
||||
*
|
||||
* The Apache Software License, Version 1.1
|
||||
|
@ -89,7 +89,7 @@ import org.apache.commons.collections.decorators.UnmodifiableCollection;
|
|||
* @author Stephen Colebourne
|
||||
* @author Phil Steitz
|
||||
*
|
||||
* @version $Revision: 1.26 $ $Date: 2003/10/09 10:39:16 $
|
||||
* @version $Revision: 1.27 $ $Date: 2003/10/09 10:48:19 $
|
||||
*/
|
||||
public class TestCollectionUtils extends TestCase {
|
||||
|
||||
|
@ -593,31 +593,33 @@ public class TestCollectionUtils extends TestCase {
|
|||
|
||||
public void testGet() {
|
||||
// Unordered map, entries exist
|
||||
Map map = new HashMap();
|
||||
map.put("zeroKey", "zero");
|
||||
map.put("oneKey", "one");
|
||||
{
|
||||
Map expected = new HashMap();
|
||||
expected.put("zeroKey", "zero");
|
||||
expected.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 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 {
|
||||
test = CollectionUtils.get(map, 2);
|
||||
CollectionUtils.get(expected, 2);
|
||||
fail("Expecting IndexOutOfBoundsException.");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
// expected
|
||||
}
|
||||
try {
|
||||
test = CollectionUtils.get(map, -2);
|
||||
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");
|
||||
|
|
Loading…
Reference in New Issue