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

File MailStatusTest.java

 

Code metrics

0
31
4
1
100
60
4
0.13
7.75
4
1

Classes

Class Line # Actions
MailStatusTest 37 31 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 4 tests. .

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;
21   
22    import java.util.Date;
23   
24    import javax.mail.Message;
25   
26    import org.junit.Test;
27   
28    import static org.junit.Assert.assertEquals;
29    import static org.junit.Assert.assertTrue;
30   
31    /**
32    * Unit tests for {@link MailStatus}.
33    *
34    * @version $Id: 265fde5cdf8afe2bffac543e7198755ea92604fd $
35    * @since 6.4RC1
36    */
 
37    public class MailStatusTest
38    {
 
39  1 toggle @Test
40    public void setError()
41    {
42  1 MailStatus status = new MailStatus();
43  1 status.setError(new Exception("outer", new Exception("inner")));
44   
45  1 assertEquals("Exception: inner", status.getErrorSummary());
46  1 assertTrue(status.getErrorDescription().contains("outer"));
47  1 assertTrue(status.getErrorDescription().contains("inner"));
48    }
49   
 
50  1 toggle @Test
51    public void verifyToStringWhenStatusHasNoError() throws Exception
52    {
53  1 ExtendedMimeMessage message = new ExtendedMimeMessage();
54  1 message.setHeader("Message-ID", "<local@domain>");
55  1 message.setType("type");
56  1 message.setRecipients(Message.RecipientType.TO, "john@doe.com");
57   
58  1 MailStatus status = new MailStatus("batchid", message, MailState.PREPARE_SUCCESS);
59  1 Date date = new Date();
60  1 status.setDate(date);
61   
62  1 assertEquals("messageId = [6ys1BeC6gnKA7srO/vs06XBZKZM=], batchId = [batchid], state = [prepare_success], date = ["
63    + date.toString() + "], recipients = [john@doe.com], type = [type]", status.toString());
64    }
65   
 
66  1 toggle @Test
67    public void verifyToStringWhenStatusHasError() throws Exception
68    {
69  1 ExtendedMimeMessage message = new ExtendedMimeMessage();
70  1 message.setHeader("Message-ID", "<local@domain>");
71  1 message.setType("type");
72  1 message.setRecipients(Message.RecipientType.TO, "john@doe.com");
73   
74  1 MailStatus status = new MailStatus("batchid", message, MailState.PREPARE_SUCCESS);
75  1 Date date = new Date();
76  1 status.setDate(date);
77  1 status.setError(new Exception("outer", new Exception("inner")));
78   
79  1 assertTrue(status.toString().startsWith("messageId = [6ys1BeC6gnKA7srO/vs06XBZKZM=], batchId = [batchid], "
80    + "state = [prepare_success], date = [" + date.toString() + "], recipients = [john@doe.com], "
81    + "type = [type], errorSummary = [Exception: inner], errorDescription = ["));
82    }
83   
 
84  1 toggle @Test
85    public void verifyToStringWhenWiki() throws Exception
86    {
87  1 ExtendedMimeMessage message = new ExtendedMimeMessage();
88  1 message.setHeader("Message-ID", "<local@domain>");
89  1 message.setType("type");
90  1 message.setRecipients(Message.RecipientType.TO, "john@doe.com");
91   
92  1 MailStatus status = new MailStatus("batchid", message, MailState.PREPARE_SUCCESS);
93  1 Date date = new Date();
94  1 status.setDate(date);
95  1 status.setWiki("wiki");
96   
97  1 assertEquals("messageId = [6ys1BeC6gnKA7srO/vs06XBZKZM=], batchId = [batchid], state = [prepare_success], date = ["
98    + date.toString() + "], recipients = [john@doe.com], type = [type], wiki = [wiki]", status.toString());
99    }
100    }