1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.mail.internal.factory.message; |
21 |
|
|
22 |
|
import java.util.Properties; |
23 |
|
|
24 |
|
import javax.mail.Message; |
25 |
|
import javax.mail.MessagingException; |
26 |
|
import javax.mail.Session; |
27 |
|
import javax.mail.internet.InternetAddress; |
28 |
|
import javax.mail.internet.MimeMessage; |
29 |
|
|
30 |
|
import org.junit.Rule; |
31 |
|
import org.junit.Test; |
32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
33 |
|
|
34 |
|
import static org.hamcrest.CoreMatchers.equalTo; |
35 |
|
import static org.hamcrest.CoreMatchers.notNullValue; |
36 |
|
import static org.junit.Assert.assertEquals; |
37 |
|
import static org.junit.Assert.assertThat; |
38 |
|
import static org.junit.Assert.fail; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
|
|
|
| 96.9% |
Uncovered Elements: 1 (32) |
Complexity: 5 |
Complexity Density: 0.18 |
|
45 |
|
public class MessageMimeMessageFactoryTest |
46 |
|
{ |
47 |
|
@Rule |
48 |
|
public MockitoComponentMockingRule<MessageMimeMessageFactory> mocker = |
49 |
|
new MockitoComponentMockingRule<>(MessageMimeMessageFactory.class); |
50 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void createMessageWithBadSource() throws Exception |
53 |
|
{ |
54 |
1 |
try { |
55 |
1 |
this.mocker.getComponentUnderTest().createMessage("source", null); |
56 |
0 |
fail("Should have thrown an exception"); |
57 |
|
} catch (MessagingException expected) { |
58 |
1 |
assertEquals("Failed to create mime message from source [class java.lang.String]", expected.getMessage()); |
59 |
|
} |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
62 |
1 |
@Test... |
63 |
|
public void createMultipleMessages() throws Exception |
64 |
|
{ |
65 |
1 |
MimeMessage source = new MimeMessage(Session.getInstance(new Properties())); |
66 |
1 |
source.setFrom(new InternetAddress("localhost@xwiki.org")); |
67 |
1 |
source.addRecipient(Message.RecipientType.TO, new InternetAddress("john@doe.com")); |
68 |
1 |
source.setSubject("Subject"); |
69 |
1 |
source.setText("Content"); |
70 |
|
|
71 |
1 |
MimeMessage first = mocker.getComponentUnderTest().createMessage(source, null); |
72 |
|
|
73 |
1 |
assertEqualMimeMessage(first, source); |
74 |
|
|
75 |
1 |
first.setFrom(new InternetAddress("jane@doe.com")); |
76 |
1 |
first.addRecipient(Message.RecipientType.TO, new InternetAddress("jack@doe.com")); |
77 |
1 |
first.setSubject("First subject"); |
78 |
1 |
first.setText("First content"); |
79 |
|
|
80 |
1 |
MimeMessage second = mocker.getComponentUnderTest().createMessage(source, null); |
81 |
|
|
82 |
|
|
83 |
1 |
assertEqualMimeMessage(second, source); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void ensureMessageReceiveSameMessageID() throws Exception |
88 |
|
{ |
89 |
1 |
MimeMessage source = new MimeMessage(Session.getInstance(new Properties())); |
90 |
1 |
source.setText("Content"); |
91 |
|
|
92 |
1 |
MimeMessage first = mocker.getComponentUnderTest().createMessage(source, null); |
93 |
1 |
MimeMessage second = mocker.getComponentUnderTest().createMessage(source, null); |
94 |
|
|
95 |
|
|
96 |
1 |
assertThat(first.getMessageID(), notNullValue()); |
97 |
1 |
assertThat(second.getMessageID(), notNullValue()); |
98 |
1 |
assertThat(first.getMessageID(), equalTo(second.getMessageID())); |
99 |
|
} |
100 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
101 |
2 |
private void assertEqualMimeMessage(MimeMessage message1, MimeMessage message2) throws Exception... |
102 |
|
{ |
103 |
2 |
assertThat(message1.getFrom(), equalTo(message2.getFrom())); |
104 |
2 |
assertThat(message1.getAllRecipients(), equalTo(message2.getAllRecipients())); |
105 |
2 |
assertThat(message1.getSubject(), equalTo(message2.getSubject())); |
106 |
2 |
assertThat(message1.getContent(), equalTo(message2.getContent())); |
107 |
|
} |
108 |
|
} |