1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.mailsender; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Before; |
24 |
|
import org.junit.BeforeClass; |
25 |
|
import org.junit.Test; |
26 |
|
|
27 |
|
|
28 |
|
@link |
29 |
|
|
30 |
|
@version |
31 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (59) |
Complexity: 14 |
Complexity Density: 0.3 |
|
32 |
|
public class MailSenderPluginTest |
33 |
|
{ |
34 |
|
@link |
35 |
|
private Mail mail; |
36 |
|
|
37 |
|
@link |
38 |
|
private static MailSenderPlugin plugin; |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
40 |
1 |
@BeforeClass... |
41 |
|
public static void setUpPlugin() |
42 |
|
{ |
43 |
1 |
plugin = new MailSenderPlugin("mail", MailSenderPlugin.class.getCanonicalName(), null); |
44 |
|
} |
45 |
|
|
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
10 |
@Before... |
48 |
|
public void setUp() |
49 |
|
{ |
50 |
10 |
this.mail = new Mail(); |
51 |
|
} |
52 |
|
|
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void testParseRawMessageWithNullMail() |
56 |
|
{ |
57 |
1 |
boolean thrown = false; |
58 |
1 |
try { |
59 |
1 |
plugin.parseRawMessage("Subject:Greetings!\n\nDear John,\nHello and Goodbye!", null); |
60 |
|
} catch (IllegalArgumentException ex) { |
61 |
1 |
thrown = true; |
62 |
|
} |
63 |
1 |
Assert.assertTrue(thrown); |
64 |
|
} |
65 |
|
|
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
67 |
1 |
@Test... |
68 |
|
public void testParseRawMessageWithNullMessage() |
69 |
|
{ |
70 |
1 |
boolean thrown = false; |
71 |
1 |
try { |
72 |
1 |
plugin.parseRawMessage(null, this.mail); |
73 |
|
} catch (IllegalArgumentException ex) { |
74 |
1 |
thrown = true; |
75 |
|
} |
76 |
1 |
Assert.assertTrue(thrown); |
77 |
|
} |
78 |
|
|
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void testParseRawMessageWithSimpleMessage() |
82 |
|
{ |
83 |
1 |
plugin.parseRawMessage("Dear John,\nHello and Goodbye!", this.mail); |
84 |
1 |
Assert.assertEquals("Dear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
85 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
86 |
|
|
87 |
|
} |
88 |
|
|
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
90 |
1 |
@Test... |
91 |
|
public void testParseRawMessageWithSubject() |
92 |
|
{ |
93 |
1 |
plugin.parseRawMessage("Subject:Greetings!\n\nDear John,\nHello and Goodbye!", this.mail); |
94 |
1 |
Assert.assertEquals("Dear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
95 |
1 |
Assert.assertEquals("Greetings!", this.mail.getSubject()); |
96 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
97 |
|
} |
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
100 |
1 |
@Test... |
101 |
|
public void testParseRawMessageWithSubjectAndFrom() |
102 |
|
{ |
103 |
1 |
plugin |
104 |
|
.parseRawMessage("Subject:Greetings!\nFrom:user@example.org\n\nDear John,\nHello and Goodbye!", this.mail); |
105 |
1 |
Assert.assertEquals("Dear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
106 |
1 |
Assert.assertEquals("Greetings!", this.mail.getSubject()); |
107 |
1 |
Assert.assertEquals("user@example.org", this.mail.getFrom()); |
108 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
109 |
|
} |
110 |
|
|
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void testParseRawMessageWithFakeFrom() |
114 |
|
{ |
115 |
1 |
plugin.parseRawMessage("Subject:Greetings!\n\nFrom:user@example.org\n\nDear John,\nHello and Goodbye!", |
116 |
|
this.mail); |
117 |
1 |
Assert.assertEquals("From:user@example.org\r\n\r\nDear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
118 |
1 |
Assert.assertEquals("Greetings!", this.mail.getSubject()); |
119 |
1 |
Assert.assertNull(this.mail.getFrom()); |
120 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
121 |
|
} |
122 |
|
|
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
124 |
1 |
@Test... |
125 |
|
public void testParseRawMessageWithColonInHeader() |
126 |
|
{ |
127 |
1 |
plugin.parseRawMessage("Subject:Greetings:Human!\n\nDear John,\nHello and Goodbye!", this.mail); |
128 |
1 |
Assert.assertEquals("Dear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
129 |
1 |
Assert.assertEquals("Greetings:Human!", this.mail.getSubject()); |
130 |
1 |
Assert.assertNull(this.mail.getFrom()); |
131 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
132 |
|
} |
133 |
|
|
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
135 |
1 |
@Test... |
136 |
|
public void testParseRawMessageWithExtraHeaders() |
137 |
|
{ |
138 |
1 |
plugin.parseRawMessage("X-Header:Something extra!\n\nDear John,\nHello and Goodbye!", this.mail); |
139 |
1 |
Assert.assertEquals("Dear John,\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
140 |
1 |
Assert.assertNull(this.mail.getSubject()); |
141 |
1 |
Assert.assertEquals(1, this.mail.getHeaders().size()); |
142 |
|
} |
143 |
|
|
144 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
145 |
1 |
@Test... |
146 |
|
public void testParseRawMessageWithMultilineSubject() |
147 |
|
{ |
148 |
1 |
plugin.parseRawMessage("Subject:Greetings\n from\n\thome\nFrom:user@example.org\n\nHello and Goodbye!", |
149 |
|
this.mail); |
150 |
1 |
Assert.assertEquals("Hello and Goodbye!\r\n", this.mail.getTextPart()); |
151 |
1 |
Assert.assertEquals("Greetings from\thome", this.mail.getSubject()); |
152 |
1 |
Assert.assertEquals("user@example.org", this.mail.getFrom()); |
153 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
154 |
|
} |
155 |
|
|
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
157 |
1 |
@Test... |
158 |
|
public void testParseRawMessageWithFakeHeaders() |
159 |
|
{ |
160 |
1 |
plugin.parseRawMessage("To Susan:Greetings!\n\nHello and Goodbye!", this.mail); |
161 |
1 |
Assert.assertEquals("To Susan:Greetings!\r\n\r\nHello and Goodbye!\r\n", this.mail.getTextPart()); |
162 |
1 |
Assert.assertNull(this.mail.getSubject()); |
163 |
1 |
Assert.assertEquals(0, this.mail.getHeaders().size()); |
164 |
|
} |
165 |
|
} |