directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r591147 - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/name/Rdn.java test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Date Thu, 01 Nov 2007 21:32:25 GMT
Author: seelmann
Date: Thu Nov  1 14:32:24 2007
New Revision: 591147

URL: http://svn.apache.org/viewvc?rev=591147&view=rev
Log:
Fixed NPE when calling iterator() of an empty Rdn, added Tests and fixed Javadoc.

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java?rev=591147&r1=591146&r2=591147&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/name/Rdn.java
Thu Nov  1 14:32:24 2007
@@ -531,19 +531,19 @@
 
 
    /**
-    * Retrieves the components of this name as an enumeration of strings. The
-    * effect on the enumeration of updates to this name is undefined. If the
-    * name has zero components, an empty (non-null) enumeration is returned.
+    * Retrieves the components of this RDN as an iterator of AttributeTypeAndValue. 
+    * The effect on the iterator of updates to this RDN is undefined. If the
+    * RDN has zero components, an empty (non-null) iterator is returned.
     *
-    * @return an enumeration of the components of this name, each a string
+    * @return an iterator of the components of this RDN, each an AttributeTypeAndValue
     */
    public Iterator<AttributeTypeAndValue> iterator()
    {
-       if ( nbAtavs == 1 )
+       if ( nbAtavs == 1 || nbAtavs == 0 )
        {
            return new Iterator<AttributeTypeAndValue>()
            {
-               private boolean hasMoreElement = true;
+               private boolean hasMoreElement = nbAtavs == 1;
 
 
                public boolean hasNext()

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=591147&r1=591146&r2=591147&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Thu Nov  1 14:32:24 2007
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.ldap.name;
 
 
+import java.util.Iterator;
+
 import javax.naming.InvalidNameException;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -512,4 +514,38 @@
         Rdn rdn = new Rdn( "cn=Kate Bush+sn=Bush" );
         assertEquals( "cn=Kate Bush+sn=Bush", rdn.getUpName() );
     }
+
+
+    public void testMultiValuedIterator() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "cn=Kate Bush+sn=Bush" );
+        Iterator<AttributeTypeAndValue> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    public void testSingleValuedIterator() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "cn=Kate Bush" );
+        Iterator<AttributeTypeAndValue> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    public void testEmptyIterator() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn();
+        Iterator<AttributeTypeAndValue> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertFalse( iterator.hasNext() );
+    }
+
 }



Mime
View raw message