james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r680984 - /james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java
Date Wed, 30 Jul 2008 11:31:08 GMT
Author: bago
Date: Wed Jul 30 04:31:07 2008
New Revision: 680984

URL: http://svn.apache.org/viewvc?rev=680984&view=rev
Log:
Add some sort of unit tests for LineBreakingOutputStream

Modified:
    james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java

Modified: james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java?rev=680984&r1=680983&r2=680984&view=diff
==============================================================================
--- james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java
(original)
+++ james/mime4j/trunk/src/test/java/org/apache/james/mime4j/util/LineBreakingOutputStreamTest.java
Wed Jul 30 04:31:07 2008
@@ -19,16 +19,67 @@
 
 package org.apache.james.mime4j.util;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 
 import junit.framework.TestCase;
 
+/**
+ * Test for LineBreakingOutputStream
+ */
 public class LineBreakingOutputStreamTest extends TestCase {
     
     public void testLongLine() throws IOException {
-        OutputStream os = new LineBreakingOutputStream(System.out, 4);
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream os = new LineBreakingOutputStream(out, 4);
         os.write("gsdfklgsjdhflkgjhsdfklgjhsdlkfjghksdljfhgslkdjfhgklsjdhf".getBytes());
+        os.flush();
+        os.close();
+        String expected = "gsdf\r\nklgs\r\njdhf\r\nlkgj\r\nhsdf\r\nklgj\r\nhsdl\r\nkfjg\r\nhksd\r\nljfh\r\ngslk\r\ndjfh\r\ngkls\r\njdhf";
+        assertEquals(new String(out.toByteArray()), expected);
+    }
+    
+    public void testLineLengthEqualInput() throws IOException {
+        String input = "gsdfklgsjdhflkgjhsdfklgjhsdlkfjghksdljfhgslkdjfhgklsjdhf";
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream os = new LineBreakingOutputStream(out, input.length());
+        os.write(input.getBytes());
+        os.flush();
+        os.close();
+        assertEquals(new String(out.toByteArray()), input);
+    }
+    
+    public void testLineLengthLongerThanInput() throws IOException {
+        String input = "gsdfklgsjdhflkgjhsdfklgjhsdlkfjghksdljfhgslkdjfhgklsjdhf";
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream os = new LineBreakingOutputStream(out, input.length()+1);
+        os.write(input.getBytes());
+        os.flush();
+        os.close();
+        assertEquals(new String(out.toByteArray()), input);
+    }
+    
+    public void testLineLengthShorterThanInput() throws IOException {
+        String input = "gsdfklgsjdhflkgjhsdfklgjhsdlkfjghksdljfhgslkdjfhgklsjdhf";
+        String expected = "gsdfklgsjdhflkgjhsdfklgjhsdlkfjghksdljfhgslkdjfhgklsjdh\r\nf";
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream os = new LineBreakingOutputStream(out, input.length()-1);
+        os.write(input.getBytes());
+        os.flush();
+        os.close();
+        assertEquals(new String(out.toByteArray()), expected);
+    }
+    
+    public void testZeroLengthInput() throws IOException {
+        String input = "";
+        String expected = "";
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        OutputStream os = new LineBreakingOutputStream(out, 10);
+        os.write(input.getBytes());
+        os.flush();
+        os.close();
+        assertEquals(new String(out.toByteArray()), expected);
     }
 
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message