commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/collections/src/test/org/apache/commons/collections TestMapUtils.java
Date Sat, 26 Apr 2003 14:27:46 GMT
scolebourne    2003/04/26 07:27:46

  Modified:    collections/src/test/org/apache/commons/collections
                        TestMapUtils.java
  Log:
  Add invertMap(Map) method
  Add toMap(ResourceBundle) method
  from Arun Mammen Thomas
  
  Revision  Changes    Path
  1.5       +66 -6     jakarta-commons/collections/src/test/org/apache/commons/collections/TestMapUtils.java
  
  Index: TestMapUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/collections/src/test/org/apache/commons/collections/TestMapUtils.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestMapUtils.java	6 Apr 2003 20:07:55 -0000	1.4
  +++ TestMapUtils.java	26 Apr 2003 14:27:46 -0000	1.5
  @@ -1,13 +1,10 @@
   /*
    * $Header$
  - * $Revision$
  - * $Date$
  - *
    * ====================================================================
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -61,14 +58,23 @@
   package org.apache.commons.collections;
   
   import java.util.HashMap;
  +import java.util.HashSet;
   import java.util.Iterator;
  +import java.util.ListResourceBundle;
   import java.util.Map;
  +import java.util.ResourceBundle;
  +import java.util.Set;
   
   import junit.framework.Test;
   
   
   /**
  - *  Tests for MapUtils.
  + * Tests for MapUtils.
  + * 
  + * @version $Revision$ $Date$
  + * 
  + * @author Stephen Colebourne
  + * @author Arun Mammen Thomas
    */
   public class TestMapUtils extends BulkTest {
   
  @@ -250,4 +256,58 @@
           assertSame(i1, i2);
       }
   
  +    public void testInvertMap() {
  +        final Map in = new HashMap( 5 , 1 );
  +        in.put( "1" , "A" );
  +        in.put( "2" , "B" );
  +        in.put( "3" , "C" );
  +        in.put( "4" , "D" );
  +        in.put( "5" , "E" );
  +    
  +        final Set inKeySet = new HashSet( in.keySet() );
  +        final Set inValSet = new HashSet( in.values() );
  +        
  +        final Map out =  MapUtils.invertMap(in);
  +
  +        final Set outKeySet = new HashSet( out.keySet() );
  +        final Set outValSet = new HashSet( out.values() );
  +        
  +        assertTrue( inKeySet.equals( outValSet ));
  +        assertTrue( inValSet.equals( outKeySet ));
  +        
  +        assertEquals( out.get("A"), "1" );
  +        assertEquals( out.get("B"), "2" );
  +        assertEquals( out.get("C"), "3" );
  +        assertEquals( out.get("D"), "4" );
  +        assertEquals( out.get("E"), "5" );
  +    }
  +                
  +    public void testConvertResourceBundle() {
  +        final Map in = new HashMap( 5 , 1 );
  +        in.put( "1" , "A" );
  +        in.put( "2" , "B" );
  +        in.put( "3" , "C" );
  +        in.put( "4" , "D" );
  +        in.put( "5" , "E" );
  +    
  +        ResourceBundle b = new ListResourceBundle() {
  +            public Object[][] getContents() {
  +                final Object[][] contents = new Object[ in.size() ][2];
  +                final Iterator i = in.keySet().iterator();
  +                int n = 0;
  +                while ( i.hasNext() ) {
  +                    final Object key = i.next();
  +                    final Object val = in.get( key );
  +                    contents[ n ][ 0 ] = key;
  +                    contents[ n ][ 1 ] = val;
  +                    ++n;
  +                }
  +                return contents;
  +            }
  +        };
  +        
  +        final Map out = MapUtils.toMap(b); 
  +
  +        assertTrue( in.equals(out));
  +    }
   }
  
  
  

---------------------------------------------------------------------
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