commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject cvs commit: jakarta-commons-sandbox/util/src/test/org/apache/commons/util StringUtilsTest.java
Date Sun, 13 Jan 2002 21:52:57 GMT
bayard      02/01/13 13:52:57

  Modified:    util/src/test/org/apache/commons/util StringUtilsTest.java
  Log:
  Pushed Bernard's rewritten test-case in, though I kept the japanese
  unicode testing line commented out at the moment.
  Submitted by:	Bernard D'Have <bdhaveos@wanadoo.be>
  
  Revision  Changes    Path
  1.12      +244 -194  jakarta-commons-sandbox/util/src/test/org/apache/commons/util/StringUtilsTest.java
  
  Index: StringUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/util/src/test/org/apache/commons/util/StringUtilsTest.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- StringUtilsTest.java	29 Dec 2001 00:59:01 -0000	1.11
  +++ StringUtilsTest.java	13 Jan 2002 21:52:57 -0000	1.12
  @@ -1,194 +1,244 @@
  -package org.apache.commons.util;
  -
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Turbine" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Turbine", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -import java.util.Arrays;
  -
  -import junit.framework.Test;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
  -
  -/**
  - * Unit tests {@link org.apache.commons.util.StringUtils}.
  - *
  - * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  - * @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
  - */
  -public class StringUtilsTest extends TestCase
  -{
  -    private static final String[] ARRAY_LIST = { "foo", "bar", "baz" };
  -
  -    private static final String SEPARATOR = ",";
  -
  -    private static final String TEXT_LIST = "foo,bar,baz";
  -
  -    private static final String FOO = "foo";
  -    private static final String CAP_FOO = "Foo";
  -    private static final String UPPER_FOO = "FOO";
  -
  -    private static final String SENTENCE = "foo bar baz";
  -
  -    public StringUtilsTest(String name)
  -    {
  -        super(name);
  -    }
  -
  -    public static Test suite()
  -    {
  -        TestSuite suite = new TestSuite();
  -        suite.addTest(new StringUtilsTest("StringUtilsTest"));
  -        return suite;
  -    }
  -
  -    protected void runTest()
  -        throws Throwable
  -    {
  -        assertEquals("clean(String) failed",
  -                     FOO, StringUtils.clean(FOO + " "));
  -        assertEquals("clean(String) failed", "", StringUtils.clean(null));
  -
  -        assertEquals("trim(String) failed", FOO, StringUtils.trim(FOO + " "));
  -        assert("trim(String) failed", StringUtils.trim(null) == null);
  -
  -        assert("isValid(String) failed",
  -               StringUtils.isValid(FOO) && !StringUtils.isValid(""));
  -
  -        assert("isEmpty(String) failed",
  -               StringUtils.isEmpty("   ") && !StringUtils.isEmpty(FOO));
  -
  -        assert("equals(String, String) failed",
  -               StringUtils.equals(null, null) &&
  -               !StringUtils.equals(null, FOO) &&
  -               StringUtils.equals(FOO, FOO));
  -
  -        assertEquals("firstLetterCaps(String) failed",
  -                     "Foo", StringUtils.firstLetterCaps(FOO));
  -
  -        assertEquals("join(Object[], String) failed", TEXT_LIST,
  -                     StringUtils.join(ARRAY_LIST, SEPARATOR));
  -        assertEquals("join(Iterator, String) failed", TEXT_LIST,
  -                     StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(),
  -                                      SEPARATOR));
  -
  -        String[] result = StringUtils.split(TEXT_LIST, SEPARATOR, 2);
  -        String[] expected = { "foo", "bar,baz" };
  -        assertEquals("split(Object[], String, int) yielded unexpected length",
  -                     expected.length, result.length);
  -        for (int i = 0; i < result.length; i++)
  -        {
  -            assertEquals("split(Object[], String, int) failed", expected[i],
  -                         result[i]);
  -        }
  -
  -        assertEquals("replace(String, String, String, int) failed",
  -                     FOO, StringUtils.replace("oo" + FOO, "o", "", 2));
  -        // removed the 4th argument of -1.
  -        assertEquals("replace(String, String, String) failed",
  -                     "", StringUtils.replace(FOO + FOO + FOO, FOO, ""));
  -        assertEquals("replaceOnce(String, String, String) failed",
  -                     FOO, StringUtils.replaceOnce(FOO + FOO, FOO, ""));
  -
  -        // bayard's tests
  -        assertEquals("capitalise(String) failed",
  -                     CAP_FOO, StringUtils.capitalise(FOO) );
  -        assertEquals("capitaliseAllWords(String) failed",
  -                     "Foo Bar Baz", StringUtils.capitaliseAllWords(SENTENCE) );
  -        assertEquals("uncapitalise(String) failed",
  -                     FOO, StringUtils.uncapitalise(CAP_FOO) );
  -
  -        assertEquals("overlayString(String, String, int, int) failed",
  -                     "foo foor baz", StringUtils.overlayString(SENTENCE, FOO, 4, 6) );
  -
  -        assertEquals("repeat(String, int) failed",
  -                     FOO + FOO + FOO, StringUtils.repeat(FOO, 3) );
  -
  -        assertEquals("center(String, int) failed",
  -                     "   "+FOO+"   ", StringUtils.center(FOO, 9) );
  -
  -        assertEquals("chomp(String) failed",
  -                     FOO, StringUtils.chomp(FOO + "\n" + FOO) );
  -
  -        assertEquals("chompLast(String) failed",
  -                     FOO, StringUtils.chompLast(FOO + "\n") );
  -
  -        assertEquals("getChomp(String, String) failed",
  -                     "\n" + FOO, StringUtils.getChomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("prechomp(String, String) failed",
  -                     FOO, StringUtils.prechomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("getPrechomp(String, String) failed",
  -                     FOO + "\n", StringUtils.getPrechomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("chop(String, String) failed",
  -                     FOO, StringUtils.chop(FOO + "\r\n") );
  -
  -        assertEquals("chopNewline(String, String) failed",
  -                     FOO, StringUtils.chopNewline(FOO + "\r\n") );
  -
  -        // next, StringUtils.count
  -
  -
  -        /* TODO: Make into a JUnit assertion.
  -        String input = "これは日本楔譴離謄好箸任后#";
  -        String unicode =
  -            StringUtils.convertNativeToUnicode(input, "iso-2022-jp");
  -        String iso = StringUtils.convertUnicodeToNative(unicode, "iso-2022-jp");
  -        System.err.println(input);
  -        System.err.println(unicode);
  -        System.err.println(iso);
  -        */
  -    }
  -}
  +package org.apache.commons.util;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Turbine" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache Turbine", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import java.util.Arrays;
  +
  +import junit.framework.Test;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +
  +/**
  + * Unit tests {@link org.apache.commons.util.StringUtils}.
  + *
  + * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  + * @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
  + */
  +public class StringUtilsTest extends TestCase
  +{
  +    private static final String[] ARRAY_LIST = { "foo", "bar", "baz" };
  +
  +    private static final String SEPARATOR = ",";
  +
  +    private static final String TEXT_LIST = "foo,bar,baz";
  +
  +    private static final String FOO = "foo";
  +    private static final String CAP_FOO = "Foo";
  +    private static final String UPPER_FOO = "FOO";
  +
  +    private static final String SENTENCE = "foo bar baz";
  +
  +    public StringUtilsTest(String name)
  +    {
  +        super(name);
  +    }
  +
  +    public void testClean()
  +    {
  +        assertEquals("clean(String) failed",
  +                     FOO, StringUtils.clean(FOO + " "));
  +        assertEquals("clean(String) failed", "", StringUtils.clean(null));
  +    }
  +
  +    public void testTrim()
  +    {
  +        assertEquals("trim(String) failed", FOO, StringUtils.trim(FOO + " "));
  +        assertTrue("trim(String) failed", StringUtils.trim(null) == null);
  +    }
  +
  +    public void testIsValid()
  +    {
  +        assertTrue("isValid(String) failed",
  +                   StringUtils.isValid(FOO) && !StringUtils.isValid(""));
  +    }
  +
  +    public void testIsEmpty()
  +    {
  +        assertTrue("isEmpty(String) failed",
  +                   StringUtils.isEmpty("   ") && !StringUtils.isEmpty(FOO));
  +    }
  +
  +    public void testEquals()
  +    {
  +        assertTrue("equals(String, String) failed",
  +                   StringUtils.equals(null, null) &&
  +                   !StringUtils.equals(null, FOO) &&
  +                   StringUtils.equals(FOO, FOO));
  +    }
  +
  +    public void testCapitalizeFunctions()
  +    {
  +        assertEquals("firstLetterCaps(String) failed",
  +                     CAP_FOO, StringUtils.firstLetterCaps(FOO));
  +
  +        assertEquals("capitalise(String) failed",
  +                     CAP_FOO, StringUtils.capitalise(FOO) );
  +        assertEquals("capitaliseAllWords(String) failed",
  +                     "Foo Bar Baz", StringUtils.capitaliseAllWords(SENTENCE) );
  +        assertEquals("uncapitalise(String) failed",
  +                     FOO, StringUtils.uncapitalise(CAP_FOO) );
  +    }
  +
  +    public void testJoin()
  +    {
  +        assertEquals("join(Object[], String) failed", TEXT_LIST,
  +                     StringUtils.join(ARRAY_LIST, SEPARATOR));
  +        assertEquals("join(Iterator, String) failed", TEXT_LIST,
  +                     StringUtils.join(Arrays.asList(ARRAY_LIST).iterator(),
  +                                      SEPARATOR));
  +    }
  +
  +    public void testSplit()
  +    {
  +        String[] result = StringUtils.split(TEXT_LIST, SEPARATOR, 2);
  +        String[] expected = { "foo", "bar,baz" };
  +        assertEquals("split(Object[], String, int) yielded unexpected length",
  +                     expected.length, result.length);
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            assertEquals("split(Object[], String, int) failed", expected[i],
  +                         result[i]);
  +        }
  +    }
  +
  +    public void testReplaceFunctions()
  +    {
  +        assertEquals("replace(String, String, String, int) failed",
  +                     FOO, StringUtils.replace("oo" + FOO, "o", "", 2));
  +        // removed the 4th argument of -1.
  +        assertEquals("replace(String, String, String) failed",
  +                     "", StringUtils.replace(FOO + FOO + FOO, FOO, ""));
  +        assertEquals("replaceOnce(String, String, String) failed",
  +                     FOO, StringUtils.replaceOnce(FOO + FOO, FOO, ""));
  +    }
  +
  +    public void testOverlayString()
  +    {
  +        assertEquals("overlayString(String, String, int, int) failed",
  +                     "foo foor baz", StringUtils.overlayString(SENTENCE, FOO, 4, 6) );
  +    }
  +
  +    public void testRepeat()
  +    {
  +        assertEquals("repeat(String, int) failed",
  +                     FOO + FOO + FOO, StringUtils.repeat(FOO, 3) );
  +    }
  +
  +    public void testCenter()
  +    {
  +        assertEquals("center(String, int) failed",
  +                     "   "+FOO+"   ", StringUtils.center(FOO, 9) );
  +    }
  +
  +    public void testChompFunctions()
  +    {
  +
  +        assertEquals("chomp(String) failed",
  +                     FOO, StringUtils.chomp(FOO + "\n" + FOO) );
  +
  +        assertEquals("chompLast(String) failed",
  +                     FOO, StringUtils.chompLast(FOO + "\n") );
  +
  +        assertEquals("getChomp(String, String) failed",
  +                     "\n" + FOO, StringUtils.getChomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("prechomp(String, String) failed",
  +                     FOO, StringUtils.prechomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("getPrechomp(String, String) failed",
  +                     FOO + "\n", StringUtils.getPrechomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("chop(String, String) failed",
  +                     FOO, StringUtils.chop(FOO + "\r\n") );
  +
  +        assertEquals("chopNewline(String, String) failed",
  +                     FOO, StringUtils.chopNewline(FOO + "\r\n") );
  +    }
  +
  +    public void testPadFunctions()
  +    {
  +        assertEquals("rightPad(String, int) failed",
  +                     "1234    ", StringUtils.rightPad ("1234", 8) );
  +
  +        assertEquals("rightPad(String, int, String) failed",
  +                     "1234-+-+", StringUtils.rightPad ("1234", 8, "-+") );
  +
  +        assertEquals("rightPad(String, int, String) failed",
  +                     "123456-+~", StringUtils.rightPad ("123456", 9, "-+~") );
  +
  +        assertEquals("leftPad(String, int) failed",
  +                     "    1234", StringUtils.leftPad("1234", 8) );
  +
  +        assertEquals("leftPad(String, int, String) failed",
  +                     "-+-+1234", StringUtils.leftPad("1234", 8, "-+") );
  +
  +        assertEquals("leftPad(String, int, String) failed",
  +                     "-+~123456", StringUtils.leftPad("123456", 9, "-+~") );
  +    }
  +
  +    public void testUnicodeFunctions() throws java.io.IOException
  +    {
  +        /* this test fails on my window box with an Sun english JDK 1.3.1
  +           I think that the input string is not right
  +        */
  +/* Kept out for the moment.
  +        String input = "これは日本楔譴離謄好箸任后#";
  +        String unicode = StringUtils.convertNativeToUnicode(input, "iso-2022-jp");
  +        String iso = StringUtils.convertUnicodeToNative(unicode, "iso-2022-jp");
  +        assertEquals("Unicode conversions failed", input, iso);
  +*/
  +    }
  +}
  +
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message