directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1393277 - in /directory/shared/trunk/ldap/model/src: main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java
Date Wed, 03 Oct 2012 03:29:22 GMT
Author: elecharny
Date: Wed Oct  3 03:29:22 2012
New Revision: 1393277

URL: http://svn.apache.org/viewvc?rev=1393277&view=rev
Log:
Fixed a bug in the BooleanCoparator : if the two Strings were eauals, but with two different
hashcode, the comparator was failing. Added a test to check this issue. Fixes DIRSERVER-1727.

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java?rev=1393277&r1=1393276&r2=1393277&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparator.java
Wed Oct  3 03:29:22 2012
@@ -77,6 +77,14 @@ public class BooleanComparator extends L
         // with normalized booleans, so no need to upper case them.
         // We don't need to check the assertion value, because we
         // are dealing with booleans.
-        return ( b1.equals( "TRUE" ) ? 1 : -1 );
+        boolean boolean1 = Boolean.valueOf( b1 );
+        boolean boolean2 = Boolean.valueOf( b2 );
+
+        if ( boolean1 == boolean2 )
+        {
+            return 0;
+        }
+
+        return ( boolean1 ? 1 : -1 );
     }
 }

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java?rev=1393277&r1=1393276&r2=1393277&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/shared/ldap/model/schema/comparators/BooleanComparatorTest.java
Wed Oct  3 03:29:22 2012
@@ -22,13 +22,13 @@ package org.apache.directory.shared.ldap
 
 import static org.junit.Assert.assertEquals;
 
-import com.mycila.junit.concurrent.Concurrency;
-import com.mycila.junit.concurrent.ConcurrentJunitRunner;
-import org.apache.directory.shared.ldap.model.schema.comparators.BooleanComparator;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
 
 /**
  * Test the Boolean comparator
@@ -67,5 +67,11 @@ public class BooleanComparatorTest
         assertEquals( 0, comparator.compare( "FALSE", "FALSE" ) );
         assertEquals( -1, comparator.compare( "FALSE", "TRUE" ) );
         assertEquals( 1, comparator.compare( "TRUE", "FALSE" ) );
+
+        // tested with two different strings
+        String b1 = "TRUE";
+        String b2 = "true";
+
+        assertEquals( 0, comparator.compare( b1, b2.toUpperCase() ) );
     }
 }



Mime
View raw message