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

File ScriptMimeMessageTest.java

 

Code metrics

0
15
6
1
93
55
6
0.4
2.5
6
1

Classes

Class Line # Actions
ScriptMimeMessageTest 41 15 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 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.script;
21   
22    import javax.mail.Address;
23    import javax.mail.Message;
24    import javax.mail.internet.InternetAddress;
25   
26    import org.junit.Before;
27    import org.junit.Test;
28    import org.xwiki.component.manager.ComponentManager;
29    import org.xwiki.context.Execution;
30   
31    import static org.junit.Assert.assertArrayEquals;
32    import static org.junit.Assert.assertEquals;
33    import static org.mockito.Mockito.mock;
34   
35    /**
36    * Unit tests for {@link ScriptMimeMessage}.
37    *
38    * @version $Id: ee240d1a7eed1a5cbcbe5405fcc27057b9c46c81 $
39    * @since 7.1M2
40    */
 
41    public class ScriptMimeMessageTest
42    {
43    private ScriptMimeMessage scriptMessage;
44   
 
45  5 toggle @Before
46    public void setUp() throws Exception
47    {
48  5 Execution execution = mock(Execution.class);
49  5 ComponentManager componentManager = mock(ComponentManager.class);
50   
51  5 this.scriptMessage = new ScriptMimeMessage(execution, componentManager);
52    }
53   
 
54  1 toggle @Test
55    public void setSubject() throws Exception
56    {
57  1 this.scriptMessage.setSubject("lorem ipsum");
58  1 assertEquals("lorem ipsum", this.scriptMessage.getSubject());
59    }
60   
 
61  1 toggle @Test
62    public void setFrom() throws Exception
63    {
64  1 this.scriptMessage.setFrom(InternetAddress.parse("john@doe.com")[0]);
65  1 assertArrayEquals(InternetAddress.parse("john@doe.com"), this.scriptMessage.getFrom());
66    }
67   
 
68  1 toggle @Test
69    public void addRecipients() throws Exception
70    {
71  1 Address[] address = InternetAddress.parse("john@doe.com,jane@doe.com,jannie@doe.com");
72  1 this.scriptMessage.addRecipients(Message.RecipientType.TO, address);
73  1 assertArrayEquals(address, this.scriptMessage.getRecipients(Message.RecipientType.TO));
74    }
75   
 
76  1 toggle @Test
77    public void addRecipient() throws Exception
78    {
79  1 this.scriptMessage.addRecipient(Message.RecipientType.TO, InternetAddress.parse("john@doe.com")[0]);
80  1 assertArrayEquals(InternetAddress.parse("john@doe.com"),
81    this.scriptMessage.getRecipients(Message.RecipientType.TO));
82    }
83   
 
84  1 toggle @Test
85    public void addHeader() throws Exception
86    {
87  1 String testHeader = "test";
88   
89  1 this.scriptMessage.addHeader("X-Test", testHeader);
90   
91  1 assertEquals(testHeader, this.scriptMessage.getHeader("X-Test", null));
92    }
93    }