1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.james.mailboxmanager.torque;
21
22 import junit.framework.TestCase;
23
24 public class MessageUtilsNormalisedWriteToTest extends TestCase {
25
26 StringBuffer buffer;
27
28 protected void setUp() throws Exception {
29 super.setUp();
30 buffer = new StringBuffer();
31 }
32
33 protected void tearDown() throws Exception {
34 super.tearDown();
35 }
36
37 public void testEmpty() throws Exception {
38 MessageUtils.normalisedWriteTo("".getBytes(), buffer);
39 assertEquals("Check processing of empty array", "", buffer.toString());
40 }
41
42 public void testNormal() throws Exception {
43 MessageUtils.normalisedWriteTo("One\r\nTwo\r\nThree\r\n".getBytes(),
44 buffer);
45 assertEquals("Check processing of normal data",
46 "One\r\nTwo\r\nThree\r\n", buffer.toString());
47 }
48
49 public void testMissing() throws Exception {
50 MessageUtils
51 .normalisedWriteTo("One\rTwo\nThree\r\n".getBytes(), buffer);
52 assertEquals("Check processing simple data containing unnormal lines",
53 "One\r\nTwo\r\nThree\r\n", buffer.toString());
54 }
55
56 public void testCRAtEnd() throws Exception {
57 MessageUtils.normalisedWriteTo("One\r\nTwo\r\nThree\r".getBytes(),
58 buffer);
59 assertEquals("CR at end", "One\r\nTwo\r\nThree\r\n", buffer.toString());
60 }
61
62 public void testLFAtEnd() throws Exception {
63 MessageUtils.normalisedWriteTo("One\r\nTwo\r\nThree\n".getBytes(),
64 buffer);
65 assertEquals("LF at end", "One\r\nTwo\r\nThree\r\n", buffer.toString());
66 }
67
68 public void testCRAtStart() throws Exception {
69 MessageUtils.normalisedWriteTo("\rOne\r\nTwo\r\nThree\r".getBytes(),
70 buffer);
71 assertEquals("CR at start", "\r\nOne\r\nTwo\r\nThree\r\n", buffer
72 .toString());
73 }
74
75 public void testLFAtStart() throws Exception {
76 MessageUtils.normalisedWriteTo("\nOne\r\nTwo\r\nThree".getBytes(),
77 buffer);
78 assertEquals("CR at start", "\r\nOne\r\nTwo\r\nThree", buffer
79 .toString());
80 }
81
82 public void testSwitchOrder() throws Exception {
83 MessageUtils.normalisedWriteTo(
84 "\n\rOne\n\rTwo\n\rThree\n\r".getBytes(), buffer);
85 assertEquals("Check processing simple data containing unnormal lines",
86 "\r\n\r\nOne\r\n\r\nTwo\r\n\r\nThree\r\n\r\n", buffer
87 .toString());
88 }
89 }