You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lg...@apache.org on 2015/10/23 19:56:15 UTC

[2/4] [lang] LANG-1171 Exclude methods from StringUtilsTest.testStringUtilsCharSequenceContract() : - StringUtils.compare(String str1, String str2); - StringUtils.compare(String str1, String str2, boolean nullIsLess); - StringUtils.compareIgnoreCas

LANG-1171 Exclude methods from StringUtilsTest.testStringUtilsCharSequenceContract() :
  - StringUtils.compare(String str1, String str2);
  - StringUtils.compare(String str1, String str2, boolean nullIsLess);
  - StringUtils.compareIgnoreCase(String str1, String str2);
  - StringUtils.compareIgnoreCase(String str1, String str2, boolean nullIsLess);


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/131917a0
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/131917a0
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/131917a0

Branch: refs/heads/master
Commit: 131917a0d3303ca2c38fd1d6765b9bed2c23ff89
Parents: 94ec5a1
Author: Loic Guibert <lg...@apache.org>
Authored: Tue Oct 20 18:50:13 2015 +0400
Committer: Loic Guibert <lg...@apache.org>
Committed: Tue Oct 20 18:50:13 2015 +0400

----------------------------------------------------------------------
 .../apache/commons/lang3/StringUtilsTest.java   | 21 ++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/131917a0/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index 5cc665a..a57a7f5 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -2373,22 +2373,39 @@ public class StringUtilsTest {
     @Test
     public void testStringUtilsCharSequenceContract() {
         final Class<StringUtils> c = StringUtils.class;
+        // Methods that are expressly excluded from testStringUtilsCharSequenceContract()
+        final String[] excludeMethods = {
+            "public static int org.apache.commons.lang3.StringUtils.compare(java.lang.String,java.lang.String)",
+            "public static int org.apache.commons.lang3.StringUtils.compare(java.lang.String,java.lang.String,boolean)",
+            "public static int org.apache.commons.lang3.StringUtils.compareIgnoreCase(java.lang.String,java.lang.String)",
+            "public static int org.apache.commons.lang3.StringUtils.compareIgnoreCase(java.lang.String,java.lang.String,boolean)"
+        };
         final Method[] methods = c.getMethods();
+
         for (final Method m : methods) {
+            String methodStr = m.toString();
             if (m.getReturnType() == String.class || m.getReturnType() == String[].class) {
                 // Assume this is mutable and ensure the first parameter is not CharSequence.
                 // It may be String or it may be something else (String[], Object, Object[]) so 
                 // don't actively test for that.
                 final Class<?>[] params = m.getParameterTypes();
                 if (params.length > 0 && (params[0] == CharSequence.class || params[0] == CharSequence[].class)) {
-                    fail("The method " + m + " appears to be mutable in spirit and therefore must not accept a CharSequence");
+                    if (ArrayUtils.contains(excludeMethods, methodStr)) {
+                        System.out.println("The mutable method \"" + methodStr + "\" is expressly excluded from testStringUtilsCharSequenceContract()");
+                    } else {
+                        fail("The method \"" + methodStr + "\" appears to be mutable in spirit and therefore must not accept a CharSequence");
+                    }
                 }
             } else {
                 // Assume this is immutable in spirit and ensure the first parameter is not String.
                 // As above, it may be something other than CharSequence.
                 final Class<?>[] params = m.getParameterTypes();
                 if (params.length > 0 && (params[0] == String.class || params[0] == String[].class)) {
-                    fail("The method " + m + " appears to be immutable in spirit and therefore must not accept a String");
+                    if (ArrayUtils.contains(excludeMethods, methodStr)) {
+                        System.out.println("The immutable method \"" + methodStr + "\" is expressly excluded from testStringUtilsCharSequenceContract()");
+                    } else {
+                        fail("The method \"" + methodStr + "\" appears to be immutable in spirit and therefore must not accept a String");
+                    }
                 }
             }
         }