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 LinuxLineFeedInputStreamTest
28 extends TestCase
29 {
30
31 public void testSimpleString()
32 throws Exception
33 {
34 assertEquals( "abc\n", roundtrip( "abc" ) );
35 }
36
37 public void testInTheMiddleOfTheLine()
38 throws Exception
39 {
40 assertEquals( "a\nbc\n", roundtrip( "a\r\nbc" ) );
41 }
42
43 public void testCrOnly()
44 throws Exception
45 {
46 assertEquals( "a\nb\n", roundtrip( "a\rb" ) );
47 }
48
49 public void testCrAtEnd() throws Exception {
50 assertEquals( "a\n", roundtrip( "a\r" ) );
51 }
52
53
54 public void testMultipleBlankLines()
55 throws Exception
56 {
57 assertEquals( "a\n\nbc\n", roundtrip( "a\r\n\r\nbc" ) );
58 }
59
60 public void testTwoLinesAtEnd()
61 throws Exception
62 {
63 assertEquals( "a\n\n", roundtrip( "a\r\n\r\n" ) );
64 }
65
66 public void testRetainLineFeed()
67 throws Exception
68 {
69 assertEquals( "a\n\n", roundtrip( "a\r\n\r\n", false ) );
70 assertEquals( "a", roundtrip( "a", false ) );
71 }
72
73 private String roundtrip( String msg )
74 throws IOException
75 {
76 return roundtrip( msg, true );
77 }
78
79 private String roundtrip( String msg, boolean ensure )
80 throws IOException
81 {
82 ByteArrayInputStream baos = new ByteArrayInputStream( msg.getBytes() );
83 LinuxLineFeedInputStream lf = new LinuxLineFeedInputStream( baos, ensure );
84 byte[] buf = new byte[100];
85 final int read = lf.read( buf );
86 return new String( buf, 0, read );
87 }
88
89 }