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

File UsersMimeMessageFactoryTest.java

 

Code metrics

0
25
4
1
114
75
8
0.32
6.25
4
2

Classes

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