}
@Test
public void testWriteRandomByteSizes() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TrimmerOutputStream trimmerOutputStream = new TrimmerOutputStream(baos, 32, 3, 4);
StringBuilder stringBuffer = new StringBuilder("<a>");
for (int i = 0; i < 100; i++) {
stringBuffer.append(testString);
}
stringBuffer.append("</a>");
byte[] testStringBytes = stringBuffer.toString().getBytes();
int written = 0;
int count = 0;
do {
count++;
trimmerOutputStream.write(testStringBytes, written, count);
written += count;
}
while ((written + count + 1) < testStringBytes.length);
trimmerOutputStream.write(testStringBytes, written, testStringBytes.length - written);
trimmerOutputStream.close();
Assert.assertEquals(baos.size(), testStringBytes.length - 7);
Assert.assertEquals(baos.toString(), stringBuffer.toString().substring(3, stringBuffer.length() - 4));
}