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

File AddressesConverterTest.java

 

Code metrics

0
13
4
1
80
47
5
0.38
3.25
4
1.25

Classes

Class Line # Actions
AddressesConverterTest 38 13 0% 5 1
0.941176594.1%
 

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.internal;
21   
22    import javax.mail.Address;
23    import javax.mail.internet.InternetAddress;
24   
25    import org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.properties.converter.ConversionException;
28    import org.xwiki.test.mockito.MockitoComponentMockingRule;
29   
30    import static org.junit.Assert.*;
31   
32    /**
33    * Unit tests for {@link org.xwiki.mail.internal.AddressConverter}.
34    *
35    * @version $Id: 3ceccaf8341f083fb5840fed36741d1c3e60dcba $
36    * @since 6.1RC1
37    */
 
38    public class AddressesConverterTest
39    {
40    @Rule
41    public MockitoComponentMockingRule<AddressesConverter> mocker =
42    new MockitoComponentMockingRule<>(AddressesConverter.class);
43   
 
44  1 toggle @Test
45    public void convert() throws Exception
46    {
47  1 InternetAddress[] addresses = new InternetAddress[2];
48  1 addresses[0] = new InternetAddress("John Doe(comment) <john1@doe.com>");
49  1 addresses[1] = new InternetAddress("john2@doe.com");
50  1 assertArrayEquals(addresses, (InternetAddress[]) this.mocker.getComponentUnderTest().convert(Address[].class,
51    "John Doe(comment) <john1@doe.com>,john2@doe.com"));
52    }
53   
 
54  1 toggle @Test
55    public void convertWhenNull() throws Exception
56    {
57  1 assertNull(this.mocker.getComponentUnderTest().convert(Address.class, null));
58    }
59   
 
60  1 toggle @Test
61    public void convertWhenTypeIsAlreadyAnAddressArray() throws Exception
62    {
63  1 InternetAddress[] addresses = new InternetAddress[2];
64  1 addresses[0] = new InternetAddress("John Doe(comment) <john1@doe.com>");
65  1 addresses[1] = new InternetAddress("john2@doe.com");
66  1 assertArrayEquals(addresses,
67    (InternetAddress[]) this.mocker.getComponentUnderTest().convert(Address.class, addresses));
68    }
69   
 
70  1 toggle @Test
71    public void convertWhenInvalid() throws Exception
72    {
73  1 try {
74  1 this.mocker.getComponentUnderTest().convert(Address[].class, "invalid(");
75  0 fail("Should have thrown an exception here");
76    } catch (ConversionException expected) {
77  1 assertEquals("Failed to convert [invalid(] to an array of [javax.mail.Address]", expected.getMessage());
78    }
79    }
80    }