1 19 20 package org.apache.james.util; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 26 import junit.framework.TestCase; 27 28 31 public class ExtraDotOutputStreamTest extends TestCase { 32 33 public void testMain() throws IOException { 34 String data = ".This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n.doubled?\r\nor not?\n.doubled\nor not?\r\n\r\n\n\n\r\r\r\n"; 35 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 36 OutputStream os = new ExtraDotOutputStream(bOut); 37 os.write(data.getBytes()); 38 os.flush(); 39 String expected = "..This is a test\r\nof the thing.\r\nWe should not have much trouble.\r\n..doubled?\r\nor not?\r\n..doubled\r\nor not?\r\n\r\n\r\n\r\n\r\n\r\n\r\n"; 40 assertEquals(expected,bOut.toString()); 41 } 42 43 46 public void testCheckCRLFTerminator() throws IOException { 47 ByteArrayOutputStream bOut = new ByteArrayOutputStream (); 48 ExtraDotOutputStream os = new ExtraDotOutputStream(bOut); 49 os.checkCRLFTerminator(); 51 os.flush(); 52 assertEquals("",bOut.toString()); 53 os.write("Test".getBytes()); 54 os.flush(); 55 assertEquals("Test",bOut.toString()); 56 os.checkCRLFTerminator(); 57 os.flush(); 58 assertEquals("Test\r\n",bOut.toString()); 59 os.write("A line with incomplete ending\r".getBytes()); 61 os.flush(); 62 assertEquals("Test\r\nA line with incomplete ending\r",bOut.toString()); 63 os.checkCRLFTerminator(); 64 os.flush(); 65 assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString()); 66 os.checkCRLFTerminator(); 68 os.flush(); 69 assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString()); 70 } 71 72 } 73 | Popular Tags |