FileDocCategorySizeDatePackage
ExtraDotOutputStreamTest.javaAPI DocApache James 2.3.13329Fri Jan 12 12:56:38 GMT 2007org.apache.james.util

ExtraDotOutputStreamTest

public class ExtraDotOutputStreamTest extends TestCase
Tests for the ExtraDotOutputStream

Fields Summary
Constructors Summary
Methods Summary
public voidtestCheckCRLFTerminator()

        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        ExtraDotOutputStream os = new ExtraDotOutputStream(bOut);
        // if the stream is empty then we should not add the CRLF.
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("",bOut.toString());
        os.write("Test".getBytes());
        os.flush();
        assertEquals("Test",bOut.toString());
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\n",bOut.toString());
        // if the stream ends with \r we should simply add the \n
        os.write("A line with incomplete ending\r".getBytes());
        os.flush();
        assertEquals("Test\r\nA line with incomplete ending\r",bOut.toString());
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString());
        // already correctly terminated, should leave the output untouched
        os.checkCRLFTerminator();
        os.flush();
        assertEquals("Test\r\nA line with incomplete ending\r\n",bOut.toString());
    
public voidtestMain()

        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";
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        OutputStream os = new ExtraDotOutputStream(bOut);
        os.write(data.getBytes());
        os.flush();
        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";
        assertEquals(expected,bOut.toString());