directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r951339 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java
Date Fri, 04 Jun 2010 09:29:57 GMT
Author: felixk
Date: Fri Jun  4 09:29:56 2010
New Revision: 951339

URL: http://svn.apache.org/viewvc?rev=951339&view=rev
Log:
- value2 is known to be not null in this place
- Add tests for equals

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java?rev=951339&r1=951338&r2=951339&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/AttributeUtils.java
Fri Jun  4 09:29:56 2010
@@ -108,7 +108,7 @@ public class AttributeUtils
 
         if ( value1 == null )
         {
-            return ( value2 == null );
+            return false;
         }
 
         if ( value1 instanceof byte[] )

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java?rev=951339&r1=951338&r2=951339&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/AttributeUtilsTest.java
Fri Jun  4 09:29:56 2010
@@ -20,6 +20,7 @@
 package org.apache.directory.shared.ldap.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
@@ -28,14 +29,15 @@ import java.util.HashSet;
 import java.util.Set;
 
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
-import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -46,6 +48,26 @@ import org.junit.Test;
  */
 public class AttributeUtilsTest
 {
+
+    byte[] byteArrayA;
+    byte[] byteArrayACopy;
+    byte[] byteArrayB;
+    byte[] byteArrayC;
+    
+    /**
+     * Initialize name instances
+     */
+    @Before
+    public void initNames() throws Exception
+    {
+        byte[] b = "aa".getBytes();
+        byteArrayA = b;
+        byteArrayACopy = b;
+        byteArrayB = "aa".getBytes();
+        byteArrayC = "cc".getBytes();
+    }
+
+    
     /**
      * Test a addModification applied to an empty entry
      */
@@ -393,5 +415,47 @@ public class AttributeUtilsTest
         assertNotNull( entry.get( "cn" ) );
         assertNull( entry.get( "ou" ) );
     }
+
+    @Test
+    public void testEqualsNull() throws Exception
+    {
+        assertFalse( AttributeUtils.equals( byteArrayA, null ) );
+        assertFalse( AttributeUtils.equals( null, byteArrayA ) );
+        assertTrue( AttributeUtils.equals( null, null ) );
+    }
+
+
+    @Test
+    public void testEqualsReflexive() throws Exception
+    {
+        assertTrue( AttributeUtils.equals( byteArrayA, byteArrayA ) );
+    }
+
+
+    @Test
+    public void testEqualsSymmetric() throws Exception
+    {
+        assertTrue( AttributeUtils.equals( byteArrayA, byteArrayACopy ) );
+        assertTrue( AttributeUtils.equals( byteArrayACopy, byteArrayA ) );
+    }
+
+
+    @Test
+    public void testEqualsTransitive() throws Exception
+    {
+        assertTrue( AttributeUtils.equals( byteArrayA, byteArrayACopy ) );
+        assertTrue( AttributeUtils.equals( byteArrayACopy, byteArrayB ) );
+        assertTrue( AttributeUtils.equals( byteArrayA, byteArrayB ) );
+    }
+
+
+    @Test
+    public void testNotEqualDiffValue() throws Exception
+    {
+        assertFalse( AttributeUtils.equals( byteArrayA, byteArrayC ) );
+        assertFalse( AttributeUtils.equals( byteArrayC, byteArrayA ) );
+        assertFalse( AttributeUtils.equals( byteArrayA, "otherObject" ) );
+        assertFalse( AttributeUtils.equals( byteArrayA, "otherObject" ) );
+    }
 }
 



Mime
View raw message