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

File SendMailConfigClassDocumentConfigurationSourceTest.java

 

Code metrics

0
38
2
1
120
71
2
0.05
19
2
1

Classes

Class Line # Actions
SendMailConfigClassDocumentConfigurationSourceTest 50 38 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 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.configuration;
21   
22    import javax.inject.Provider;
23   
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.cache.Cache;
27    import org.xwiki.cache.CacheManager;
28    import org.xwiki.cache.config.CacheConfiguration;
29    import org.xwiki.model.reference.DocumentReference;
30    import org.xwiki.model.reference.LocalDocumentReference;
31    import org.xwiki.properties.ConverterManager;
32    import org.xwiki.test.mockito.MockitoComponentMockingRule;
33    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
34   
35    import com.xpn.xwiki.XWiki;
36    import com.xpn.xwiki.XWikiContext;
37    import com.xpn.xwiki.doc.XWikiDocument;
38    import com.xpn.xwiki.objects.BaseObject;
39    import com.xpn.xwiki.objects.BaseProperty;
40   
41    import static org.mockito.Mockito.*;
42    import static org.junit.Assert.*;
43   
44    /**
45    * Unit tests for {@link org.xwiki.mail.internal.configuration.SendMailConfigClassDocumentConfigurationSource}.
46    *
47    * @version $Id: 99d07bfcffcd3fd72c3e747bc8819c41ece798c5 $
48    * @since 6.4M2
49    */
 
50    public class SendMailConfigClassDocumentConfigurationSourceTest
51    {
52    @Rule
53    public MockitoComponentMockingRule<SendMailConfigClassDocumentConfigurationSource> mocker =
54    new MockitoComponentMockingRule<>(SendMailConfigClassDocumentConfigurationSource.class);
55   
 
56  1 toggle @Test
57    public void getPropertyWhenSendMailConfigClassXObjectExists() throws Exception
58    {
59  1 ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
60  1 when(converterManager.convert(String.class, "value")).thenReturn("value");
61   
62  1 Cache<Object> cache = mock(Cache.class);
63  1 CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
64  1 when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
65   
66  1 WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
67  1 when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
68   
69  1 LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
70   
71  1 BaseProperty property = mock(BaseProperty.class);
72  1 when(property.toText()).thenReturn("value");
73   
74  1 BaseObject object = mock(BaseObject.class);
75  1 when(object.getField("key")).thenReturn(property);
76   
77  1 XWikiDocument document = mock(XWikiDocument.class);
78  1 when(document.getXObject(classReference)).thenReturn(object);
79   
80  1 DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
81  1 XWiki xwiki = mock(XWiki.class);
82  1 when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
83   
84  1 XWikiContext xcontext = mock(XWikiContext.class);
85  1 when(xcontext.getWiki()).thenReturn(xwiki);
86   
87  1 Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
88  1 when(xcontextProvider.get()).thenReturn(xcontext);
89   
90  1 assertEquals("value", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
91    }
92   
 
93  1 toggle @Test
94    public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception
95    {
96  1 Cache<Object> cache = mock(Cache.class);
97  1 CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
98  1 when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
99   
100  1 WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
101  1 when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
102   
103  1 LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
104   
105  1 XWikiDocument document = mock(XWikiDocument.class);
106  1 when(document.getXObject(classReference)).thenReturn(null);
107   
108  1 DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
109  1 XWiki xwiki = mock(XWiki.class);
110  1 when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
111   
112  1 XWikiContext xcontext = mock(XWikiContext.class);
113  1 when(xcontext.getWiki()).thenReturn(xwiki);
114   
115  1 Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
116  1 when(xcontextProvider.get()).thenReturn(xcontext);
117   
118  1 assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
119    }
120    }