1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.mail.internal

File MemoryMailListenerTest.java

 

Code metrics

0
26
1
1
91
53
1
0.04
26
1
1

Classes

Class Line # Actions
MemoryMailListenerTest 45 26 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link MemoryMailListener}.
41    *
42    * @version $Id: 0799640a0c01f2e7602b1125e8c270b7cced1cd8 $
43    * @since 6.2M1
44    */
 
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   
 
54  1 toggle @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    }