commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ep...@apache.org
Subject cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestConfigurationSet.java TestConfigurationMap.java
Date Thu, 12 Aug 2004 17:29:53 GMT
epugh       2004/08/12 10:29:53

  Modified:    configuration/src/java/org/apache/commons/configuration
                        ConfigurationSet.java
               configuration/src/java/org/apache/commons/configuration/beanutils
                        ConfigurationDynaBean.java
               configuration/src/test/org/apache/commons/configuration
                        TestConfigurationMap.java
  Added:       configuration/src/test/org/apache/commons/configuration
                        TestConfigurationSet.java
  Log:
  29611 More unit tests from  Ricardo Gladwell
  
  Revision  Changes    Path
  1.3       +7 -10     jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationSet.java
  
  Index: ConfigurationSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/ConfigurationSet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ConfigurationSet.java	12 Aug 2004 17:17:15 -0000	1.2
  +++ ConfigurationSet.java	12 Aug 2004 17:29:53 -0000	1.3
  @@ -20,15 +20,12 @@
   import java.util.Iterator;
   import java.util.Map;
   
  -import org.apache.commons.logging.Log;
  -import org.apache.commons.logging.LogFactory;
   
   /**
    * @author <a href="mailto:ricardo.gladwell@btinternet.com">Ricardo Gladwell</a>
    */
   class ConfigurationSet extends AbstractSet {
   
  -    private final static Log log = LogFactory.getLog(ConfigurationSet.class);
   
       class Entry implements Map.Entry {
   
  @@ -55,11 +52,11 @@
           
       }
   
  -    class ConfigurationEntrySetIterator implements Iterator {
  +    class ConfigurationSetIterator implements Iterator {
   
           Iterator keys;
   
  -        public ConfigurationEntrySetIterator() {
  +        public ConfigurationSetIterator() {
           	keys = configuration.getKeys();
           }
   
  @@ -80,7 +77,6 @@
       Configuration configuration;
   
       public ConfigurationSet(Configuration configuration) {
  -        if(log.isTraceEnabled()) log.trace("ConfigurationEntrySet("+configuration+")");
           this.configuration = configuration;
       }
   
  @@ -88,10 +84,12 @@
   	 * @see java.util.Collection#size()
   	 */
   	public int size() {
  -        if(log.isTraceEnabled()) log.trace("size()");
           int count = 0;
   		Iterator iterator = configuration.getKeys();
  -        while(iterator.hasNext()) count++;
  +        while(iterator.hasNext()) {
  +            iterator.next();
  +            count++;
  +        }
           return count;
   	}
   
  @@ -99,8 +97,7 @@
   	 * @see java.util.Collection#iterator()
   	 */
   	public Iterator iterator() {
  -        if(log.isTraceEnabled()) log.trace("iterator()");
  -		return new ConfigurationEntrySetIterator();
  +		return new ConfigurationSetIterator();
   	}
   
   }
  
  
  
  1.2       +1 -3      jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java
  
  Index: ConfigurationDynaBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/beanutils/ConfigurationDynaBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConfigurationDynaBean.java	12 Aug 2004 16:29:38 -0000	1.1
  +++ ConfigurationDynaBean.java	12 Aug 2004 17:29:53 -0000	1.2
  @@ -52,13 +52,11 @@
       private final static Log log = LogFactory.getLog(ConfigurationDynaBean.class);
   
       Configuration configuration;
  -    ConfigurationMap map;
   
       public ConfigurationDynaBean(Configuration configuration) {
           super(configuration);
           if(log.isTraceEnabled()) log.trace("ConfigurationDynaBean("+configuration+")");
           this.configuration = configuration;
  -        map = new ConfigurationMap(configuration);
       }
   
       /**
  @@ -79,7 +77,7 @@
           } else if(value instanceof boolean[]) {
               boolean[] array = (boolean[]) value;
               for(int i = 0; i < array.length; i++)
  -                configuration.addProperty(name,new Boolean(array[i]));
  +                configuration.addProperty(name,Boolean.valueOf(array[i]));
           } else if(value instanceof char[]) {
               char[] array = (char[]) value;
               for(int i = 0; i < array.length; i++)
  
  
  
  1.2       +0 -39     jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationMap.java
  
  Index: TestConfigurationMap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationMap.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestConfigurationMap.java	12 Aug 2004 16:06:01 -0000	1.1
  +++ TestConfigurationMap.java	12 Aug 2004 17:29:53 -0000	1.2
  @@ -16,10 +16,6 @@
   
   package org.apache.commons.configuration;
   
  -import java.util.Iterator;
  -import java.util.Map;
  -import java.util.Set;
  -
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -34,30 +30,20 @@
   
       String[] properties = {
               "booleanProperty",
  -            "booleanSecond",
               "doubleProperty",
               "floatProperty",
               "intProperty",
               "longProperty",
  -            "mappedProperty.key1",
  -            "mappedProperty.key2",
  -            "mappedProperty.key3",
  -            "mappedIntProperty.key1",
               "shortProperty",
               "stringProperty"
       };
       
       Object[] values = {
               Boolean.TRUE,
  -            Boolean.TRUE,
               new Double(Double.MAX_VALUE),
               new Float(Float.MAX_VALUE),
               new Integer(Integer.MAX_VALUE),
               new Long(Long.MAX_VALUE),
  -            "First Value",
  -            "Second Value",
  -            "Third Value",
  -            new Integer(Integer.MAX_VALUE),
               new Short(Short.MAX_VALUE),
               "This is a string"
       };
  @@ -96,31 +82,6 @@
       public void tearDown()
       {
           map = null;
  -    }
  -
  -    /**
  -     * Class under test for Set entrySet()
  -     */
  -    public void testEntrySet()
  -    {
  -        Set entrySet = map.entrySet();
  -        Iterator iterator = entrySet.iterator();
  -        while(iterator.hasNext()) {
  -            Object object = iterator.next();
  -            assertTrue("Entry set iterator did not return EntrySet object, returned "
  -                    + object.getClass().getName(), object instanceof Map.Entry);
  -            Map.Entry entry = (Map.Entry) object;
  -            boolean found = false;
  -            for(int i = 0; i < properties.length; i++) {
  -                if(entry.getKey().equals(properties[i])) {
  -                    assertEquals("Incorrect value for property " +
  -                            properties[i],values[i],entry.getValue());
  -                    found = true;
  -                    break;
  -                }
  -            }
  -            assertTrue("Could not find property " + entry.getKey(),found);
  -        }
       }
   
       /**
  
  
  
  1.1                  jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestConfigurationSet.java
  
  Index: TestConfigurationSet.java
  ===================================================================
  package org.apache.commons.configuration;
  
  import java.util.Iterator;
  import java.util.Map;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  /**
   * @author rgladwel
   */
  public class TestConfigurationSet extends TestCase {
  
      ConfigurationSet set;
  
      String[] properties = {
              "booleanProperty",
              "doubleProperty",
              "floatProperty",
              "intProperty",
              "longProperty",
              "shortProperty",
              "stringProperty"
      };
  
      Object[] values = {
              Boolean.TRUE,
              new Double(Double.MAX_VALUE),
              new Float(Float.MAX_VALUE),
              new Integer(Integer.MAX_VALUE),
              new Long(Long.MAX_VALUE),
              new Short(Short.MAX_VALUE),
              "This is a string"
      };
  
      /**
       * Construct a new instance of this test case.
       * @param name Name of the test case
       */
      public TestConfigurationSet(String name)
      {
          super(name);
      }
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() throws Exception
      {
          BaseConfiguration configuration = new BaseConfiguration();
          for(int i = 0; i < properties.length ; i++)
              configuration.setProperty(properties[i], values[i]);
          set = new ConfigurationSet(configuration);
      }
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite()
      {
          return (new TestSuite(TestConfigurationSet.class));
      }
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown()
      {
          set = null;
      }
  
      public void testSize() {
          assertEquals("Entry set does not match properties size.", properties.length, set.size());
      }
  
      /**
       * Class under test for Iterator iterator()
       */
      public void testIterator() {
          Iterator iterator = set.iterator();
          while(iterator.hasNext()) {
              Object object = iterator.next();
              assertTrue("Entry set iterator did not return EntrySet object, returned "
                      + object.getClass().getName(), object instanceof Map.Entry);
              Map.Entry entry = (Map.Entry) object;
              boolean found = false;
              for(int i = 0; i < properties.length; i++) {
                  if(entry.getKey().equals(properties[i])) {
                      assertEquals("Incorrect value for property " +
                              properties[i],values[i],entry.getValue());
                      found = true;
                  }
              }
              assertTrue("Could not find property " + entry.getKey(),found);
              iterator.remove();
          }
          assertTrue("Iterator failed to remove all properties.",set.isEmpty());
      }
  
  }
  
  
  

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