@Test
public void testSetIndex() {

	// Negative index
	StringBundler sb = new StringBundler();
	try {
		sb.setIndex(-1);
		Assert.fail();
	}
	catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
	}
	// New index equals current index
	sb = new StringBundler(4);
	sb.append("test1");
	sb.append("test2");
	Assert.assertEquals(2, sb.index());
	Assert.assertEquals("test1", sb.stringAt(0));
	Assert.assertEquals("test2", sb.stringAt(1));
	sb.setIndex(2);
	Assert.assertEquals(2, sb.index());
	Assert.assertEquals("test1", sb.stringAt(0));
	Assert.assertEquals("test2", sb.stringAt(1));
	// New index is larger than the current index but smaller than the array
	// size
	Assert.assertEquals(4, sb.capacity());
	sb.setIndex(4);
	Assert.assertEquals(4, sb.capacity());
	Assert.assertEquals(4, sb.index());
	Assert.assertEquals("test1", sb.stringAt(0));
	Assert.assertEquals("test2", sb.stringAt(1));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(2));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(3));
	// New index is larger than the current index and array size
	sb.setIndex(6);
	Assert.assertEquals(6, sb.capacity());
	Assert.assertEquals(6, sb.index());
	Assert.assertEquals("test1", sb.stringAt(0));
	Assert.assertEquals("test2", sb.stringAt(1));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(2));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(3));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(4));
	Assert.assertEquals(StringPool.BLANK, sb.stringAt(5));
	// New index is smaller than current index
	sb.setIndex(1);
	Assert.assertEquals(6, sb.capacity());
	Assert.assertEquals(1, sb.index());
	Assert.assertEquals("test1", sb.stringAt(0));
	try {
		Assert.assertEquals(null, sb.stringAt(1));
		Assert.fail();
	}
	catch (ArrayIndexOutOfBoundsException arrayIndexOutOfBoundsException) {
	}
}