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());