* Tests the wrapping writer.
*/
public void testWrappingWriter() throws Exception
{
StringWriter writer;
WrappingWriter wrapper;
// Test wrapping anywhere
writer = new StringWriter();
wrapper = new WrappingWriter(writer);
wrapper.setWrappingMode(WrappingWriter.WRAP_ANYWHERE);
wrapper.setMaxLineLength(10);
wrapper.write("1234567891123456789212345678931234567894");
wrapper.close();
assertEquals("1234567891\r\n" +
" 123456789\r\n" +
" 212345678\r\n" +
" 931234567\r\n" +
" 894",
writer.toString());
// Test wrapping only on whitespace
writer = new StringWriter();
wrapper = new WrappingWriter(writer);
wrapper.setWrappingMode(WrappingWriter.WRAP_REPLACE_WHITESPACE);
wrapper.setMaxLineLength(10);
wrapper.write("1234567891 newline here!");
wrapper.close();
assertEquals("1234567891\r\n" +
" newline\r\n" +
" here!",
writer.toString());
writer = new StringWriter();
wrapper = new WrappingWriter(writer);
wrapper.setWrappingMode(WrappingWriter.WRAP_REPLACE_WHITESPACE);
wrapper.setMaxLineLength(10);
wrapper.write("123456789 1 newline here!");
wrapper.close();
assertEquals("123456789\r\n" +
" 1 newline\r\n" +
" here!",
writer.toString());
// Test switching wrapping modes
writer = new StringWriter();
wrapper = new WrappingWriter(writer);
wrapper.setWrappingMode(WrappingWriter.WRAP_REPLACE_WHITESPACE);
wrapper.setMaxLineLength(10);
wrapper.write("1234567891 12345");
wrapper.setWrappingMode(WrappingWriter.WRAP_ANYWHERE);
wrapper.write("678921234");
wrapper.setWrappingMode(WrappingWriter.WRAP_REPLACE_WHITESPACE);
wrapper.write(" a bc def ghij klmno pqrstu");
wrapper.close();
assertEquals("1234567891\r\n" +
" 123456789\r\n" +
" 21234 a\r\n" +
" bc def\r\n" +
" ghij\r\n" +
" klmno\r\n" +
" pqrstu",
writer.toString());
// Test line with no spaces, longer than maximum length
writer = new StringWriter();
wrapper = new WrappingWriter(writer);
wrapper.setWrappingMode(WrappingWriter.WRAP_REPLACE_WHITESPACE);
wrapper.setMaxLineLength(10);
wrapper.write("123456789112345 1234567891");
wrapper.close();
assertEquals("123456789112345\r\n" +
" 1234567891",
writer.toString());
}