Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 15563 invoked from network); 7 Apr 2011 05:22:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Apr 2011 05:22:29 -0000 Received: (qmail 58455 invoked by uid 500); 7 Apr 2011 05:22:29 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 58392 invoked by uid 500); 7 Apr 2011 05:22:27 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 58378 invoked by uid 99); 7 Apr 2011 05:22:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2011 05:22:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 07 Apr 2011 05:22:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C8AE523889E0; Thu, 7 Apr 2011 05:22:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1089742 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java Date: Thu, 07 Apr 2011 05:22:01 -0000 To: commits@commons.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110407052201.C8AE523889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Thu Apr 7 05:22:01 2011 New Revision: 1089742 URL: http://svn.apache.org/viewvc?rev=1089742&view=rev Log: Adding a test to enforce the CharSequence vs String contract for StringUtils. LANG-687 Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=1089742&r1=1089741&r2=1089742&view=diff ============================================================================== --- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java (original) +++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java Thu Apr 7 05:22:01 2011 @@ -17,6 +17,7 @@ package org.apache.commons.lang3; import java.lang.reflect.Constructor; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.nio.CharBuffer; import java.util.Arrays; @@ -1887,4 +1888,32 @@ public class StringUtilsTest extends Tes assertEquals("12",StringUtils.stripEnd("120.00", ".0")); assertEquals("121",StringUtils.stripEnd("121.00", ".0")); } + + // Methods on StringUtils that are immutable in spirit (i.e. calculate the length) + // should take a CharSequence parameter. Methods that are mutable in spirit (i.e. capitalize) + // should take a String or String[] parameter and return String or String[]. + // This test enforces that this is done. + public void testStringUtilsCharSequenceContract() { + Class c = StringUtils.class; + Method[] methods = c.getMethods(); + for (int i=0; i 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"); + } + } else { + // Assume this is immutable in spirit and ensure the first parameter is not String. + // As above, it may be something other than CharSequence. + 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"); + } + } + } + } }