1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.icon.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
29 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
30 |
|
import org.xwiki.component.manager.ComponentLookupException; |
31 |
|
import org.xwiki.icon.IconSetCache; |
32 |
|
import org.xwiki.model.reference.DocumentReference; |
33 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
34 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
35 |
|
import org.xwiki.observation.event.Event; |
36 |
|
|
37 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
38 |
|
import com.xpn.xwiki.objects.BaseObject; |
39 |
|
|
40 |
|
import static org.junit.Assert.assertEquals; |
41 |
|
import static org.junit.Assert.assertTrue; |
42 |
|
import static org.mockito.ArgumentMatchers.any; |
43 |
|
import static org.mockito.ArgumentMatchers.eq; |
44 |
|
import static org.mockito.Mockito.atLeastOnce; |
45 |
|
import static org.mockito.Mockito.mock; |
46 |
|
import static org.mockito.Mockito.never; |
47 |
|
import static org.mockito.Mockito.verify; |
48 |
|
import static org.mockito.Mockito.when; |
49 |
|
|
50 |
|
|
51 |
|
@link |
52 |
|
|
53 |
|
@since |
54 |
|
@version |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (34) |
Complexity: 6 |
Complexity Density: 0.21 |
|
56 |
|
public class IconThemeListenerTest |
57 |
|
{ |
58 |
|
@Rule |
59 |
|
public MockitoComponentMockingRule<IconThemeListener> mocker = |
60 |
|
new MockitoComponentMockingRule<>(IconThemeListener.class); |
61 |
|
|
62 |
|
private IconSetCache iconSetCache; |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
5 |
@Before... |
65 |
|
public void setUp() throws ComponentLookupException |
66 |
|
{ |
67 |
5 |
iconSetCache = mocker.getInstance(IconSetCache.class); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void onEvent() throws Exception |
72 |
|
{ |
73 |
|
|
74 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
75 |
1 |
List<BaseObject> list = new ArrayList<BaseObject>(); |
76 |
1 |
BaseObject obj = mock(BaseObject.class); |
77 |
1 |
list.add(obj); |
78 |
1 |
when(obj.getStringValue("name")).thenReturn("icontheme1"); |
79 |
|
|
80 |
1 |
DocumentReference docRef = new DocumentReference("wikiA", "b", "c"); |
81 |
1 |
when(doc.getDocumentReference()).thenReturn(docRef); |
82 |
|
|
83 |
1 |
LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass"); |
84 |
1 |
when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list); |
85 |
|
|
86 |
|
|
87 |
1 |
mocker.getComponentUnderTest().onEvent(null, doc, null); |
88 |
|
|
89 |
|
|
90 |
1 |
verify(iconSetCache, atLeastOnce()).clear(docRef); |
91 |
1 |
verify(iconSetCache, atLeastOnce()).clear("icontheme1", "wikiA"); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
public void onEventWhenNoObjects() throws Exception |
96 |
|
{ |
97 |
|
|
98 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
99 |
1 |
when(doc.getXObject(any(DocumentReference.class))).thenReturn(null); |
100 |
|
|
101 |
|
|
102 |
1 |
mocker.getComponentUnderTest().onEvent(null, doc, null); |
103 |
|
|
104 |
|
|
105 |
1 |
verify(iconSetCache, never()).clear(any(DocumentReference.class)); |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
108 |
1 |
@Test... |
109 |
|
public void onEventWhenEmptyListObjects() throws Exception |
110 |
|
{ |
111 |
|
|
112 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
113 |
1 |
List<BaseObject> list = new ArrayList<BaseObject>(); |
114 |
|
|
115 |
1 |
LocalDocumentReference iconThemeClassRef = new LocalDocumentReference("IconThemesCode", "IconThemeClass"); |
116 |
1 |
when(doc.getXObjects(eq(iconThemeClassRef))).thenReturn(list); |
117 |
|
|
118 |
|
|
119 |
1 |
mocker.getComponentUnderTest().onEvent(null, doc, null); |
120 |
|
|
121 |
|
|
122 |
1 |
verify(iconSetCache, never()).clear(any(DocumentReference.class)); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void getEvents() throws Exception |
127 |
|
{ |
128 |
1 |
List<Event> results = mocker.getComponentUnderTest().getEvents(); |
129 |
|
|
130 |
|
|
131 |
1 |
assertEquals(2, results.size()); |
132 |
1 |
assertTrue(results.get(0) instanceof DocumentUpdatedEvent); |
133 |
1 |
assertTrue(results.get(1) instanceof DocumentDeletedEvent); |
134 |
|
} |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
136 |
1 |
@Test... |
137 |
|
public void getName() throws Exception |
138 |
|
{ |
139 |
1 |
assertEquals("Icon Theme listener.", mocker.getComponentUnderTest().getName()); |
140 |
|
} |
141 |
|
|
142 |
|
} |