1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
46 |
|
|
47 |
|
@version |
48 |
|
@since |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (40) |
Complexity: 2 |
Complexity Density: 0.05 |
|
50 |
|
public class SendMailConfigClassDocumentConfigurationSourceTest |
51 |
|
{ |
52 |
|
@Rule |
53 |
|
public MockitoComponentMockingRule<SendMailConfigClassDocumentConfigurationSource> mocker = |
54 |
|
new MockitoComponentMockingRule<>(SendMailConfigClassDocumentConfigurationSource.class); |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
56 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
93 |
1 |
@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 |
|
} |