}
@Test
public void testContentExceedsClearBuffer() throws IOException {
final String content = "<p>Simple content</p>";
final StringBuilderWriter stringWriter = new StringBuilderWriter();
LimitingTeeWriter writer = new LimitingTeeWriter(content.length() - 1, NullWriter.NULL_WRITER, stringWriter,
new Function<LimitingTeeWriter, Object>() {
@Override
public Object apply(LimitingTeeWriter input) {
final StringBuilder builder = stringWriter.getBuilder();
builder.delete(0, builder.length());
return null;
}
});
// write the first few chars
writer.write(content.substring(0, 5));
// verify content successfully buffered
Assert.assertFalse(writer.isLimitReached());
Assert.assertEquals(content.substring(0,5), stringWriter.toString());
// now write the remainder
writer.write(content.substring(5, content.length()));
Assert.assertTrue(writer.isLimitReached());
Assert.assertEquals("", stringWriter.toString());
// try to write more and see no results
writer.write("a");
Assert.assertEquals("", stringWriter.toString());
}