harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r379882 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/lang/StringBuilder.java test/java/org/apache/harmony/tests/java/lang/AllTests.java test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
Date Wed, 22 Feb 2006 20:50:53 GMT
Author: tellison
Date: Wed Feb 22 12:50:50 2006
New Revision: 379882

URL: http://svn.apache.org/viewcvs?rev=379882&view=rev
Log:
Applied patch HARMONY-103 (java.lang.StringBuilder Implementation for LUNI)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java?rev=379882&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/lang/StringBuilder.java Wed Feb 22 12:50:50 2006
@@ -0,0 +1,651 @@
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * 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 java.lang;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+import org.apache.harmony.luni.util.NotYetImplementedException;
+
+/**
+ * TODO javadoc
+ */
+public final class StringBuilder implements CharSequence, Serializable {
+
+	// TODO add 'implements Appendable' (see HARMONY-103)
+
+	private static final long serialVersionUID = 4383685877147921099L;
+
+	private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
+	private static final String NULL_STRING = "null"; //$NON-NLS-1$
+
+	private static final char[] NULL_CHAR_ARRAY = NULL_STRING.toCharArray();
+
+	private static final int INITIAL_CAPACITY = 16;
+
+	private transient char[] buffer;
+
+	private transient int length;
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder() {
+		super();
+		this.buffer = new char[INITIAL_CAPACITY];
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder(int capacity) {
+		super();
+		if (capacity < 0)
+			throw new NegativeArraySizeException();
+		this.buffer = new char[capacity];
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder(CharSequence seq) {
+		super();
+		if (seq == null)
+			throw new NullPointerException();
+		this.length = seq.length();
+		this.buffer = new char[length + 16];
+		for (int i = 0; i < length; i++) {
+			this.buffer[i] = seq.charAt(i);
+		}
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder(String str) {
+		this((CharSequence) str);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(boolean b) {
+		return append(String.valueOf(b));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Appendable#append(char)
+	 */
+	public StringBuilder append(char c) {
+		return append(String.valueOf(c));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(char[] str) {
+		return append(String.valueOf(str));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(char[] str, int offset, int len) {
+		return append(String.valueOf(str, offset, len));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Appendable#append(java.lang.CharSequence)
+	 */
+	public StringBuilder append(CharSequence csq) {
+		return append((String) (csq == null ? null : csq.toString()));
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.Appendable#append(java.lang.CharSequence, int, int)
+	 */
+	public StringBuilder append(CharSequence csq, int start, int end) {
+		if (csq == null)
+			csq = NULL_STRING;
+		return append(csq.subSequence(start, end));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(double d) {
+		return append(String.valueOf(d));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(float f) {
+		return append(String.valueOf(f));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(int i) {
+		return append(String.valueOf(i));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(long lng) {
+		return append(String.valueOf(lng));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(Object obj) {
+		return append(String.valueOf(obj));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(String str) {
+		// if null or interned "null" string append "null"
+		if (str == null || str == NULL_STRING) {
+			ensureCapacity(length + 4);
+			System.arraycopy(NULL_CHAR_ARRAY, 0, buffer, length, 4);
+			length += 4;
+		} else {
+			int len = str.length();
+			ensureCapacity(length + len);
+			for (int i = 0; i < len; i++) {
+				buffer[length++] = str.charAt(i);
+			}
+		}
+		return this;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder append(StringBuffer sb) {
+		return append((CharSequence) sb);
+	}
+
+	/**
+	 * <p>
+	 * <b>NOTE - This method is currently not implemented and always throws a
+	 * {@link NotYetImplementedException}.</b>
+	 * </p>
+	 * TODO javadoc
+	 */
+	public StringBuilder appendCodePoint(int codePoint) {
+		// TODO Implement Java 5 code point functionality.
+		throw new NotYetImplementedException();
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int capacity() {
+		return buffer.length;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.CharSequence#charAt(int)
+	 */
+	public char charAt(int index) {
+		if (index < 0 || index >= length)
+			throw new IndexOutOfBoundsException();
+		return buffer[index];
+	}
+
+	/**
+	 * <p>
+	 * <b>NOTE - This method is currently NOT completely implemented and just
+	 * delegates to the {@link #charAt(int)} method.</b>
+	 * </p>
+	 * TODO javadoc
+	 */
+	public int codePointAt(int index) {
+		// TODO Implement Java 5 code point functionality.
+		return charAt(index);
+	}
+
+	/**
+	 * <p>
+	 * <b>NOTE - This method is currently NOT completely implemented and just
+	 * delegates to the {@link #charAt(int)} method by retrieving the character
+	 * at the preceding index.</b>
+	 * </p>
+	 * TODO javadoc
+	 */
+	public int codePointBefore(int index) {
+		// TODO Implement Java 5 code point functionality.
+		return codePointAt(index - 1);
+	}
+
+	/**
+	 * <p>
+	 * <b>NOTE - This method is currently NOT completely implemented and just
+	 * return the difference between the index parameters.</b>
+	 * </p>
+	 * TODO javadoc
+	 */
+	public int codePointCount(int beginIndex, int endIndex) {
+		// TODO Implement Java 5 code point functionality.
+		if (beginIndex < 0 || endIndex > length || beginIndex > endIndex)
+			throw new IndexOutOfBoundsException();
+		return endIndex - beginIndex;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder delete(int start, int end) {
+		if (start < 0 || start > length || start > end)
+			throw new StringIndexOutOfBoundsException();
+		if (start != end) {
+			// massage end if it's too long
+			if (end > length)
+				end = length;
+			// shift chars left
+			System.arraycopy(buffer, end, buffer, start, length - end);
+			// adjust length
+			length -= (end - start);
+		}
+		return this;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder deleteCharAt(int index) {
+		// check for index values past length, as 'delete' will massage them out
+		if (index >= length)
+			throw new StringIndexOutOfBoundsException();
+		return delete(index, index + 1);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public void ensureCapacity(int minimumCapacity) {
+		if (minimumCapacity > buffer.length) {
+			/*
+			 * Create a new buffer that's the greater of the requested capacity
+			 * or the current capacity multiplied by 2 plus 2.
+			 */
+			char[] newbuffer = new char[Math.max(minimumCapacity,
+					(buffer.length * 2) + 2)];
+			// copy the original buffer's contents
+			System.arraycopy(buffer, 0, newbuffer, 0, length);
+			// assign new buffer to instance field
+			buffer = newbuffer;
+		}
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
+		if (dst == null)
+			throw new NullPointerException();
+		if (srcBegin < 0 || dstBegin < 0 || srcBegin > srcEnd
+				|| srcEnd > length
+				|| (dstBegin + srcEnd - srcBegin) > dst.length)
+			throw new IndexOutOfBoundsException();
+
+		System.arraycopy(buffer, srcBegin, dst, dstBegin, srcEnd - srcBegin);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int indexOf(String str) {
+		if (str == null)
+			throw new NullPointerException();
+		// TODO optimize
+		return this.toString().indexOf(str);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int indexOf(String str, int fromIndex) {
+		if (str == null)
+			throw new NullPointerException();
+		// TODO optimize
+		return this.toString().indexOf(str, fromIndex);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, boolean b) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(b));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, char c) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(c));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, char[] str) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(str));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int index, char[] str, int offset, int len) {
+		if (index < 0 || index > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(index, String.valueOf(str, offset, len));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, CharSequence s) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, (s == null ? (String) null : s.toString()));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, CharSequence s, int start, int end) {
+		if (offset < 0 || offset > length)
+			throw new IndexOutOfBoundsException();
+
+		if (s == null)
+			s = NULL_STRING;
+
+		return insert(offset, s.subSequence(start, end));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, double d) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(d));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, float f) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(f));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, int i) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(i));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, long l) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(l));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, Object obj) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		return insert(offset, String.valueOf(obj));
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder insert(int offset, String str) {
+		if (offset < 0 || offset > length)
+			throw new StringIndexOutOfBoundsException();
+
+		if (str == null)
+			str = NULL_STRING;
+
+		int len = str.length();
+		ensureCapacity(length + len);
+		// shift chars right
+		System.arraycopy(buffer, offset, buffer, offset + len, length - offset);
+		// adjust length
+		length += len;
+		// copy in new chars
+		for (int i = 0, j = offset; i < len; i++, j++)
+			buffer[j] = str.charAt(i);
+		return this;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int lastIndexOf(String str) {
+		if (str == null)
+			throw new NullPointerException();
+		// TODO optimize
+		return this.toString().lastIndexOf(str);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int lastIndexOf(String str, int fromIndex) {
+		if (str == null)
+			throw new NullPointerException();
+		// TODO optimize
+		return this.toString().lastIndexOf(str, fromIndex);
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.CharSequence#length()
+	 */
+	public int length() {
+		return length;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public int offsetByCodePoints(int index, int codePointOffset) {
+		// TODO Implement Java 5 code point functionality.
+		throw new NotYetImplementedException();
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder replace(int start, int end, String str) {
+		if (start < 0 || start > length || start > end)
+			throw new StringIndexOutOfBoundsException();
+
+		if (str == null) // TODO verify this undocumented NPE
+			throw new NullPointerException();
+
+		// if the start is just past last char, then treat it like an append
+		if (start == length) {
+			return append(str);
+		}
+
+		int sbLen = end - start;
+		int strLen = str.length();
+		if (strLen > sbLen) {
+			// shift chars with an insert of the difference
+			// this will handle capacity and length management
+			insert(start, new char[strLen - sbLen]);
+		}
+		// copy in new chars
+		for (int i = 0, j = start; i < strLen; i++, j++)
+			buffer[j] = str.charAt(i);
+		return this;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public StringBuilder reverse() {
+		if (length > 1) { // only reverse if necessary
+			for (int i = 0, j = length - 1; i <= j - 1; i++, j--) {
+				char c = buffer[j];
+				buffer[j] = buffer[i];
+				buffer[i] = c;
+			}
+		}
+		return this;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public void setCharAt(int index, char ch) {
+		if (index < 0 || index >= length)
+			throw new IndexOutOfBoundsException();
+		buffer[index] = ch;
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public void setLength(int newLength) {
+		if (newLength < 0)
+			throw new IndexOutOfBoundsException();
+		if (newLength > length) {
+			// expand if necessary
+			ensureCapacity(newLength);
+			// null out any new chars at the sequence end
+			for (int i = length; i < newLength; i++)
+				buffer[i] = 0;
+		}
+		length = newLength;
+	}
+
+	/*
+	 * (non-Javadoc)
+	 * 
+	 * @see java.lang.CharSequence#subSequence(int, int)
+	 */
+	public CharSequence subSequence(int start, int end) {
+		return substring(start, end);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public String substring(int start) {
+		if (start < 0 || start > length)
+			throw new StringIndexOutOfBoundsException();
+
+		int ssCharCnt = length - start;
+		if (ssCharCnt == 0)
+			return EMPTY_STRING;
+		return new String(buffer, start, ssCharCnt);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public String substring(int start, int end) {
+		if (start < 0 || end > length || start > end)
+			throw new StringIndexOutOfBoundsException();
+
+		int ssCharCnt = end - start;
+		if (ssCharCnt == 0)
+			return EMPTY_STRING;
+		return new String(buffer, start, end - start);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public String toString() {
+		if (length == 0)
+			return EMPTY_STRING;
+		return new String(buffer, 0, length);
+	}
+
+	/**
+	 * TODO javadoc
+	 */
+	public void trimToSize() {
+		if (length < buffer.length) {
+			char[] newbuffer = new char[length];
+			System.arraycopy(buffer, 0, newbuffer, 0, length);
+			buffer = newbuffer;
+		}
+	}
+
+	private void readObject(ObjectInputStream in) throws IOException,
+			ClassNotFoundException {
+		in.defaultReadObject();
+		length = in.readInt();
+		buffer = (char[]) in.readObject();
+	}
+
+	private void writeObject(ObjectOutputStream out) throws IOException {
+		out.defaultWriteObject();
+		out.writeInt(length);
+		out.writeObject(buffer);
+	}
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java?rev=379882&r1=379881&r2=379882&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/AllTests.java Wed Feb 22 12:50:50 2006
@@ -32,6 +32,7 @@
 		suite.addTestSuite(StringBufferTest.class);
 		suite.addTestSuite(SecurityManagerTest.class);
 		suite.addTestSuite(DoubleTest.class);
+		suite.addTestSuite(StringBuilderTest.class);
 		//$JUnit-END$
 		return suite;
 	}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java?rev=379882&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/lang/StringBuilderTest.java Wed Feb 22 12:50:50 2006
@@ -0,0 +1,1611 @@
+/*
+ * Copyright 1998, 2006 The Apache Software Foundation or its licensors, as
+ * applicable
+ * 
+ * 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.harmony.tests.java.lang;
+
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+public class StringBuilderTest extends TestCase {
+
+	/*
+	 * @tests java.lang.StringBuilder.StringBuilder()
+	 */
+	public void test_Constructor() {
+		StringBuilder sb = new StringBuilder();
+		assertNotNull(sb);
+		assertEquals(16, sb.capacity());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.StringBuilder(int)
+	 */
+	public void test_ConstructorI() {
+		StringBuilder sb = new StringBuilder(24);
+		assertNotNull(sb);
+		assertEquals(24, sb.capacity());
+
+		try {
+			new StringBuilder(-1);
+			fail("no exception");
+		} catch (NegativeArraySizeException e) {
+			// Expected
+		}
+
+		assertNotNull(new StringBuilder(0));
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.StringBuilder(CharSequence)
+	 */
+	public void test_ConstructorLjava_lang_CharSequence() {
+		StringBuilder sb = new StringBuilder((CharSequence) "fixture");
+		assertEquals("fixture", sb.toString());
+		assertEquals("fixture".length() + 16, sb.capacity());
+
+		sb = new StringBuilder((CharSequence) new StringBuffer("fixture"));
+		assertEquals("fixture", sb.toString());
+		assertEquals("fixture".length() + 16, sb.capacity());
+
+		try {
+			new StringBuilder((CharSequence) null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.StringBuilder(String)
+	 */
+	public void test_ConstructorLjava_lang_String() {
+		StringBuilder sb = new StringBuilder("fixture");
+		assertEquals("fixture", sb.toString());
+		assertEquals("fixture".length() + 16, sb.capacity());
+
+		try {
+			new StringBuilder((String) null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(boolean)
+	 */
+	public void test_appendZ() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(true));
+		assertEquals("true", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(false));
+		assertEquals("false", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(char)
+	 */
+	public void test_appendC() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append('a'));
+		assertEquals("a", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append('b'));
+		assertEquals("b", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(char[])
+	 */
+	public void test_append$C() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(new char[] { 'a', 'b' }));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(new char[] { 'c', 'd' }));
+		assertEquals("cd", sb.toString());
+		try {
+			sb.append((char[]) null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(char[], int, int)
+	 */
+	public void test_append$CII() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(new char[] { 'a', 'b' }, 0, 2));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(new char[] { 'c', 'd' }, 0, 2));
+		assertEquals("cd", sb.toString());
+
+		sb.setLength(0);
+		assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, 2));
+		assertEquals("ab", sb.toString());
+
+		sb.setLength(0);
+		assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 2));
+		assertEquals("cd", sb.toString());
+
+		sb.setLength(0);
+		assertSame(sb, sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 0));
+		assertEquals("", sb.toString());
+
+		try {
+			sb.append((char[]) null, 0, 2);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		try {
+			sb.append(new char[] { 'a', 'b', 'c', 'd' }, -1, 2);
+			fail("no IOOBE, negative offset");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.append(new char[] { 'a', 'b', 'c', 'd' }, 0, -1);
+			fail("no IOOBE, negative length");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.append(new char[] { 'a', 'b', 'c', 'd' }, 2, 3);
+			fail("no IOOBE, offset and length overflow");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(CharSequence)
+	 */
+	public void test_appendLjava_lang_CharSequence() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append((CharSequence) "ab"));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) "cd"));
+		assertEquals("cd", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) null));
+		assertEquals("null", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(CharSequence, int, int)
+	 */
+	public void test_appendLjava_lang_CharSequenceII() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append((CharSequence) "ab", 0, 2));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) "cd", 0, 2));
+		assertEquals("cd", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) "abcd", 0, 2));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) "abcd", 2, 4));
+		assertEquals("cd", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((CharSequence) null, 0, 2));
+		assertEquals("nu", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(double)
+	 */
+	public void test_appendD() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(1D));
+		assertEquals(String.valueOf(1D), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(0D));
+		assertEquals(String.valueOf(0D), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(-1D));
+		assertEquals(String.valueOf(-1D), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Double.NaN));
+		assertEquals(String.valueOf(Double.NaN), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Double.NEGATIVE_INFINITY));
+		assertEquals(String.valueOf(Double.NEGATIVE_INFINITY), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Double.POSITIVE_INFINITY));
+		assertEquals(String.valueOf(Double.POSITIVE_INFINITY), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Double.MIN_VALUE));
+		assertEquals(String.valueOf(Double.MIN_VALUE), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Double.MAX_VALUE));
+		assertEquals(String.valueOf(Double.MAX_VALUE), sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(float)
+	 */
+	public void test_appendF() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(1F));
+		assertEquals(String.valueOf(1F), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(0F));
+		assertEquals(String.valueOf(0F), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(-1F));
+		assertEquals(String.valueOf(-1F), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Float.NaN));
+		assertEquals(String.valueOf(Float.NaN), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Float.NEGATIVE_INFINITY));
+		assertEquals(String.valueOf(Float.NEGATIVE_INFINITY), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Float.POSITIVE_INFINITY));
+		assertEquals(String.valueOf(Float.POSITIVE_INFINITY), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Float.MIN_VALUE));
+		assertEquals(String.valueOf(Float.MIN_VALUE), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Float.MAX_VALUE));
+		assertEquals(String.valueOf(Float.MAX_VALUE), sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(int)
+	 */
+	public void test_appendI() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(1));
+		assertEquals(String.valueOf(1), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(0));
+		assertEquals(String.valueOf(0), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(-1));
+		assertEquals(String.valueOf(-1), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Integer.MIN_VALUE));
+		assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Integer.MAX_VALUE));
+		assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(long)
+	 */
+	public void test_appendL() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(1L));
+		assertEquals(String.valueOf(1L), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(0L));
+		assertEquals(String.valueOf(0L), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(-1L));
+		assertEquals(String.valueOf(-1L), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Integer.MIN_VALUE));
+		assertEquals(String.valueOf(Integer.MIN_VALUE), sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(Integer.MAX_VALUE));
+		assertEquals(String.valueOf(Integer.MAX_VALUE), sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(Object)'
+	 */
+	public void test_appendLjava_lang_Object() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(Fixture.INSTANCE));
+		assertEquals(Fixture.INSTANCE.toString(), sb.toString());
+
+		sb.setLength(0);
+		assertSame(sb, sb.append((Object) null));
+		assertEquals("null", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(String)
+	 */
+	public void test_appendLjava_lang_String() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append("ab"));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append("cd"));
+		assertEquals("cd", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((String) null));
+		assertEquals("null", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.append(StringBuffer)
+	 */
+	public void test_appendLjava_lang_StringBuffer() {
+		StringBuilder sb = new StringBuilder();
+		assertSame(sb, sb.append(new StringBuffer("ab")));
+		assertEquals("ab", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append(new StringBuffer("cd")));
+		assertEquals("cd", sb.toString());
+		sb.setLength(0);
+		assertSame(sb, sb.append((StringBuffer) null));
+		assertEquals("null", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.appendCodePoint(int)'
+	 */
+	public void test_appendCodePointI() {
+		// TODO Implement Java 5 code point functionality.
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.capacity()'
+	 */
+	public void test_capacity() {
+		StringBuilder sb = new StringBuilder();
+		assertEquals(16, sb.capacity());
+		sb.append("0123456789ABCDEF0123456789ABCDEF");
+		assertTrue(sb.capacity() > 16);
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.charAt(int)'
+	 */
+	public void test_charAtI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		for (int i = 0; i < fixture.length(); i++) {
+			assertEquals((char) ('0' + i), sb.charAt(i));
+		}
+
+		try {
+			sb.charAt(-1);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.charAt(fixture.length());
+			fail("no IOOBE, equal to length");
+		} catch (IndexOutOfBoundsException e) {
+		}
+
+		try {
+			sb.charAt(fixture.length() + 1);
+			fail("no IOOBE, greater than length");
+		} catch (IndexOutOfBoundsException e) {
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.codePointAt(int)
+	 */
+	public void test_codePointAtI() {
+		// TODO Implement Java 5 code point functionality.
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.codePointBefore(int)
+	 */
+	public void test_codePointBeforeI() {
+		// TODO Implement Java 5 code point functionality.
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.codePointCount(int, int)
+	 */
+	public void test_codePointCountII() {
+		// TODO Implement Java 5 code point functionality.
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.delete(int, int)
+	 */
+	public void test_deleteII() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.delete(0, 0));
+		assertEquals(fixture, sb.toString());
+		assertSame(sb, sb.delete(5, 5));
+		assertEquals(fixture, sb.toString());
+		assertSame(sb, sb.delete(0, 1));
+		assertEquals("123456789", sb.toString());
+		assertEquals(9, sb.length());
+		assertSame(sb, sb.delete(0, sb.length()));
+		assertEquals("", sb.toString());
+		assertEquals(0, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.delete(0, 11));
+		assertEquals("", sb.toString());
+		assertEquals(0, sb.length());
+
+		try {
+			new StringBuilder(fixture).delete(-1, 2);
+			fail("no SIOOBE, negative start");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			new StringBuilder(fixture).delete(11, 12);
+			fail("no SIOOBE, start too far");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			new StringBuilder(fixture).delete(13, 12);
+			fail("no SIOOBE, start larger than end");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.deleteCharAt(int)
+	 */
+	public void test_deleteCharAtI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.deleteCharAt(0));
+		assertEquals("123456789", sb.toString());
+		assertEquals(9, sb.length());
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.deleteCharAt(5));
+		assertEquals("012346789", sb.toString());
+		assertEquals(9, sb.length());
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.deleteCharAt(9));
+		assertEquals("012345678", sb.toString());
+		assertEquals(9, sb.length());
+
+		try {
+			new StringBuilder(fixture).deleteCharAt(-1);
+			fail("no SIOOBE, negative index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			new StringBuilder(fixture).deleteCharAt(fixture.length());
+			fail("no SIOOBE, index equals length");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			new StringBuilder(fixture).deleteCharAt(fixture.length() + 1);
+			fail("no SIOOBE, index exceeds length");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.ensureCapacity(int)'
+	 */
+	public void test_ensureCapacityI() {
+		StringBuilder sb = new StringBuilder(5);
+		assertEquals(5, sb.capacity());
+		sb.ensureCapacity(10);
+		assertEquals(12, sb.capacity());
+		sb.ensureCapacity(26);
+		assertEquals(26, sb.capacity());
+		sb.ensureCapacity(55);
+		assertEquals(55, sb.capacity());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.getChars(int, int, char[], int)'
+	 */
+	public void test_getCharsII$CI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		char[] dst = new char[10];
+		sb.getChars(0, 10, dst, 0);
+		assertTrue(Arrays.equals(fixture.toCharArray(), dst));
+
+		Arrays.fill(dst, '\0');
+		sb.getChars(0, 5, dst, 0);
+		char[] fixtureChars = new char[10];
+		fixture.getChars(0, 5, fixtureChars, 0);
+		assertTrue(Arrays.equals(fixtureChars, dst));
+
+		Arrays.fill(dst, '\0');
+		Arrays.fill(fixtureChars, '\0');
+		sb.getChars(0, 5, dst, 5);
+		fixture.getChars(0, 5, fixtureChars, 5);
+		assertTrue(Arrays.equals(fixtureChars, dst));
+
+		Arrays.fill(dst, '\0');
+		Arrays.fill(fixtureChars, '\0');
+		sb.getChars(5, 10, dst, 1);
+		fixture.getChars(5, 10, fixtureChars, 1);
+		assertTrue(Arrays.equals(fixtureChars, dst));
+
+		try {
+			sb.getChars(0, 10, null, 0);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		try {
+			sb.getChars(-1, 10, dst, 0);
+			fail("no IOOBE, srcBegin negative");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.getChars(0, 10, dst, -1);
+			fail("no IOOBE, dstBegin negative");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.getChars(5, 4, dst, 0);
+			fail("no IOOBE, srcBegin > srcEnd");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.getChars(0, 11, dst, 0);
+			fail("no IOOBE, srcEnd > length");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.getChars(0, 10, dst, 5);
+			fail("no IOOBE, dstBegin and src size too large for what's left in dst");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.indexOf(String)
+	 */
+	public void test_indexOfLjava_lang_String() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertEquals(0, sb.indexOf("0"));
+		assertEquals(0, sb.indexOf("012"));
+		assertEquals(-1, sb.indexOf("02"));
+		assertEquals(8, sb.indexOf("89"));
+
+		try {
+			sb.indexOf(null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.indexOf(String, int)
+	 */
+	public void test_IndexOfStringInt() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertEquals(0, sb.indexOf("0"));
+		assertEquals(0, sb.indexOf("012"));
+		assertEquals(-1, sb.indexOf("02"));
+		assertEquals(8, sb.indexOf("89"));
+
+		assertEquals(0, sb.indexOf("0"), 0);
+		assertEquals(0, sb.indexOf("012"), 0);
+		assertEquals(-1, sb.indexOf("02"), 0);
+		assertEquals(8, sb.indexOf("89"), 0);
+
+		assertEquals(-1, sb.indexOf("0"), 5);
+		assertEquals(-1, sb.indexOf("012"), 5);
+		assertEquals(-1, sb.indexOf("02"), 0);
+		assertEquals(8, sb.indexOf("89"), 5);
+
+		try {
+			sb.indexOf(null, 0);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, boolean)
+	 */
+	public void test_insertIZ() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, true));
+		assertEquals("true0000", sb.toString());
+		assertEquals(8, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, false));
+		assertEquals("false0000", sb.toString());
+		assertEquals(9, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, false));
+		assertEquals("00false00", sb.toString());
+		assertEquals(9, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, false));
+		assertEquals("0000false", sb.toString());
+		assertEquals(9, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, false);
+			fail("no SIOOBE, negative index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, false);
+			fail("no SIOOBE, index too large index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, char)
+	 */
+	public void test_insertIC() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 'a'));
+		assertEquals("a0000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 'b'));
+		assertEquals("b0000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, 'b'));
+		assertEquals("00b00", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, 'b'));
+		assertEquals("0000b", sb.toString());
+		assertEquals(5, sb.length());
+
+		// FIXME this fails on Sun JRE 5.0_5
+//		try {
+//			sb = new StringBuilder(fixture);
+//			sb.insert(-1, 'a');
+//			fail("no SIOOBE, negative index");
+//		} catch (StringIndexOutOfBoundsException e) {
+//			// Expected
+//		}
+
+		/*
+		 * FIXME This fails on Sun JRE 5.0_5, but that seems like a bug, since
+		 * the 'insert(int, char[]) behaves this way.
+		 */
+//		try {
+//			sb = new StringBuilder(fixture);
+//			sb.insert(5, 'a');
+//			fail("no SIOOBE, index too large index");
+//		} catch (StringIndexOutOfBoundsException e) {
+//			// Expected
+//		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, char[])'
+	 */
+	public void test_insertI$C() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }));
+		assertEquals("ab0000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }));
+		assertEquals("00ab00", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }));
+		assertEquals("0000ab", sb.toString());
+		assertEquals(6, sb.length());
+
+		/*
+		 * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
+		 * undocumented. The assumption is that this method behaves like
+		 * String.valueOf(char[]), which does throw a NPE too, but that is also
+		 * undocumented.
+		 */
+
+		try {
+			sb.insert(0, (char[]) null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, new char[] { 'a', 'b' });
+			fail("no SIOOBE, negative index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' });
+			fail("no SIOOBE, index too large index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, char[], int, int)
+	 */
+	public void test_insertI$CII() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 2));
+		assertEquals("ab0000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, new char[] { 'a', 'b' }, 0, 1));
+		assertEquals("a0000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 2));
+		assertEquals("00ab00", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, new char[] { 'a', 'b' }, 0, 1));
+		assertEquals("00a00", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 2));
+		assertEquals("0000ab", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, new char[] { 'a', 'b' }, 0, 1));
+		assertEquals("0000a", sb.toString());
+		assertEquals(5, sb.length());
+
+		/*
+		 * TODO This NPE is the behavior on Sun's JRE 5.0_5, but it's
+		 * undocumented. The assumption is that this method behaves like
+		 * String.valueOf(char[]), which does throw a NPE too, but that is also
+		 * undocumented.
+		 */
+
+		try {
+			sb.insert(0, (char[]) null, 0, 2);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, new char[] { 'a', 'b' }, 0, 2);
+			fail("no SIOOBE, negative index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, 0, 2);
+			fail("no SIOOBE, index too large index");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, -1, 2);
+			fail("no SIOOBE, negative offset");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
+			fail("no SIOOBE, negative length");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
+			fail("no SIOOBE, too long");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, CharSequence)
+	 */
+	public void test_insertILjava_lang_CharSequence() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, (CharSequence) "ab"));
+		assertEquals("ab0000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, (CharSequence) "ab"));
+		assertEquals("00ab00", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (CharSequence) "ab"));
+		assertEquals("0000ab", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (CharSequence) null));
+		assertEquals("0000null", sb.toString());
+		assertEquals(8, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, (CharSequence) "ab");
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, (CharSequence) "ab");
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, CharSequence, int, int)
+	 */
+	public void test_insertILjava_lang_CharSequenceII() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 2));
+		assertEquals("ab0000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, (CharSequence) "ab", 0, 1));
+		assertEquals("a0000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 2));
+		assertEquals("00ab00", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, (CharSequence) "ab", 0, 1));
+		assertEquals("00a00", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 2));
+		assertEquals("0000ab", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (CharSequence) "ab", 0, 1));
+		assertEquals("0000a", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (CharSequence) null, 0, 2));
+		assertEquals("0000nu", sb.toString());
+		assertEquals(6, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, (CharSequence) "ab", 0, 2);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, (CharSequence) "ab", 0, 2);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, (CharSequence) "ab", -1, 2);
+			fail("no IOOBE, negative offset");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, 0, -1);
+			fail("no IOOBE, negative length");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, new char[] { 'a', 'b' }, 0, 3);
+			fail("no IOOBE, too long");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, double)
+	 */
+	public void test_insertID() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, -1D));
+		assertEquals("-1.00000", sb.toString());
+		assertEquals(8, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 0D));
+		assertEquals("0.00000", sb.toString());
+		assertEquals(7, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, 1D));
+		assertEquals("001.000", sb.toString());
+		assertEquals(7, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, 2D));
+		assertEquals("00002.0", sb.toString());
+		assertEquals(7, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, 1D);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, 1D);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, float)
+	 */
+	public void test_insertIF() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, -1F));
+		assertEquals("-1.00000", sb.toString());
+		assertEquals(8, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 0F));
+		assertEquals("0.00000", sb.toString());
+		assertEquals(7, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, 1F));
+		assertEquals("001.000", sb.toString());
+		assertEquals(7, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, 2F));
+		assertEquals("00002.0", sb.toString());
+		assertEquals(7, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, 1F);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, 1F);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, int)
+	 */
+	public void test_insertII() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, -1));
+		assertEquals("-10000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 0));
+		assertEquals("00000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, 1));
+		assertEquals("00100", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, 2));
+		assertEquals("00002", sb.toString());
+		assertEquals(5, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, 1);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, 1);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, long)
+	 */
+	public void test_insertIJ() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, -1L));
+		assertEquals("-10000", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, 0L));
+		assertEquals("00000", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, 1L));
+		assertEquals("00100", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, 2L));
+		assertEquals("00002", sb.toString());
+		assertEquals(5, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, 1L);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, 1L);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, Object)
+	 */
+	public void test_insertILjava_lang_Object() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, Fixture.INSTANCE));
+		assertEquals("fixture0000", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, Fixture.INSTANCE));
+		assertEquals("00fixture00", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, Fixture.INSTANCE));
+		assertEquals("0000fixture", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (Object) null));
+		assertEquals("0000null", sb.toString());
+		assertEquals(8, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, Fixture.INSTANCE);
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, Fixture.INSTANCE);
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.insert(int, String)
+	 */
+	public void test_insertILjava_lang_String() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(0, "fixture"));
+		assertEquals("fixture0000", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(2, "fixture"));
+		assertEquals("00fixture00", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, "fixture"));
+		assertEquals("0000fixture", sb.toString());
+		assertEquals(11, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.insert(4, (Object) null));
+		assertEquals("0000null", sb.toString());
+		assertEquals(8, sb.length());
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(-1, "fixture");
+			fail("no IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.insert(5, "fixture");
+			fail("no IOOBE, index too large index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.lastIndexOf(String)
+	 */
+	public void test_lastIndexOfLjava_lang_String() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertEquals(0, sb.lastIndexOf("0"));
+		assertEquals(0, sb.lastIndexOf("012"));
+		assertEquals(-1, sb.lastIndexOf("02"));
+		assertEquals(8, sb.lastIndexOf("89"));
+
+		try {
+			sb.lastIndexOf(null);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.lastIndexOf(String, int)
+	 */
+	public void test_lastIndexOfLjava_lang_StringI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertEquals(0, sb.lastIndexOf("0"));
+		assertEquals(0, sb.lastIndexOf("012"));
+		assertEquals(-1, sb.lastIndexOf("02"));
+		assertEquals(8, sb.lastIndexOf("89"));
+
+		assertEquals(0, sb.lastIndexOf("0"), 0);
+		assertEquals(0, sb.lastIndexOf("012"), 0);
+		assertEquals(-1, sb.lastIndexOf("02"), 0);
+		assertEquals(8, sb.lastIndexOf("89"), 0);
+
+		assertEquals(-1, sb.lastIndexOf("0"), 5);
+		assertEquals(-1, sb.lastIndexOf("012"), 5);
+		assertEquals(-1, sb.lastIndexOf("02"), 0);
+		assertEquals(8, sb.lastIndexOf("89"), 5);
+
+		try {
+			sb.lastIndexOf(null, 0);
+			fail("no NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.length()
+	 */
+	public void test_length() {
+		StringBuilder sb = new StringBuilder();
+		assertEquals(0, sb.length());
+		sb.append("0000");
+		assertEquals(4, sb.length());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.offsetByCodePoints(int, int)'
+	 */
+	public void test_offsetByCodePointsII() {
+		// TODO Implement Java 5 code point functionality.
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.replace(int, int, String)'
+	 */
+	public void test_replaceIILjava_lang_String() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.replace(1, 3, "11"));
+		assertEquals("0110", sb.toString());
+		assertEquals(4, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.replace(1, 2, "11"));
+		assertEquals("01100", sb.toString());
+		assertEquals(5, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.replace(4, 5, "11"));
+		assertEquals("000011", sb.toString());
+		assertEquals(6, sb.length());
+
+		sb = new StringBuilder(fixture);
+		assertSame(sb, sb.replace(4, 6, "11"));
+		assertEquals("000011", sb.toString());
+		assertEquals(6, sb.length());
+
+		// FIXME Undocumented NPE in Sun's JRE 5.0_5
+		try {
+			sb.replace(1, 2, null);
+			fail("No NPE");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.replace(-1, 2, "11");
+			fail("No SIOOBE, negative start");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.replace(5, 2, "11");
+			fail("No SIOOBE, start > length");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb = new StringBuilder(fixture);
+			sb.replace(3, 2, "11");
+			fail("No SIOOBE, start > end");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.reverse()
+	 */
+	public void test_reverse() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertSame(sb, sb.reverse());
+		assertEquals("9876543210", sb.toString());
+
+		sb = new StringBuilder("012345678");
+		assertSame(sb, sb.reverse());
+		assertEquals("876543210", sb.toString());
+
+		sb.setLength(1);
+		assertSame(sb, sb.reverse());
+		assertEquals("8", sb.toString());
+
+		sb.setLength(0);
+		assertSame(sb, sb.reverse());
+		assertEquals("", sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.setCharAt(int, char)
+	 */
+	public void test_setCharAtIC() {
+		final String fixture = "0000";
+		StringBuilder sb = new StringBuilder(fixture);
+		sb.setCharAt(0, 'A');
+		assertEquals("A000", sb.toString());
+		sb.setCharAt(1, 'B');
+		assertEquals("AB00", sb.toString());
+		sb.setCharAt(2, 'C');
+		assertEquals("ABC0", sb.toString());
+		sb.setCharAt(3, 'D');
+		assertEquals("ABCD", sb.toString());
+
+		try {
+			sb.setCharAt(-1, 'A');
+			fail("No IOOBE, negative index");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.setCharAt(4, 'A');
+			fail("No IOOBE, index == length");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.setCharAt(5, 'A');
+			fail("No IOOBE, index > length");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.setLength(int)'
+	 */
+	public void test_setLengthI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		sb.setLength(5);
+		assertEquals(5, sb.length());
+		assertEquals("01234", sb.toString());
+		sb.setLength(6);
+		assertEquals(6, sb.length());
+		assertEquals("01234\0", sb.toString());
+		sb.setLength(0);
+		assertEquals(0, sb.length());
+		assertEquals("", sb.toString());
+
+		try {
+			sb.setLength(-1);
+			fail("No IOOBE, negative length.");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.subSequence(int, int)
+	 */
+	public void test_subSequenceII() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		CharSequence ss = sb.subSequence(0, 5);
+		assertEquals("01234", ss.toString());
+
+		ss = sb.subSequence(0, 0);
+		assertEquals("", ss.toString());
+
+		try {
+			sb.subSequence(-1, 1);
+			fail("No IOOBE, negative start.");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.subSequence(0, -1);
+			fail("No IOOBE, negative end.");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.subSequence(0, fixture.length() + 1);
+			fail("No IOOBE, end > length.");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.subSequence(3, 2);
+			fail("No IOOBE, start > end.");
+		} catch (IndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.substring(int)
+	 */
+	public void test_substringI() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		String ss = sb.substring(0);
+		assertEquals(fixture, ss);
+
+		ss = sb.substring(10);
+		assertEquals("", ss);
+
+		try {
+			sb.substring(-1);
+			fail("No SIOOBE, negative start.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.substring(0, -1);
+			fail("No SIOOBE, negative end.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.substring(fixture.length() + 1);
+			fail("No SIOOBE, start > length.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.substring(int, int)
+	 */
+	public void test_substringII() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		String ss = sb.substring(0, 5);
+		assertEquals("01234", ss);
+
+		ss = sb.substring(0, 0);
+		assertEquals("", ss);
+
+		try {
+			sb.substring(-1, 1);
+			fail("No SIOOBE, negative start.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.substring(0, -1);
+			fail("No SIOOBE, negative end.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.substring(0, fixture.length() + 1);
+			fail("No SIOOBE, end > length.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+
+		try {
+			sb.substring(3, 2);
+			fail("No SIOOBE, start > end.");
+		} catch (StringIndexOutOfBoundsException e) {
+			// Expected
+		}
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.toString()'
+	 */
+	public void test_toString() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertEquals(fixture, sb.toString());
+	}
+
+	/*
+	 * @tests java.lang.StringBuilder.trimToSize()'
+	 */
+	public void test_trimToSize() {
+		final String fixture = "0123456789";
+		StringBuilder sb = new StringBuilder(fixture);
+		assertTrue(sb.capacity() > fixture.length());
+		assertEquals(fixture.length(), sb.length());
+		assertEquals(fixture, sb.toString());
+		int prevCapacity = sb.capacity();
+		sb.trimToSize();
+		assertTrue(prevCapacity > sb.capacity());
+		assertEquals(fixture.length(), sb.length());
+		assertEquals(fixture, sb.toString());
+	}
+
+	private static final class Fixture {
+		static final Fixture INSTANCE = new Fixture();
+
+		private Fixture() {
+			super();
+		}
+
+		public String toString() {
+			return "fixture";
+		}
+	}
+}



Mime
View raw message