directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r948947 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java test/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparatorTest.java
Date Thu, 27 May 2010 18:49:14 GMT
Author: elecharny
Date: Thu May 27 18:49:14 2010
New Revision: 948947

URL: http://svn.apache.org/viewvc?rev=948947&view=rev
Log:
Added a test for the BooleanComparator

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

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java?rev=948947&r1=948946&r2=948947&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparator.java
Thu May 27 18:49:14 2010
@@ -19,6 +19,7 @@
  */
 package org.apache.directory.shared.ldap.schema.comparators;
 
+
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,6 +39,7 @@ public class BooleanComparator extends L
     /** The serialVersionUID */
     private static final long serialVersionUID = 1L;
 
+
     /**
      * The BooleanComparator constructor. Its OID is the BooleanMatch matching
      * rule OID.
@@ -47,13 +49,14 @@ public class BooleanComparator extends L
         super( oid );
     }
 
+
     /**
      * Implementation of the Compare method
      */
-    public int compare( String b1, String b2 ) 
+    public int compare( String b1, String b2 )
     {
         LOG.debug( "comparing boolean objects '{}' with '{}'", b1, b2 );
-        
+
         // First, shortcut the process by comparing
         // references. If they are equals, then o1 and o2
         // reference the same object
@@ -61,7 +64,7 @@ public class BooleanComparator extends L
         {
             return 0;
         }
-        
+
         // Then, deal with one of o1 or o2 being null
         // Both can't be null, because then they would 
         // have been catched by the previous test
@@ -72,7 +75,7 @@ public class BooleanComparator extends L
 
         // The boolean should have been stored as 'TRUE' or 'FALSE'
         // into the server, and the compare method will be called
-        // with normalized booleans, so no need to uppercase them.
+        // 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 );

Added: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparatorTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparatorTest.java?rev=948947&view=auto
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparatorTest.java
(added)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/schema/comparators/BooleanComparatorTest.java
Thu May 27 18:49:14 2010
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.shared.ldap.schema.comparators;
+
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test the Boolean comparator
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BooleanComparatorTest
+{
+    private BooleanComparator comparator;
+
+
+    @Before
+    public void init()
+    {
+        comparator = new BooleanComparator( null );
+    }
+
+
+    @Test
+    public void testNullBooleans()
+    {
+        assertEquals( 0, comparator.compare( null, null ) );
+        assertEquals( -1, comparator.compare( null, "TRUE" ) );
+        assertEquals( -1, comparator.compare( null, "FALSE" ) );
+        assertEquals( 1, comparator.compare( "TRUE", null ) );
+        assertEquals( 1, comparator.compare( "FALSE", null ) );
+    }
+
+
+    @Test
+    public void testBooleans()
+    {
+        assertEquals( 0, comparator.compare( "TRUE", "TRUE" ) );
+        assertEquals( 0, comparator.compare( "FALSE", "FALSE" ) );
+        assertEquals( -1, comparator.compare( "FALSE", "TRUE" ) );
+        assertEquals( 1, comparator.compare( "TRUE", "FALSE" ) );
+    }
+}



Mime
View raw message