1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.mail.internal.factory.group

File GroupMimeMessageFactoryTest.java

 

Code metrics

0
25
4
1
113
74
8
0.32
6.25
4
2

Classes

Class Line # Actions
GroupMimeMessageFactoryTest 47 25 0% 8 4
0.8620689586.2%
 

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.factory.group;
21   
22    import java.util.Collections;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import javax.inject.Provider;
27    import javax.mail.MessagingException;
28   
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.component.util.DefaultParameterizedType;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.test.mockito.MockitoComponentMockingRule;
35   
36    import static org.junit.Assert.assertEquals;
37    import static org.junit.Assert.fail;
38    import static org.mockito.Mockito.when;
39   
40    /**
41    * Unit tests for {@link org.xwiki.mail.internal.factory.group.GroupMimeMessageFactory}.
42    *
43    * @version $Id: 84e0772e277796b2e54f2de2bdb690749029a0ef $
44    * @since 6.4.1
45    */
46    @Deprecated
 
47    public class GroupMimeMessageFactoryTest
48    {
49    @Rule
50    public MockitoComponentMockingRule<GroupMimeMessageFactory> mocker =
51    new MockitoComponentMockingRule<>(GroupMimeMessageFactory.class);
52   
 
53  1 toggle @Test
54    public void createMessageWhenNullParametersPassed() throws Exception
55    {
56  1 DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
57   
58  1 try {
59  1 this.mocker.getComponentUnderTest().createMessage(groupReference, null);
60  0 fail("Should have thrown an exception");
61    } catch (MessagingException expected) {
62  1 assertEquals("You must pass parameters for this Mime Message Factory to work!", expected.getMessage());
63    }
64    }
65   
 
66  1 toggle @Test
67    public void createMessageWhenNoHintParameterPassed() throws Exception
68    {
69  1 DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
70   
71  1 try {
72  1 this.mocker.getComponentUnderTest().createMessage(groupReference, Collections.<String, Object>emptyMap());
73  0 fail("Should have thrown an exception");
74    } catch (MessagingException expected) {
75  1 assertEquals("The parameter [hint] is mandatory.", expected.getMessage());
76    }
77    }
78   
 
79  1 toggle @Test
80    public void createMessageWhenNoSourceParameterPassed() throws Exception
81    {
82  1 DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
83   
84  1 try {
85  1 this.mocker.getComponentUnderTest().createMessage(groupReference,
86    Collections.<String, Object>singletonMap("hint", "factoryHint"));
87  0 fail("Should have thrown an exception");
88    } catch (MessagingException expected) {
89  1 assertEquals("The parameter [source] is mandatory.", expected.getMessage());
90    }
91    }
92   
 
93  1 toggle @Test
94    public void createMessageWhenNotExistingMimeMessageFactory() throws Exception
95    {
96  1 DocumentReference groupReference = new DocumentReference("wiki", "space", "page");
97  1 Map<String, Object> parameters = new HashMap<>();
98  1 parameters.put("hint", "factoryHint");
99  1 parameters.put("source", "factorySource");
100   
101  1 Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(
102    new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
103  1 when(componentManagerProvider.get()).thenReturn(this.mocker);
104   
105  1 try {
106  1 this.mocker.getComponentUnderTest().createMessage(groupReference, parameters);
107  0 fail("Should have thrown an exception");
108    } catch (MessagingException expected) {
109  1 assertEquals("Failed to find a [MimeMessageFactory<MimeMessage>] for hint [factoryHint]",
110    expected.getMessage());
111    }
112    }
113    }