コード例 #1
0
  @Test
  public final void testAppendCharSequenceIntInt() {
    final Random ramdom = new Random();

    for (int repeatIndex = 0; repeatIndex < 100; repeatIndex++) {
      for (int i = 0, size = string.length(); i < size; i++) {
        final int length = size - i - ramdom.nextInt(size - i);
        final int endIndex = i + length;

        final StringBuildWriter stringBuildWriter = new StringBuildWriter();
        stringBuildWriter.append(string, i, endIndex);

        assertThat(
            stringBuildWriter.getStringBuilder().toString(),
            is(equalTo(string.substring(i, endIndex))));
      }
      for (int i = string.length() - 1, size = string.length() + 1; i > 0; i--) {
        final int length = ramdom.nextInt(size - i);
        final int endIndex = i + length;

        final StringBuildWriter stringBuildWriter = new StringBuildWriter();
        stringBuildWriter.append(string, i, endIndex);

        assertThat(
            stringBuildWriter.getStringBuilder().toString(),
            is(equalTo(string.substring(i, endIndex))));
      }
    }
  }
コード例 #2
0
 @Test
 public final void testAppendChar() {
   final StringBuildWriter stringBuildWriter = new StringBuildWriter();
   final StringBuilder expected = new StringBuilder();
   for (int i = 0, size = chars.length; i < size; i++) {
     stringBuildWriter.append(chars[i]);
     expected.append(chars[i]);
     assertThat(stringBuildWriter.getStringBuilder().toString(), is(equalTo(expected.toString())));
   }
 }
コード例 #3
0
 @Test
 public final void testAppendCharSequence() {
   final StringBuildWriter stringBuildWriter = new StringBuildWriter();
   stringBuildWriter.append(string);
   assertThat(stringBuildWriter.getStringBuilder().toString(), is(equalTo(string)));
 }