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

File MemoryMailStatusResultTest.java

 

Code metrics

2
22
1
1
82
49
2
0.09
22
1
2

Classes

Class Line # Actions
MemoryMailStatusResultTest 42 22 0% 2 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.ArrayList;
23    import java.util.Iterator;
24    import java.util.List;
25   
26    import org.junit.Test;
27    import org.xwiki.mail.ExtendedMimeMessage;
28    import org.xwiki.mail.MailState;
29    import org.xwiki.mail.MailStatus;
30   
31    import static org.hamcrest.CoreMatchers.equalTo;
32    import static org.hamcrest.Matchers.containsInAnyOrder;
33    import static org.junit.Assert.assertThat;
34    import static org.mockito.Mockito.mock;
35    import static org.mockito.Mockito.when;
36   
37    /**
38    * Unit tests for {@link MemoryMailStatusResult}.
39    *
40    * @version $Id: 2ac35bd98eb30ac7b352eaa6a4b2a036de77b425 $
41    */
 
42    public class MemoryMailStatusResultTest
43    {
44    private static final String BATCH_ID = "batch1";
45    private static final String UNIQUE_MESSAGE_ID1 = "message1";
46    private static final String UNIQUE_MESSAGE_ID2 = "message2";
47    private static final String UNIQUE_MESSAGE_ID3 = "message3";
48    private static final String UNIQUE_MESSAGE_ID4 = "message4";
49    private static final String UNIQUE_MESSAGE_ID5 = "message5";
50   
 
51  1 toggle @Test
52    public void getAllErrorTest() throws Exception
53    {
54  1 MemoryMailStatusResult statusResult = new MemoryMailStatusResult();
55  1 ExtendedMimeMessage message1 = mock(ExtendedMimeMessage.class);
56  1 when(message1.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID1);
57  1 ExtendedMimeMessage message2 = mock(ExtendedMimeMessage.class);
58  1 when(message2.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID2);
59  1 ExtendedMimeMessage message3 = mock(ExtendedMimeMessage.class);
60  1 when(message3.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID3);
61  1 ExtendedMimeMessage message4 = mock(ExtendedMimeMessage.class);
62  1 when(message4.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID4);
63  1 ExtendedMimeMessage message5 = mock(ExtendedMimeMessage.class);
64  1 when(message5.getUniqueMessageId()).thenReturn(UNIQUE_MESSAGE_ID5);
65   
66  1 statusResult.setStatus(new MailStatus(BATCH_ID, message1, MailState.PREPARE_SUCCESS));
67  1 statusResult.setStatus(new MailStatus(BATCH_ID, message2, MailState.PREPARE_ERROR));
68  1 statusResult.setStatus(new MailStatus(BATCH_ID, message3, MailState.SEND_SUCCESS));
69  1 statusResult.setStatus(new MailStatus(BATCH_ID, message4, MailState.SEND_ERROR));
70  1 statusResult.setStatus(new MailStatus(BATCH_ID, message5, MailState.SEND_FATAL_ERROR));
71   
72  1 List<String> allErrorIds = new ArrayList<>();
73  1 Iterator<MailStatus> it = statusResult.getAllErrors();
74   
75  4 while (it.hasNext()) {
76  3 allErrorIds.add(it.next().getMessageId());
77    }
78   
79  1 assertThat(allErrorIds, containsInAnyOrder(UNIQUE_MESSAGE_ID2, UNIQUE_MESSAGE_ID4, UNIQUE_MESSAGE_ID5));
80  1 assertThat(allErrorIds.size(), equalTo(3));
81    }
82    }