commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r165710 - /jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
Date Mon, 02 May 2005 22:55:31 GMT
Author: ggregory
Date: Mon May  2 15:55:31 2005
New Revision: 165710

URL: http://svn.apache.org/viewcvs?rev=165710&view=rev
Log:
A good start for: [Bug 34715][lang] unit test for org.apache.commons.lang.text.StrBuilder.
From heuermh@acm.org.

Added:
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
  (with props)

Added: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java?rev=165710&view=auto
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
(added)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
Mon May  2 15:55:31 2005
@@ -0,0 +1,919 @@
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ * 
+ * Licensed 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.commons.lang.text;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Unit tests for {@link org.apache.commons.lang.text.StrBuilder}.
+ * 
+ * @author Michael Heuer
+ * @version $Id$
+ */
+public class StrBuilderTest extends TestCase {
+
+    private static Object FOO = new Object() {
+        public String toString() {
+            return "foo";
+        }
+    };
+
+    /**
+     * Main.
+     * 
+     * @param args
+     *            command line arguments, ignored
+     */
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    /**
+     * Return a new test suite containing this test case.
+     * 
+     * @return a new test suite containing this test case
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite(StrBuilderTest.class);
+        suite.setName("StrBuilder Tests");
+        return suite;
+    }
+
+    /**
+     * Create a new test case with the specified name.
+     * 
+     * @param name
+     *            name
+     */
+    public StrBuilderTest(String name) {
+        super(name);
+    }
+
+    public void testAppend() {
+
+        StrBuilder sb = new StrBuilder();
+        assertEquals("", sb.toString());
+
+        sb.appendNull();
+        assertEquals("", sb.toString());
+
+        sb.append((Object) null);
+        assertEquals("", sb.toString());
+
+        sb.append(FOO);
+        assertEquals("foo", sb.toString());
+
+        sb.append((String) null);
+        assertEquals("foo", sb.toString());
+
+        sb.append("");
+        assertEquals("foo", sb.toString());
+
+        sb.append("bar");
+        assertEquals("foobar", sb.toString());
+
+        sb.append((StringBuffer) null);
+        assertEquals("foobar", sb.toString());
+
+        sb.append(new StringBuffer("baz"));
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.append((char[]) null);
+        assertEquals("", sb.toString());
+
+        sb.append(new char[0]);
+        assertEquals("", sb.toString());
+
+        sb.append(new char[]{'f', 'o', 'o'});
+        assertEquals("foo", sb.toString());
+
+        sb.append((char[]) null, 0, 1);
+        assertEquals("foo", sb.toString());
+
+        try {
+            sb.append(new char[]{'b', 'a', 'r'}, -1, 1);
+            fail("append(char[], -1,) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.append(new char[]{'b', 'a', 'r'}, 3, 1);
+            fail("append(char[], 3,) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.append(new char[]{'b', 'a', 'r'}, 1, -1);
+            fail("append(char[],, -1) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.append(new char[]{'b', 'a', 'r'}, 1, 3);
+            fail("append(char[], 1, 3) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        // These next two cases slip by the error condition checks but are silent modifications
+        sb.append(new char[]{'b', 'a', 'r'}, -1, 0);
+        assertEquals("foo", sb.toString());
+
+        sb.append(new char[]{'b', 'a', 'r'}, 3, 0);
+        assertEquals("foo", sb.toString());
+
+        sb.append(new char[]{'a', 'b', 'c', 'b', 'a', 'r', 'd', 'e', 'f'}, 3, 3);
+        assertEquals("foobar", sb.toString());
+
+        sb.append(true);
+        assertEquals("foobartrue", sb.toString());
+
+        sb.append(false);
+        assertEquals("foobartruefalse", sb.toString());
+
+        sb.append('!');
+        assertEquals("foobartruefalse!", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.append(0);
+        assertEquals("0", sb.toString());
+
+        sb.append(1L);
+        assertEquals("01", sb.toString());
+
+        sb.append(2.3F);
+        assertEquals("012.3", sb.toString());
+
+        sb.append(4.5D);
+        assertEquals("012.34.5", sb.toString());
+    }
+
+    public void testAppendFixedLength() {
+
+        StrBuilder sb = new StrBuilder();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", -1, '-');
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 0, '-');
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 1, '-');
+        assertEquals("o", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 2, '-');
+        assertEquals("oo", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 3, '-');
+        assertEquals("foo", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 4, '-');
+        assertEquals("-foo", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadLeft("foo", 10, '-');
+        assertEquals(10, sb.length());
+        // 1234567890
+        assertEquals("-------foo", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadRight("foo", -1, '-');
+        assertEquals("", sb.toString());
+
+        sb.appendFixedLengthPadRight("foo", 0, '-');
+        assertEquals("", sb.toString());
+
+        /*
+         * 
+         * TODO: appears the implementation for appendFixedLengthPadRight is broken?
+         * 
+         * sb.appendFixedLengthPadRight("foo", 1, '-'); assertEquals("f", sb.toString());
+         * 
+         * sb.clear(); assertEquals("", sb.toString());
+         * 
+         * sb.appendFixedLengthPadRight("foo", 2, '-'); assertEquals("fo", sb.toString());
+         * 
+         * sb.clear(); assertEquals("", sb.toString());
+         * 
+         * sb.appendFixedLengthPadRight("foo", 3, '-'); assertEquals("foo", sb.toString());
+         * 
+         * sb.clear(); assertEquals("", sb.toString());
+         * 
+         * sb.appendFixedLengthPadRight("foo", 4, '-'); assertEquals("foo-", sb.toString());
+         * 
+         * sb.clear(); assertEquals("", sb.toString());
+         * 
+         * sb.appendFixedLengthPadRight("foo", 10, '-'); assertEquals(10, sb.length()); //
1234567890
+         * assertEquals("foo-------", sb.toString());
+         * 
+         */
+    }
+
+    public void testAppendPadding() {
+
+        StrBuilder sb = new StrBuilder();
+        sb.append("foo");
+        assertEquals("foo", sb.toString());
+
+        sb.appendPadding(-1, '-');
+        assertEquals("foo", sb.toString());
+
+        sb.appendPadding(0, '-');
+        assertEquals("foo", sb.toString());
+
+        sb.appendPadding(1, '-');
+        assertEquals("foo-", sb.toString());
+
+        sb.appendPadding(16, '-');
+        assertEquals(20, sb.length());
+        // 12345678901234567890
+        assertEquals("foo-----------------", sb.toString());
+    }
+
+    public void testAppendWithNullText() {
+
+        StrBuilder sb = new StrBuilder();
+        sb.setNullText("null");
+        assertEquals("", sb.toString());
+
+        sb.appendNull();
+        assertEquals("null", sb.toString());
+
+        sb.append((Object) null);
+        assertEquals("nullnull", sb.toString());
+
+        sb.append(FOO);
+        assertEquals("nullnullfoo", sb.toString());
+
+        sb.append((String) null);
+        assertEquals("nullnullfoonull", sb.toString());
+
+        sb.append("");
+        assertEquals("nullnullfoonull", sb.toString());
+
+        sb.append("bar");
+        assertEquals("nullnullfoonullbar", sb.toString());
+
+        sb.append((StringBuffer) null);
+        assertEquals("nullnullfoonullbarnull", sb.toString());
+
+        sb.append(new StringBuffer("baz"));
+        assertEquals("nullnullfoonullbarnullbaz", sb.toString());
+    }
+
+    public void testAppendWithSeparators() {
+
+        StrBuilder sb = new StrBuilder();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators((Object[]) null, ",");
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(new Object[0], ",");
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(new Object[]{"foo", "bar", "baz"}, ",");
+        assertEquals("foo,bar,baz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(new Object[]{"foo", "bar", "baz"}, null);
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(new Object[]{"foo", null, "baz"}, ",");
+        assertEquals("foo,,baz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators((Collection) null, ",");
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(Collections.EMPTY_LIST, ",");
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(Arrays.asList(new Object[]{"foo", "bar", "baz"}), ",");
+        assertEquals("foo,bar,baz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(Arrays.asList(new Object[]{"foo", "bar", "baz"}), null);
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(Arrays.asList(new Object[]{"foo", null, "baz"}), ",");
+        assertEquals("foo,,baz", sb.toString());
+    }
+
+    public void testAppendWithSeparatorsWithNullText() {
+
+        StrBuilder sb = new StrBuilder();
+        sb.setNullText("null");
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(new Object[]{"foo", null, "baz"}, ",");
+        assertEquals("foo,null,baz", sb.toString());
+
+        sb.clear();
+        assertEquals("", sb.toString());
+
+        sb.appendWithSeparators(Arrays.asList(new Object[]{"foo", null, "baz"}), ",");
+        assertEquals("foo,null,baz", sb.toString());
+    }
+
+    public void testCapacityAndLength() {
+
+        StrBuilder sb = new StrBuilder();
+        assertEquals(32, sb.capacity());
+        assertEquals(0, sb.length());
+        assertEquals(0, sb.size());
+        assertTrue(sb.isEmpty());
+
+        sb.minimizeCapacity();
+        assertEquals(0, sb.capacity());
+        assertEquals(0, sb.length());
+        assertEquals(0, sb.size());
+        assertTrue(sb.isEmpty());
+
+        sb.ensureCapacity(32);
+        assertTrue(sb.capacity() >= 32);
+        assertEquals(0, sb.length());
+        assertEquals(0, sb.size());
+        assertTrue(sb.isEmpty());
+
+        sb.append("foo");
+        assertTrue(sb.capacity() >= 32);
+        assertEquals(3, sb.length());
+        assertEquals(3, sb.size());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.clear();
+        assertTrue(sb.capacity() >= 32);
+        assertEquals(0, sb.length());
+        assertEquals(0, sb.size());
+        assertTrue(sb.isEmpty());
+
+        sb.append("123456789012345678901234567890123");
+        assertTrue(sb.capacity() > 32);
+        assertEquals(33, sb.length());
+        assertEquals(33, sb.size());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.ensureCapacity(16);
+        assertTrue(sb.capacity() > 16);
+        assertEquals(33, sb.length());
+        assertEquals(33, sb.size());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.minimizeCapacity();
+        assertEquals(33, sb.capacity());
+        assertEquals(33, sb.length());
+        assertEquals(33, sb.size());
+        assertTrue(sb.isEmpty() == false);
+
+        try {
+            sb.setLength(-1);
+            fail("setLength(-1) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.setLength(33);
+        assertEquals(33, sb.capacity());
+        assertEquals(33, sb.length());
+        assertEquals(33, sb.size());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.setLength(16);
+        assertTrue(sb.capacity() >= 16);
+        assertEquals(16, sb.length());
+        assertEquals(16, sb.size());
+        assertEquals("1234567890123456", sb.toString());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.setLength(32);
+        assertTrue(sb.capacity() >= 32);
+        assertEquals(32, sb.length());
+        assertEquals(32, sb.size());
+        assertEquals("1234567890123456\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sb.toString());
+        assertTrue(sb.isEmpty() == false);
+
+        sb.setLength(0);
+        assertTrue(sb.capacity() >= 32);
+        assertEquals(0, sb.length());
+        assertEquals(0, sb.size());
+        assertTrue(sb.isEmpty());
+    }
+
+    public void testCharArray() {
+        // TODO
+    }
+
+    public void testConstructor() {
+
+        StrBuilder sb0 = new StrBuilder();
+        assertTrue(sb0.isEmpty());
+        StrBuilder sb1 = new StrBuilder(32);
+        assertTrue(sb1.isEmpty());
+        StrBuilder sb2 = new StrBuilder(0);
+        assertTrue(sb2.isEmpty());
+        StrBuilder sb3 = new StrBuilder(-1);
+        assertTrue(sb3.isEmpty());
+        StrBuilder sb4 = new StrBuilder(1);
+        assertTrue(sb4.isEmpty());
+        StrBuilder sb5 = new StrBuilder((String) null);
+        assertTrue(sb5.isEmpty());
+        StrBuilder sb6 = new StrBuilder("");
+        assertTrue(sb6.isEmpty());
+        StrBuilder sb7 = new StrBuilder("foo");
+        assertFalse(sb7.isEmpty());
+    }
+
+    public void testGetSetChar() {
+
+        StrBuilder sb = new StrBuilder();
+
+        try {
+            sb.charAt(0);
+            fail("charAt(0) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.charAt(-1);
+            fail("charAt(-1) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.setCharAt(0, 'f');
+            fail("setCharAt(0,) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.setCharAt(-1, 'f');
+            fail("setCharAt(-1,) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.append("foo");
+        assertEquals('f', sb.charAt(0));
+        assertEquals('o', sb.charAt(1));
+        assertEquals('o', sb.charAt(2));
+
+        try {
+            sb.charAt(3);
+            fail("charAt(3) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.setCharAt(0, 'b');
+        sb.setCharAt(1, 'a');
+        sb.setCharAt(2, 'r');
+
+        try {
+            sb.setCharAt(3, '!');
+            fail("setCharAt(3,) expected IndexOutOfBoundsException");
+        } catch (IndexOutOfBoundsException e) {
+            // expected
+        }
+
+        assertEquals('b', sb.charAt(0));
+        assertEquals('a', sb.charAt(1));
+        assertEquals('r', sb.charAt(2));
+    }
+
+    public void testInitialCapacityAndLength() {
+
+        StrBuilder sb0 = new StrBuilder();
+        assertEquals(32, sb0.capacity());
+        assertEquals(0, sb0.length());
+        assertEquals(0, sb0.size());
+
+        StrBuilder sb1 = new StrBuilder(32);
+        assertEquals(32, sb1.capacity());
+        assertEquals(0, sb1.length());
+        assertEquals(0, sb1.size());
+
+        StrBuilder sb2 = new StrBuilder(0);
+        assertEquals(32, sb2.capacity());
+        assertEquals(0, sb2.length());
+        assertEquals(0, sb2.size());
+
+        StrBuilder sb3 = new StrBuilder(-1);
+        assertEquals(32, sb3.capacity());
+        assertEquals(0, sb3.length());
+        assertEquals(0, sb3.size());
+
+        StrBuilder sb4 = new StrBuilder(1);
+        assertEquals(1, sb4.capacity());
+        assertEquals(0, sb4.length());
+        assertEquals(0, sb4.size());
+
+        StrBuilder sb5 = new StrBuilder((String) null);
+        assertEquals(32, sb5.capacity());
+        assertEquals(0, sb5.length());
+        assertEquals(0, sb5.size());
+
+        StrBuilder sb6 = new StrBuilder("");
+        assertEquals(32, sb6.capacity());
+        assertEquals(0, sb6.length());
+        assertEquals(0, sb6.size());
+
+        StrBuilder sb7 = new StrBuilder("foo");
+        assertEquals(35, sb7.capacity());
+        assertEquals(3, sb7.length());
+        assertEquals(3, sb7.size());
+    }
+
+    public void testInsert() {
+
+        StrBuilder sb = new StrBuilder();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, FOO);
+            fail("insert(-1, Object) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, FOO);
+            fail("insert(7, Object) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (Object) null);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, FOO);
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, "foo");
+            fail("insert(-1, String) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, "foo");
+            fail("insert(7, String) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (String) null);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, "foo");
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, new char[]{'f', 'o', 'o'});
+            fail("insert(-1, char[]) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, new char[]{'f', 'o', 'o'});
+            fail("insert(7, char[]) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (char[]) null);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, new char[0]);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, new char[]{'f', 'o', 'o'});
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3);
+            fail("insert(-1, char[], 3, 3) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3);
+            fail("insert(7, char[], 3, 3) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (char[]) null, 0, 0);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, new char[0], 0, 0);
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, -1, 3);
+            fail("insert(0, char[], -1, 3) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 10, 3);
+            fail("insert(0, char[], 10, 3) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, -1);
+            fail("insert(0, char[], 0, -1) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 10);
+            fail("insert(0, char[], 0, 10) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 0, 0);
+        assertEquals("barbaz", sb.toString());
+
+        sb.insert(0, new char[]{'a', 'b', 'c', 'f', 'o', 'o', 'd', 'e', 'f'}, 3, 3);
+        assertEquals("foobarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, true);
+            fail("insert(-1, boolean) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, true);
+            fail("insert(7, boolean) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, true);
+        assertEquals("truebarbaz", sb.toString());
+
+        sb.insert(0, false);
+        assertEquals("falsetruebarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, '!');
+            fail("insert(-1, char) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, '!');
+            fail("insert(7, char) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, '!');
+        assertEquals("!barbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, 0);
+            fail("insert(-1, int) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, 0);
+            fail("insert(7, int) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, '0');
+        assertEquals("0barbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, 1L);
+            fail("insert(-1, long) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, 1L);
+            fail("insert(7, long) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, 1L);
+        assertEquals("1barbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, 2.3F);
+            fail("insert(-1, float) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, 2.3F);
+            fail("insert(7, float) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, 2.3F);
+        assertEquals("2.3barbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, 4.5D);
+            fail("insert(-1, double) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, 4.5D);
+            fail("insert(7, double) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, 4.5D);
+        assertEquals("4.5barbaz", sb.toString());
+    }
+
+    public void testInsertWithNullText() {
+
+        StrBuilder sb = new StrBuilder();
+        sb.setNullText("null");
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, FOO);
+            fail("insert(-1, Object) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, FOO);
+            fail("insert(7, Object) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (Object) null);
+        assertEquals("nullbarbaz", sb.toString());
+
+        sb.insert(0, FOO);
+        assertEquals("foonullbarbaz", sb.toString());
+
+        sb.clear();
+        sb.append("barbaz");
+        assertEquals("barbaz", sb.toString());
+
+        try {
+            sb.insert(-1, "foo");
+            fail("insert(-1, String) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            sb.insert(7, "foo");
+            fail("insert(7, String) expected StringIndexOutOfBoundsException");
+        } catch (StringIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        sb.insert(0, (String) null);
+        assertEquals("nullbarbaz", sb.toString());
+
+        sb.insert(0, "foo");
+        assertEquals("foonullbarbaz", sb.toString());
+    }
+
+    public void testNullText() {
+
+        StrBuilder sb = new StrBuilder();
+        assertEquals(null, sb.getNullText());
+
+        sb.setNullText("null");
+        assertEquals("null", sb.getNullText());
+
+        sb.setNullText("");
+        assertEquals(null, sb.getNullText());
+
+        sb.setNullText("foo");
+        assertEquals("foo", sb.getNullText());
+
+        sb.setNullText((String) null);
+        assertEquals(null, sb.getNullText());
+    }
+}

Propchange: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Mon May  2 15:55:31 2005
@@ -0,0 +1 @@
+LastChangedDate Date LastChangedRevision Revision Rev LastChangedBy Author HeadURL URL Id

Propchange: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



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


Mime
View raw message