commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r233505 - in /jakarta/commons/proper/configuration/trunk/src: java/org/apache/commons/configuration/ConfigurationKey.java test/org/apache/commons/configuration/TestConfigurationKey.java
Date Fri, 19 Aug 2005 16:16:48 GMT
Author: oheger
Date: Fri Aug 19 09:16:31 2005
New Revision: 233505

URL: http://svn.apache.org/viewcvs?rev=233505&view=rev
Log:
Minor fixes and increased unit test coverage

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationKey.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationKey.java

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationKey.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationKey.java?rev=233505&r1=233504&r2=233505&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationKey.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationKey.java
Fri Aug 19 09:16:31 2005
@@ -286,7 +286,7 @@
      */
     public int hashCode()
     {
-        return keyBuffer.hashCode();
+        return keyBuffer.toString().hashCode();
     }
 
     /**
@@ -548,7 +548,7 @@
         {
             boolean result = false;
 
-            int idx = key.indexOf(INDEX_START);
+            int idx = key.lastIndexOf(INDEX_START);
             if (idx > 0)
             {
                 int endidx = key.indexOf(INDEX_END, idx);

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationKey.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationKey.java?rev=233505&r1=233504&r2=233505&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationKey.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationKey.java
Fri Aug 19 09:16:31 2005
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import java.util.NoSuchElementException;
+
 import junit.framework.TestCase;
 
 /**
@@ -59,6 +61,15 @@
         assertEquals("[@dataType]", it.currentKey(true));
         assertTrue(it.isAttribute());
         assertFalse(it.hasNext());
+        try
+        {
+            it.next();
+            fail("Could iterate over the iteration's end!");
+        }
+        catch(NoSuchElementException nex)
+        {
+            //ok
+        }
         
         key = new ConfigurationKey();
         assertFalse(key.iterator().hasNext());
@@ -66,6 +77,15 @@
         it = key.iterator();
         assertTrue(it.hasNext());
         assertEquals("simple", it.next());
+        try
+        {
+            it.remove();
+            fail("Could remove key component!");
+        }
+        catch(UnsupportedOperationException uex)
+        {
+            //ok
+        }
     }
     
     public void testAttribute()
@@ -103,6 +123,7 @@
         ConfigurationKey k2 = new ConfigurationKey(TESTKEY);
         assertTrue(k1.equals(k2));
         assertTrue(k2.equals(k1));
+        assertEquals(k1.hashCode(), k2.hashCode());
         k2.append("anotherPart");
         assertFalse(k1.equals(k2));
         assertFalse(k2.equals(k1));
@@ -132,6 +153,16 @@
         
         kc = k1.commonKey(k1);
         assertEquals(kc, k1);
+        
+        try
+        {
+            kc.commonKey(null);
+            fail("Could construct common key with null key!");
+        }
+        catch(IllegalArgumentException iex)
+        {
+            //ok
+        }
     }
     
     public void testDifferenceKey()
@@ -166,5 +197,29 @@
         assertEquals("trailing.dot.", kit.nextKey());
         assertEquals("strange", kit.nextKey());
         assertFalse(kit.hasNext());
+    }
+    
+    /**
+     * Tests some funny keys.
+     */
+    public void testIterateStrangeKeys()
+    {
+        ConfigurationKey k = new ConfigurationKey("key.");
+        ConfigurationKey.KeyIterator it = k.iterator();
+        assertTrue(it.hasNext());
+        assertEquals("key", it.next());
+        assertFalse(it.hasNext());
+        
+        k = new ConfigurationKey(".");
+        it = k.iterator();
+        assertFalse(it.hasNext());
+        
+        k = new ConfigurationKey("key().index()undefined(0).test");
+        it = k.iterator();
+        assertEquals("key()", it.next());
+        assertFalse(it.hasIndex());
+        assertEquals("index()undefined", it.nextKey(false));
+        assertTrue(it.hasIndex());
+        assertEquals(0, it.getIndex());
     }
 }



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