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
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -89,7 +89,7 @@ import org.apache.commons.collections.decorators.UnmodifiableCollection;
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @author Phil Steitz
|
* @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 {
|
public class TestCollectionUtils extends TestCase {
|
||||||
|
|
||||||
|
@ -593,31 +593,33 @@ public class TestCollectionUtils extends TestCase {
|
||||||
|
|
||||||
public void testGet() {
|
public void testGet() {
|
||||||
// Unordered map, entries exist
|
// Unordered map, entries exist
|
||||||
Map map = new HashMap();
|
{
|
||||||
map.put("zeroKey", "zero");
|
Map expected = new HashMap();
|
||||||
map.put("oneKey", "one");
|
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 index out of range
|
Map found = new HashMap();
|
||||||
try {
|
Map.Entry entry = (Map.Entry)(CollectionUtils.get(expected, 0));
|
||||||
test = CollectionUtils.get(map, 2);
|
found.put(entry.getKey(),entry.getValue());
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
entry = (Map.Entry)(CollectionUtils.get(expected, 1));
|
||||||
} catch (IndexOutOfBoundsException e) {
|
found.put(entry.getKey(),entry.getValue());
|
||||||
// expected
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
Object test;
|
||||||
test = CollectionUtils.get(map, -2);
|
|
||||||
fail("Expecting IndexOutOfBoundsException.");
|
|
||||||
} catch (IndexOutOfBoundsException e) {
|
|
||||||
// expected
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sorted map, entries exist, should respect order
|
// Sorted map, entries exist, should respect order
|
||||||
SortedMap map2 = new TreeMap();
|
SortedMap map2 = new TreeMap();
|
||||||
map2.put("zeroKey", "zero");
|
map2.put("zeroKey", "zero");
|
||||||
|
|
Loading…
Reference in New Issue