commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwins...@apache.org
Subject svn commit: r921330 - in /commons/proper/net/branches/NET_2_0/src: main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java
Date Wed, 10 Mar 2010 12:50:58 GMT
Author: rwinston
Date: Wed Mar 10 12:50:57 2010
New Revision: 921330

URL: http://svn.apache.org/viewvc?rev=921330&view=rev
Log:
Make allowances for platform-specific line endings in unit tests

Modified:
    commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java
    commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java

Modified: commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java?rev=921330&r1=921329&r2=921330&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/io/DotTerminatedMessageReader.java
Wed Mar 10 12:50:57 2010
@@ -38,14 +38,8 @@ import java.io.Reader;
  */
 public final class DotTerminatedMessageReader extends Reader
 {
-    private static final String LS;
-    private static final char[] LS_CHARS;
-
-    static
-    {
-        LS = System.getProperty("line.separator");
-        LS_CHARS = LS.toCharArray();
-    }
+    private static final String LS = System.getProperty("line.separator");
+    char[] LS_CHARS;
 
     private boolean atBeginning;
     private boolean eof;
@@ -61,6 +55,7 @@ public final class DotTerminatedMessageR
     public DotTerminatedMessageReader(Reader reader)
     {
         super(reader);
+        LS_CHARS = LS.toCharArray();
         internalBuffer = new char[LS_CHARS.length + 3];
         pos = internalBuffer.length;
         // Assumes input is at start of message

Modified: commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java?rev=921330&r1=921329&r2=921330&view=diff
==============================================================================
--- commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java
(original)
+++ commons/proper/net/branches/NET_2_0/src/test/java/org/apache/commons/net/io/DotTerminatedMessageReaderTest.java
Wed Mar 10 12:50:57 2010
@@ -27,17 +27,32 @@ public class DotTerminatedMessageReaderT
 	private DotTerminatedMessageReader reader;
 	private StringBuilder str = new StringBuilder();
 	private char[] buf = new char[64];
+	final static String SEP = System.getProperty("line.separator");
 	
-	public void testReadSimpleString() throws IOException {
+	public void testReadSimpleStringCrLfLineEnding() throws IOException {
 		final String test = "Hello World!\r\n.\r\n";
 		reader = new DotTerminatedMessageReader(new StringReader(test));
+		reader.LS_CHARS = new char[]{'\r','\n'};
 		
 		int read = 0;
 		while ((read = reader.read(buf)) != -1) {
-			str.append(buf, 0, read-1);
+			str.append(buf, 0, read);
 		}
 		
-		assertEquals(str.toString(), "Hello World!");
+		assertEquals("Hello World!" + String.valueOf(reader.LS_CHARS), str.toString());
+	}
+	
+	public void testReadSimpleStringLfLineEnding() throws IOException {
+		final String test = "Hello World!\r\n.\r\n";
+		reader = new DotTerminatedMessageReader(new StringReader(test));
+		reader.LS_CHARS = new char[]{'\n'};
+		
+		int read = 0;
+		while ((read = reader.read(buf)) != -1) {
+			str.append(buf, 0, read);
+		}
+		
+		assertEquals("Hello World!" + String.valueOf(reader.LS_CHARS), str.toString());
 	}
 	
 	public void testEmbeddedNewlines() throws IOException {
@@ -46,10 +61,10 @@ public class DotTerminatedMessageReaderT
 		
 		int read = 0;
 		while ((read = reader.read(buf)) != -1) {
-			str.append(buf, 0, read-1);
+			str.append(buf, 0, read);
 		}
 		
-		assertEquals(str.toString(), "Hello\nWorld\nA\rB");
+		assertEquals(str.toString(), "Hello\nWorld\nA\rB" + SEP);
 	}
 	
 	public void testDoubleCrBeforeDot() throws IOException {
@@ -58,10 +73,10 @@ public class DotTerminatedMessageReaderT
 		
 		int read = 0;
 		while ((read = reader.read(buf)) != -1) {
-			str.append(buf, 0, read-1);
+			str.append(buf, 0, read);
 		}
 		
-		assertEquals("Hello World!\r",str.toString());
+		assertEquals("Hello World!\r" + SEP,str.toString());
 	}
 
 }



Mime
View raw message