@@ -0,0 +1,3311 @@
+/****************************************************************%0A * Licensed to the Apache Software Foundation (ASF) under one   *%0A * or more contributor license agreements.  See the NOTICE file *%0A * distributed with this work for additional information        *%0A * regarding copyright ownership.  The ASF licenses this file   *%0A * to you under the Apache License, Version 2.0 (the            *%0A * %22License%22); you may not use this file except in compliance   *%0A * with the License.  You may obtain a copy of the License at   *%0A *                                                              *%0A *   http://www.apache.org/licenses/LICENSE-2.0                 *%0A *                                                              *%0A * Unless required by applicable law or agreed to in writing,   *%0A * software distributed under the License is distributed on an  *%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *%0A * KIND, either express or implied.  See the License for the    *%0A * specific language governing permissions and limitations      *%0A * under the License.                                           *%0A ****************************************************************/%0A%0Apackage org.apache.james.util;%0A%0Aimport java.io.ByteArrayOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.OutputStream;%0A%0Aimport junit.framework.TestCase;%0A%0A/**%0A * Tests for the ExtraDotOutputStream%0A */%0Apublic class CRLFOutputStreamTest extends TestCase %7B%0A%0A    public void testMain() throws IOException %7B%0A        String data = %22.This is a test%5Cr%5Cnof the thing.%5Cr%5CnWe should not have much trouble.%5Cr%5Cn.doubled?%5Cr%5Cnor not?%5Cn.doubled%5Cnor not?%5Cr%5Cn%5Cr%5Cn%5Cn%5Cn%5Cr%5Cr%5Cr%5Cn%22;%0A        ByteArrayOutputStream bOut = new ByteArrayOutputStream();%0A        OutputStream os = new CRLFOutputStream(bOut);%0A        os.write(data.getBytes());%0A        os.flush();%0A        String expected = %22.This is a test%5Cr%5Cnof the thing.%5Cr%5CnWe should not have much trouble.%5Cr%5Cn.doubled?%5Cr%5Cnor not?%5Cr%5Cn.doubled%5Cr%5Cnor not?%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn%22;%0A        assertEquals(expected,bOut.toString());%0A    %7D%0A%0A    /*%0A     * Test method for 'org.apache.james.util.ExtraDotOutputStream.checkCRLFTerminator()'%0A     */%0A    public void testCheckCRLFTerminator() throws IOException %7B%0A        ByteArrayOutputStream bOut = new ByteArrayOutputStream();%0A        CRLFOutputStream os = new CRLFOutputStream(bOut);%0A        // if the stream is empty then we should not add the CRLF.%0A        os.checkCRLFTerminator();%0A        os.flush();%0A        assertEquals(%22%22,bOut.toString());%0A        os.write(%22Test%22.getBytes());%0A        os.flush();%0A        assertEquals(%22Test%22,bOut.toString());%0A        os.checkCRLFTerminator();%0A        os.flush();%0A        assertEquals(%22Test%5Cr%5Cn%22,bOut.toString());%0A        // if the stream ends with %5Cr we should simply add the %5Cn%0A        os.write(%22A line with incomplete ending%5Cr%22.getBytes());%0A        os.flush();%0A        assertEquals(%22Test%5Cr%5CnA line with incomplete ending%5Cr%22,bOut.toString());%0A        os.checkCRLFTerminator();%0A        os.flush();%0A        assertEquals(%22Test%5Cr%5CnA line with incomplete ending%5Cr%5Cn%22,bOut.toString());%0A        // already correctly terminated, should leave the output untouched%0A        os.checkCRLFTerminator();%0A        os.flush();%0A        assertEquals(%22Test%5Cr%5CnA line with incomplete ending%5Cr%5Cn%22,bOut.toString());%0A    %7D%0A%0A%7D%0A

Test for Extracted CRLFOutputStream from ExtraDotOutputStream (remove com.sun dependency)