1 package org.apache.maven.plugin.assembly.utils;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import junit.framework.TestCase;
23
24 import java.io.ByteArrayInputStream;
25 import java.io.IOException;
26
27 public class WindowsLineFeedInputStreamTest
28 extends TestCase
29 {
30
31 public void testSimpleString()
32 throws Exception
33 {
34 assertEquals( "abc\r\n", roundtrip( "abc" ) );
35 }
36
37 public void testInTheMiddleOfTheLine()
38 throws Exception
39 {
40 assertEquals( "a\r\nbc\r\n", roundtrip( "a\r\nbc" ) );
41 }
42
43 public void testMultipleBlankLines()
44 throws Exception
45 {
46 assertEquals( "a\r\n\r\nbc\r\n", roundtrip( "a\r\n\r\nbc" ) );
47 }
48
49 public void testTwoLinesAtEnd()
50 throws Exception
51 {
52 assertEquals( "a\r\n\r\n", roundtrip( "a\r\n\r\n" ) );
53 }
54
55 public void testLinuxLinefeeds()
56 throws Exception
57 {
58 final String roundtrip = roundtrip( "ab\nc", false );
59 assertEquals( "ab\r\nc", roundtrip );
60 }
61
62
63 public void testMalformed()
64 throws Exception
65 {
66 assertEquals( "a\rbc", roundtrip( "a\rbc", false ) );
67 }
68
69 public void testRetainLineFeed()
70 throws Exception
71 {
72 assertEquals( "a\r\n\r\n", roundtrip( "a\r\n\r\n", false ) );
73 assertEquals( "a", roundtrip( "a", false ) );
74 }
75
76 private String roundtrip( String msg )
77 throws IOException
78 {
79 return roundtrip( msg, true );
80 }
81
82 private String roundtrip( String msg, boolean ensure )
83 throws IOException
84 {
85 ByteArrayInputStream baos = new ByteArrayInputStream( msg.getBytes() );
86 WindowsLineFeedInputStream lf = new WindowsLineFeedInputStream( baos, ensure );
87 byte[] buf = new byte[100];
88 final int read = lf.read( buf );
89 return new String( buf, 0, read );
90 }
91
92
93 }