1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.listeners; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.junit.Before; |
27 |
|
import org.junit.Rule; |
28 |
|
import org.junit.Test; |
29 |
|
import org.xwiki.bridge.event.DocumentCreatedEvent; |
30 |
|
import org.xwiki.bridge.event.DocumentDeletedEvent; |
31 |
|
import org.xwiki.bridge.event.DocumentUpdatedEvent; |
32 |
|
import org.xwiki.lesscss.internal.cache.ColorThemeCache; |
33 |
|
import org.xwiki.lesscss.internal.cache.LESSResourcesCache; |
34 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReference; |
35 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory; |
36 |
|
import org.xwiki.lesscss.internal.colortheme.DocumentColorThemeReference; |
37 |
|
import org.xwiki.model.EntityType; |
38 |
|
import org.xwiki.model.reference.DocumentReference; |
39 |
|
import org.xwiki.model.reference.EntityReference; |
40 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
41 |
|
import org.xwiki.observation.event.Event; |
42 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
43 |
|
|
44 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
45 |
|
import com.xpn.xwiki.objects.BaseObject; |
46 |
|
|
47 |
|
import static org.junit.Assert.assertEquals; |
48 |
|
import static org.mockito.ArgumentMatchers.eq; |
49 |
|
import static org.mockito.Mockito.mock; |
50 |
|
import static org.mockito.Mockito.verify; |
51 |
|
import static org.mockito.Mockito.verifyZeroInteractions; |
52 |
|
import static org.mockito.Mockito.when; |
53 |
|
|
54 |
|
|
55 |
|
@link |
56 |
|
|
57 |
|
@since |
58 |
|
@version |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (51) |
Complexity: 6 |
Complexity Density: 0.13 |
|
60 |
|
public class ColorThemeListenerTest |
61 |
|
{ |
62 |
|
@Rule |
63 |
|
public MockitoComponentMockingRule<ColorThemeListener> mocker = |
64 |
|
new MockitoComponentMockingRule<>(ColorThemeListener.class); |
65 |
|
|
66 |
|
private LESSResourcesCache lessResourcesCache; |
67 |
|
|
68 |
|
private ColorThemeCache colorThemeCache; |
69 |
|
|
70 |
|
private ColorThemeReferenceFactory colorThemeReferenceFactory; |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
72 |
5 |
@Before... |
73 |
|
public void setUp() throws Exception |
74 |
|
{ |
75 |
5 |
lessResourcesCache = mocker.getInstance(LESSResourcesCache.class); |
76 |
5 |
colorThemeCache = mocker.getInstance(ColorThemeCache.class); |
77 |
5 |
colorThemeReferenceFactory = mocker.getInstance(ColorThemeReferenceFactory.class); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
80 |
1 |
@Test... |
81 |
|
public void getName() throws Exception |
82 |
|
{ |
83 |
1 |
assertEquals("LESS Color Theme Listener", mocker.getComponentUnderTest().getName()); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void getEvents() throws Exception |
88 |
|
{ |
89 |
1 |
List<Event> eventsToObserve = Arrays.<Event>asList( |
90 |
|
new DocumentCreatedEvent(), |
91 |
|
new DocumentUpdatedEvent(), |
92 |
|
new DocumentDeletedEvent()); |
93 |
|
|
94 |
1 |
assertEquals(eventsToObserve, mocker.getComponentUnderTest().getEvents()); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
97 |
1 |
@Test... |
98 |
|
public void onEventWhenFlamingoThemeChanged() throws Exception |
99 |
|
{ |
100 |
|
|
101 |
1 |
Event event = mock(Event.class); |
102 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
103 |
1 |
Object data = new Object(); |
104 |
|
|
105 |
1 |
EntityReference classReference = new LocalDocumentReference("FlamingoThemesCode", "ThemeClass"); |
106 |
1 |
List<BaseObject> objects = new ArrayList<>(); |
107 |
1 |
BaseObject object = mock(BaseObject.class); |
108 |
1 |
objects.add(object); |
109 |
1 |
when(doc.getXObjects(classReference)).thenReturn(objects); |
110 |
|
|
111 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
112 |
1 |
when(doc.getDocumentReference()).thenReturn(documentReference); |
113 |
|
|
114 |
1 |
ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null); |
115 |
1 |
when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference); |
116 |
|
|
117 |
|
|
118 |
1 |
mocker.getComponentUnderTest().onEvent(event, doc, data); |
119 |
|
|
120 |
|
|
121 |
1 |
verify(lessResourcesCache).clearFromColorTheme(colorThemeReference); |
122 |
1 |
verify(colorThemeCache).clearFromColorTheme(colorThemeReference); |
123 |
|
} |
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
125 |
1 |
@Test... |
126 |
|
public void onEventWhenColorThemeChanged() throws Exception |
127 |
|
{ |
128 |
|
|
129 |
1 |
Event event = mock(Event.class); |
130 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
131 |
1 |
Object data = new Object(); |
132 |
|
|
133 |
1 |
EntityReference classReference = new LocalDocumentReference("ColorThemes", "ColorThemeClass"); |
134 |
1 |
List<BaseObject> objects = new ArrayList<>(); |
135 |
1 |
BaseObject object = mock(BaseObject.class); |
136 |
1 |
objects.add(object); |
137 |
1 |
when(doc.getXObjects(classReference)).thenReturn(objects); |
138 |
|
|
139 |
1 |
DocumentReference documentReference = new DocumentReference("wiki", "space", "page"); |
140 |
1 |
when(doc.getDocumentReference()).thenReturn(documentReference); |
141 |
|
|
142 |
1 |
ColorThemeReference colorThemeReference = new DocumentColorThemeReference(documentReference, null); |
143 |
1 |
when(colorThemeReferenceFactory.createReference(eq(documentReference))).thenReturn(colorThemeReference); |
144 |
|
|
145 |
|
|
146 |
1 |
mocker.getComponentUnderTest().onEvent(event, doc, data); |
147 |
|
|
148 |
|
|
149 |
1 |
verify(lessResourcesCache).clearFromColorTheme(colorThemeReference); |
150 |
1 |
verify(colorThemeCache).clearFromColorTheme(colorThemeReference); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
public void onEventWhenNoObject() throws Exception |
155 |
|
{ |
156 |
|
|
157 |
1 |
Event event = mock(Event.class); |
158 |
1 |
XWikiDocument doc = mock(XWikiDocument.class); |
159 |
1 |
Object data = new Object(); |
160 |
|
|
161 |
1 |
EntityReference classReference = new EntityReference("ColorThemeClass", EntityType.DOCUMENT, |
162 |
|
new EntityReference("ColorThemes", EntityType.SPACE)); |
163 |
1 |
List<BaseObject> objects = new ArrayList<>(); |
164 |
1 |
when(doc.getXObjects(classReference)).thenReturn(objects); |
165 |
|
|
166 |
|
|
167 |
1 |
mocker.getComponentUnderTest().onEvent(event, doc, data); |
168 |
|
|
169 |
|
|
170 |
1 |
verifyZeroInteractions(lessResourcesCache); |
171 |
1 |
verifyZeroInteractions(colorThemeCache); |
172 |
|
} |
173 |
|
} |