Index: TestMapUtils.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/collections/src/test/org/apache/ commons/collections/TestMapUtils.java,v retrieving revision 1.1 diff -u -r1.1 TestMapUtils.java --- TestMapUtils.java 13 Aug 2002 00:26:52 -0000 1.1 +++ TestMapUtils.java 12 Oct 2002 20:55:10 -0000 @@ -133,6 +133,71 @@ // expected } } + + + public void testAsMap() { + Map map = MapUtils.asMap(new String[][] {{"foo", "bar"}, {"hello", "world"}}); + + assertEquals("bar", map.get("foo")); + assertEquals("world", map.get("hello")); + + try { + MapUtils.asMap(new String[][] {{"foo", "bar"}, {"short"}}); + fail("exception expected"); + } catch (ArrayIndexOutOfBoundsException e) { + // expected. + } + + try { + MapUtils.asMap(new Object[] {new Object[] {"foo", "bar"}, "illegal type"}); + fail("exception expected"); + } catch (IllegalArgumentException e) { + // expected. + } + + try { + MapUtils.asMap(new Object[] {new Object[] {"foo", "bar"}, null}); + fail("exception expected"); + } catch (NullPointerException e) { + // expected. + } + + map = MapUtils.asMap(new Object[] {new DefaultMapEntry("foo", "bar")}); + assertEquals("bar", map.get("foo")); + } + + + public void testToMapEntry() throws Exception { + try { + MapUtils.toMapEntry(new String("no way")); + fail("Exception expected."); + } catch (IllegalArgumentException e) { + // expected + } + + try { + Map.Entry entry = MapUtils.toMapEntry(new Object[] {"short"}); + entry.getValue(); + fail("Exception expected."); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + + Map.Entry entry1 = MapUtils.toMapEntry( + new Object[] {"foo", "bar"}); + assertTrue("foo" == entry1.getKey()); + assertTrue("bar" == entry1.getValue()); + + Map.Entry entry2 = new DefaultMapEntry("foo", "bar"); + Map.Entry entry3 = MapUtils.toMapEntry(entry2); + assertTrue(entry3 == entry2); + assertTrue(entry1.equals(entry3)); + + Map.Entry entry4 = MapUtils.toMapEntry( + new Object[] {"hello", "world"}); + assertTrue(!entry1.equals(entry4)); + assertTrue(!entry1.equals("no Map.Entry")); + }
public BulkTest bulkTestPredicatedMap() { -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>