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

File AddressConverterTest.java

 

Code metrics

0
9
4
1
75
42
5
0.56
2.25
4
1.25

Classes

Class Line # Actions
AddressConverterTest 38 9 0% 5 1
0.923076992.3%
 

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 AddressesConverter}.
34    *
35    * @version $Id: c3dbfcb871834057367a1d53f1549aaf6523c263 $
36    * @since 6.2M1
37    */
 
38    public class AddressConverterTest
39    {
40    @Rule
41    public MockitoComponentMockingRule<AddressConverter> mocker =
42    new MockitoComponentMockingRule<>(AddressConverter.class);
43   
 
44  1 toggle @Test
45    public void convert() throws Exception
46    {
47  1 InternetAddress address = new InternetAddress("John Doe(comment) <john1@doe.com>");
48  1 assertEquals(address,
49    this.mocker.getComponentUnderTest().convert(Address.class, "John Doe(comment) <john1@doe.com>"));
50    }
51   
 
52  1 toggle @Test
53    public void convertWhenNull() throws Exception
54    {
55  1 assertNull(this.mocker.getComponentUnderTest().convert(Address.class, null));
56    }
57   
 
58  1 toggle @Test
59    public void convertWhenTypeIsAlreadyAnAddress() throws Exception
60    {
61  1 InternetAddress address = new InternetAddress("John Doe(comment) <john1@doe.com>");
62  1 assertEquals(address, this.mocker.getComponentUnderTest().convert(Address.class, address));
63    }
64   
 
65  1 toggle @Test
66    public void convertWhenInvalid() throws Exception
67    {
68  1 try {
69  1 this.mocker.getComponentUnderTest().convert(Address.class, "invalid(");
70  0 fail("Should have thrown an exception here");
71    } catch (ConversionException expected) {
72  1 assertEquals("Failed to convert [invalid(] to [javax.mail.Address]", expected.getMessage());
73    }
74    }
75    }