2014-12-16 19:08:51 -05:00
|
|
|
package com.fsck.k9.mail.filter;
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
2014-12-16 19:08:51 -05:00
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
public class EOLConvertingOutputStreamTest {
|
2014-12-16 19:08:51 -05:00
|
|
|
private EOLConvertingOutputStream subject;
|
|
|
|
private ByteArrayOutputStream out;
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Before
|
2014-12-16 19:08:51 -05:00
|
|
|
public void setUp() throws Exception {
|
|
|
|
out = new ByteArrayOutputStream();
|
|
|
|
subject = new EOLConvertingOutputStream(out);
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFilterWithoutCRorLF() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Unchanged".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("Unchanged", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFilterWithCRLF() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Filter\r\nNext Line".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("Filter\r\nNext Line", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFilterWithJustCR() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("\n\n\n".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("\r\n\r\n\r\n", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFilterWithCR() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Filter\rNext Line".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("Filter\r\nNext Line", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFilterWithLF() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Filter\nNext Line".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("Filter\r\nNext Line", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFlushWithCR() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Flush\r".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
assertEquals("Flush\r\n", out.toString());
|
|
|
|
subject.write("\n\n\n".getBytes());
|
|
|
|
assertEquals("Flush\r\n\r\n\r\n", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFlushWithCRNotFollowedByLF() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Flush\r".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
subject.write("Next line".getBytes());
|
|
|
|
assertEquals("Flush\r\nNext line", out.toString());
|
|
|
|
}
|
|
|
|
|
2014-12-18 05:56:02 -05:00
|
|
|
@Test public void testFlushWithLF() throws Exception {
|
2014-12-16 19:08:51 -05:00
|
|
|
subject.write("Flush\n".getBytes());
|
|
|
|
subject.flush();
|
|
|
|
subject.write("\n".getBytes());
|
|
|
|
assertEquals("Flush\r\n\r\n", out.toString());
|
|
|
|
}
|
|
|
|
}
|