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

File RecipientConverterTest.java

 

Code metrics

0
10
3
1
77
44
4
0.4
3.33
3
1.33

Classes

Class Line # Actions
RecipientConverterTest 38 10 0% 4 1
0.923076992.3%
 

Contributing tests

This file is covered by 3 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.Message;
23    import javax.mail.internet.MimeMessage;
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.RecipientConverter}.
34    *
35    * @version $Id: 17379ff094ed559a8184bd6a715aa7b6ccf3f9c5 $
36    * @since 6.1RC1
37    */
 
38    public class RecipientConverterTest
39    {
40    @Rule
41    public MockitoComponentMockingRule<RecipientConverter> mocker =
42    new MockitoComponentMockingRule<>(RecipientConverter.class);
43   
 
44  1 toggle @Test
45    public void convert() throws Exception
46    {
47  1 assertEquals(Message.RecipientType.TO,
48    this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, "to"));
49  1 assertEquals("To",
50    this.mocker.getComponentUnderTest().convert(String.class, Message.RecipientType.TO));
51   
52  1 assertEquals(Message.RecipientType.CC,
53    this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, "cc"));
54  1 assertEquals(Message.RecipientType.BCC,
55    this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, "bcc"));
56  1 assertEquals(MimeMessage.RecipientType.NEWSGROUPS,
57    this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, "newsgroups"));
58    }
59   
 
60  1 toggle @Test
61    public void convertWhenInvalidType() throws Exception
62    {
63  1 try {
64  1 this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, "something");
65  0 fail("Should have thrown an exception here");
66    } catch (ConversionException expected) {
67  1 assertEquals("Cannot convert [something] to [javax.mail.Message$RecipientType]", expected.getMessage());
68    }
69    }
70   
 
71  1 toggle @Test
72    public void convertWhenTypeIsAlreadyARecipientType() throws Exception
73    {
74  1 assertEquals(Message.RecipientType.TO,
75    this.mocker.getComponentUnderTest().convert(Message.RecipientType.class, Message.RecipientType.TO));
76    }
77    }