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; |
21 |
|
|
22 |
|
import java.util.Collections; |
23 |
|
import java.util.Iterator; |
24 |
|
import java.util.UUID; |
25 |
|
|
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.mail.ExtendedMimeMessage; |
29 |
|
import org.xwiki.mail.MailState; |
30 |
|
import org.xwiki.mail.MailStatus; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
32 |
|
|
33 |
|
import static org.junit.Assert.assertEquals; |
34 |
|
import static org.junit.Assert.assertFalse; |
35 |
|
import static org.junit.Assert.assertTrue; |
36 |
|
import static org.mockito.Mockito.mock; |
37 |
|
import static org.mockito.Mockito.when; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 1 |
Complexity Density: 0.04 |
|
45 |
|
public class MemoryMailListenerTest |
46 |
|
{ |
47 |
|
private static final String UNIQUE_MESSAGE_ID1 = "ar1vm0Wca42E/dDn3dsH8ogs3/s="; |
48 |
|
private static final String UNIQUE_MESSAGE_ID2 = "6ys1BeC6gnKA7srO/vs06XBZKZM="; |
49 |
|
|
50 |
|
@Rule |
51 |
|
public MockitoComponentMockingRule<MemoryMailListener> mocker = |
52 |
|
new MockitoComponentMockingRule<>(MemoryMailListener.class); |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (26) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
54 |
1 |
@Test... |
55 |
|
public void onErrorAndGetMailStatusResult() throws Exception |
56 |
|
{ |
57 |
1 |
MemoryMailListener listener = this.mocker.getComponentUnderTest(); |
58 |
|
|
59 |
1 |
String batchId = UUID.randomUUID().toString(); |
60 |
1 |
listener.onPrepareBegin(batchId, Collections.<String, Object>emptyMap()); |
61 |
|
|
62 |
1 |
ExtendedMimeMessage message1 = mock(ExtendedMimeMessage.class); |
63 |
1 |
when(message1.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID1); |
64 |
1 |
when(message1.getType()).thenReturn("mailtype1"); |
65 |
1 |
listener.onPrepareMessageError(message1, new Exception("error1"), Collections.<String, Object>emptyMap()); |
66 |
|
|
67 |
1 |
ExtendedMimeMessage message2 = mock(ExtendedMimeMessage.class); |
68 |
1 |
when(message2.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID2); |
69 |
1 |
when(message2.getType()).thenReturn("mailtype2"); |
70 |
1 |
listener.onPrepareMessageError(message2, new Exception("error2"), Collections.<String, Object>emptyMap()); |
71 |
|
|
72 |
1 |
Iterator<MailStatus> results = listener.getMailStatusResult().getByState(MailState.PREPARE_ERROR); |
73 |
1 |
assertTrue("These should be mails in error!", results.hasNext()); |
74 |
|
|
75 |
1 |
MailStatus status = results.next(); |
76 |
1 |
assertEquals("Exception: error1", status.getErrorSummary()); |
77 |
1 |
assertTrue(status.getErrorDescription().contains("error1")); |
78 |
1 |
assertEquals(batchId, status.getBatchId()); |
79 |
1 |
assertEquals(UNIQUE_MESSAGE_ID1, status.getMessageId()); |
80 |
1 |
assertEquals("mailtype1", status.getType()); |
81 |
|
|
82 |
1 |
status = results.next(); |
83 |
1 |
assertEquals("Exception: error2", status.getErrorSummary()); |
84 |
1 |
assertTrue(status.getErrorDescription().contains("error2")); |
85 |
1 |
assertEquals(batchId, status.getBatchId()); |
86 |
1 |
assertEquals(UNIQUE_MESSAGE_ID2, status.getMessageId()); |
87 |
1 |
assertEquals("mailtype2", status.getType()); |
88 |
|
|
89 |
1 |
assertFalse(results.hasNext()); |
90 |
|
} |
91 |
|
} |