package junit_example;
import org.junit.*;


/**
  Class for testing side effects.
  The java.lang.StringBuilder class is tested.
  This class will test some return values and throws as well.
*/
public class TestSides {

  @Test
  public void testStringBuilder() {
    final StringBuilder buf = new StringBuilder();
    //  "Constructs a string builder with no characters in it"
    Assert.assertEquals(0, buf.length());
    //  "initial capacity of 16 characters"
    Assert.assertEquals(16, buf.capacity());
    //  "Returns: a reference to this object."
    Assert.assertSame(buf, buf.append("de"));
    //  Length is previous length (0) + length of appended string.
    Assert.assertEquals(2, buf.length());
    //  "As long as the length of the character sequence contained
    //    in the string builder does not exceed the capacity,
    //    it is not necessary to allocate a new internal buffer"
    Assert.assertEquals(16, buf.capacity());
    //  "Then the character at index k in the new character sequence
    //    is equal to the character at index k in the old character
    //    sequence, if k is less than n; otherwise, it is equal to
    //    the character at index k-n in the argument str."
    Assert.assertEquals('d', buf.charAt(0));
    Assert.assertEquals('e', buf.charAt(1));
  }

}
