From d5bfdf10effe1eff92ee3fd81d92636d152ef269 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 29 Jan 2015 14:36:19 +0000
Subject: [PATCH] AutoRefactor'ed code cleanups Manually fixed the test assertions

---
 opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java                                    |   14 ++++---
 opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java                                    |   27 ++++++-------
 opendj-sdk/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java |   14 +++---
 opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java                             |    2 
 opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java                                     |   18 ++++----
 5 files changed, 37 insertions(+), 38 deletions(-)

diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java
index d486a48..751b88c 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/AddressMask.java
@@ -204,17 +204,16 @@
         } else if (ruleString.startsWith("[") || ruleString.indexOf(':') != -1) {
             ruleType = RuleType.IPv6;
         } else {
-            int wildCount = 0;
+            int wildcardsCount = 0;
             final String[] s = ruleString.split("\\.", -1);
             /*
              * Try to figure out how many wildcards and if the rule is hostname
-             * (can't begin with digit) or ipv4 address. Default to IPv4
-             * ruletype.
+             * (can't begin with digit) or ipv4 address. Default to IPv4 ruletype.
              */
             ruleType = RuleType.HOST;
             for (final String value : s) {
-                if (value.equals("*")) {
-                    wildCount++;
+                if ("*".equals(value)) {
+                    wildcardsCount++;
                     continue;
                 }
                 // Looks like an ipv4 address
@@ -224,7 +223,7 @@
                 }
             }
             // All wildcards (*.*.*.*)
-            if (wildCount == s.length) {
+            if (wildcardsCount == s.length) {
                 ruleType = RuleType.ALLWILDCARD;
             }
         }
@@ -249,10 +248,9 @@
             return false;
         }
         for (int i = 0; i < prefixMask.length; i++) {
-            if (!wildCard.get(i)) {
-                if ((ruleMask[i] & prefixMask[i]) != (remoteMask[i] & prefixMask[i])) {
-                    return false;
-                }
+            if (!wildCard.get(i)
+                    && (ruleMask[i] & prefixMask[i]) != (remoteMask[i] & prefixMask[i])) {
+                return false;
             }
         }
         return true;
@@ -276,10 +274,9 @@
         }
         for (int i = 0; i < s.length; i++) {
             // skip if wildcard
-            if (!hostName[i].equals("*")) {
-                if (!s[i].equalsIgnoreCase(hostName[i])) {
-                    return false;
-                }
+            if (!"*".equals(hostName[i])
+                    && !s[i].equalsIgnoreCase(hostName[i])) {
+                return false;
             }
         }
         return true;
@@ -401,7 +398,7 @@
             }
             for (int i = 0; i < IN4ADDRSZ; i++) {
                 final String quad = s[i].trim();
-                if (quad.equals("*")) {
+                if ("*".equals(quad)) {
                     wildCard.set(i); // see wildcard mark bitset
                 } else {
                     final long val = Integer.parseInt(quad);
diff --git a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
index af0903a..23ae1cc 100644
--- a/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
+++ b/opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/ObjectClass.java
@@ -67,7 +67,7 @@
         private final Set<String> optionalAttributes = new LinkedHashSet<String>();
         private final Set<String> requiredAttributes = new LinkedHashSet<String>();
         private final Set<String> superiorClasses = new LinkedHashSet<String>();
-        private ObjectClassType type = null;
+        private ObjectClassType type;
 
         Builder(final ObjectClass oc, final SchemaBuilder builder) {
             super(builder, oc);
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java
index 95db14c..80b2ee4 100644
--- a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/DNTestCase.java
@@ -26,6 +26,9 @@
  */
 package org.forgerock.opendj.ldap;
 
+import static org.fest.assertions.Assertions.*;
+import static org.testng.Assert.*;
+
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
@@ -33,9 +36,6 @@
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
-import static org.fest.assertions.Assertions.*;
-import static org.testng.Assert.*;
-
 /**
  * This class defines a set of tests for the org.forgerock.opendj.ldap.DN class.
  */
@@ -546,13 +546,13 @@
         final int h2 = dn2.hashCode();
 
         if (result == 0) {
-            if (h1 != h2) {
-                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
-            }
+            assertThat(h1)
+                    .as("Hash codes for <" + first + "> and <" + second + "> should be the same.")
+                    .isEqualTo(h2);
         } else {
-            if (h1 == h2) {
-                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
-            }
+            assertThat(h1)
+                    .as("Hash codes for <" + first + "> and <" + second + "> should NOT be the same.")
+                    .isNotEqualTo(h2);
         }
     }
 
diff --git a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java
index ff3f7e7..04d6eae 100644
--- a/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java
+++ b/opendj-sdk/opendj-core/src/test/java/org/forgerock/opendj/ldap/RDNTestCase.java
@@ -27,6 +27,7 @@
 
 package org.forgerock.opendj.ldap;
 
+import static org.fest.assertions.Assertions.*;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
@@ -34,6 +35,7 @@
 
 import java.util.Arrays;
 import java.util.Iterator;
+
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
 import org.forgerock.opendj.ldap.schema.AttributeType;
 import org.forgerock.opendj.ldap.schema.Schema;
@@ -436,13 +438,13 @@
         final int h2 = rdn2.hashCode();
 
         if (result == 0) {
-            if (h1 != h2) {
-                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
-            }
+            assertThat(h1)
+                    .as("Hash codes for <" + first + "> and <" + second + "> should be the same.")
+                    .isEqualTo(h2);
         } else {
-            if (h1 == h2) {
-                fail("Hash codes for <" + first + "> and <" + second + "> should be the same.");
-            }
+            assertThat(h1)
+                    .as("Hash codes for <" + first + "> and <" + second + "> should NOT be the same.")
+                    .isNotEqualTo(h2);
         }
     }
 }
diff --git a/opendj-sdk/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java b/opendj-sdk/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java
index 0ed25c8..66a3594 100644
--- a/opendj-sdk/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java
+++ b/opendj-sdk/opendj-rest2ldap-servlet/src/main/java/org/forgerock/opendj/rest2ldap/servlet/Rest2LDAPAuthnFilter.java
@@ -123,7 +123,7 @@
         }
 
         // First of all parse the HTTP headers for authentication credentials.
-        if (!(request instanceof HttpServletRequest && response instanceof HttpServletResponse)) {
+        if ((!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse))) {
             // This should never happen.
             throw new ServletException("non-HTTP request or response");
         }
@@ -165,7 +165,7 @@
             } else if (headerAuthorization != null) {
                 final StringTokenizer st = new StringTokenizer(headerAuthorization);
                 final String method = st.nextToken();
-                if (method == null || !method.equalsIgnoreCase(HttpServletRequest.BASIC_AUTH)) {
+                if (method == null || !HttpServletRequest.BASIC_AUTH.equalsIgnoreCase(method)) {
                     throw ResourceException.getException(401);
                 }
                 final String b64Credentials = st.nextToken();
@@ -450,11 +450,11 @@
     private AuthenticationMethod parseAuthenticationMethod(final JsonValue configuration) {
         if (configuration.isDefined("method")) {
             final String method = configuration.get("method").asString();
-            if (method.equalsIgnoreCase("simple")) {
+            if ("simple".equalsIgnoreCase(method)) {
                 return AuthenticationMethod.SIMPLE;
-            } else if (method.equalsIgnoreCase("sasl-plain")) {
+            } else if ("sasl-plain".equalsIgnoreCase(method)) {
                 return AuthenticationMethod.SASL_PLAIN;
-            } else if (method.equalsIgnoreCase("search-simple")) {
+            } else if ("search-simple".equalsIgnoreCase(method)) {
                 return AuthenticationMethod.SEARCH_SIMPLE;
             } else {
                 throw new JsonValueException(configuration,
@@ -469,9 +469,9 @@
     private SearchScope parseSearchScope(final JsonValue configuration) {
         if (configuration.isDefined("searchScope")) {
             final String scope = configuration.get("searchScope").asString();
-            if (scope.equalsIgnoreCase("sub")) {
+            if ("sub".equalsIgnoreCase(scope)) {
                 return SearchScope.WHOLE_SUBTREE;
-            } else if (scope.equalsIgnoreCase("one")) {
+            } else if ("one".equalsIgnoreCase(scope)) {
                 return SearchScope.SINGLE_LEVEL;
             } else {
                 throw new JsonValueException(configuration,

--
Gitblit v1.10.0