1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.component.wiki; |
21 |
|
|
22 |
|
import org.junit.Rule; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.component.descriptor.ComponentDescriptor; |
25 |
|
import org.xwiki.component.manager.ComponentManager; |
26 |
|
import org.xwiki.component.wiki.internal.DefaultWikiComponentManager; |
27 |
|
import org.xwiki.component.wiki.internal.WikiComponentManagerContext; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
30 |
|
|
31 |
|
import static org.mockito.ArgumentMatchers.*; |
32 |
|
import static org.mockito.Mockito.*; |
33 |
|
|
34 |
|
|
35 |
|
@link |
36 |
|
|
37 |
|
@version |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.08 |
|
39 |
|
public class DefaultWikiComponentManagerTest |
40 |
|
{ |
41 |
|
private static final DocumentReference DOC_REFERENCE = new DocumentReference("xwiki", "XWiki", "MyComponent"); |
42 |
|
|
43 |
|
private static final DocumentReference AUTHOR_REFERENCE = new DocumentReference("xwiki", "XWiki", "Admin"); |
44 |
|
|
45 |
|
@Rule |
46 |
|
public MockitoComponentMockingRule<DefaultWikiComponentManager> mocker = new MockitoComponentMockingRule<>( |
47 |
|
DefaultWikiComponentManager.class); |
48 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
49 |
1 |
@Test... |
50 |
|
public void registerAndUnregisterWikiComponent() throws Exception |
51 |
|
{ |
52 |
1 |
WikiComponentManagerContext wcmc = this.mocker.getInstance(WikiComponentManagerContext.class); |
53 |
1 |
when(wcmc.getCurrentEntityReference()).thenReturn(DOC_REFERENCE); |
54 |
1 |
when(wcmc.getCurrentUserReference()).thenReturn(AUTHOR_REFERENCE); |
55 |
|
|
56 |
1 |
WikiComponent component = new TestImplementation(DOC_REFERENCE, AUTHOR_REFERENCE, WikiComponentScope.WIKI); |
57 |
|
|
58 |
1 |
ComponentManager wikiComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "wiki"); |
59 |
|
|
60 |
|
|
61 |
1 |
this.mocker.getComponentUnderTest().registerWikiComponent(component); |
62 |
|
|
63 |
|
|
64 |
1 |
verify(wikiComponentManager, times(1)).registerComponent(any(ComponentDescriptor.class), eq(component)); |
65 |
|
|
66 |
|
|
67 |
1 |
this.mocker.getComponentUnderTest().registerWikiComponent(component); |
68 |
|
|
69 |
|
|
70 |
1 |
verify(wikiComponentManager, times(2)).registerComponent(any(ComponentDescriptor.class), eq(component)); |
71 |
|
|
72 |
|
|
73 |
1 |
this.mocker.getComponentUnderTest().unregisterWikiComponents(DOC_REFERENCE); |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
1 |
verify(wikiComponentManager, times(1)).unregisterComponent(TestRole.class, "roleHint"); |
79 |
|
|
80 |
|
|
81 |
1 |
this.mocker.getComponentUnderTest().unregisterWikiComponents(DOC_REFERENCE); |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
1 |
verify(wikiComponentManager, times(1)).unregisterComponent(TestRole.class, "roleHint"); |
86 |
|
} |
87 |
|
} |