1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.filter.test.integration; |
21 |
|
|
22 |
|
import java.lang.annotation.ElementType; |
23 |
|
import java.lang.annotation.Retention; |
24 |
|
import java.lang.annotation.RetentionPolicy; |
25 |
|
import java.lang.annotation.Target; |
26 |
|
import java.lang.reflect.Method; |
27 |
|
import java.util.ArrayList; |
28 |
|
import java.util.Collections; |
29 |
|
import java.util.List; |
30 |
|
|
31 |
|
import org.junit.runner.Description; |
32 |
|
import org.junit.runner.Runner; |
33 |
|
import org.junit.runner.notification.Failure; |
34 |
|
import org.junit.runner.notification.RunNotifier; |
35 |
|
import org.junit.runners.BlockJUnit4ClassRunner; |
36 |
|
import org.junit.runners.Suite; |
37 |
|
import org.junit.runners.model.FrameworkMethod; |
38 |
|
import org.junit.runners.model.InitializationError; |
39 |
|
import org.junit.runners.model.Statement; |
40 |
|
import org.xwiki.component.manager.ComponentManager; |
41 |
|
import org.xwiki.test.mockito.MockitoComponentManager; |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 94.7% |
Uncovered Elements: 1 (19) |
Complexity: 5 |
Complexity Density: 0.36 |
|
48 |
|
public class FilterTestSuite extends Suite |
49 |
|
{ |
50 |
|
private static final TestDataGenerator GENERATOR = new TestDataGenerator(); |
51 |
|
|
52 |
|
private static final String DEFAULT_PATTERN = ".*\\.test"; |
53 |
|
|
54 |
|
private final Object klassInstance; |
55 |
|
|
56 |
|
@Retention(RetentionPolicy.RUNTIME) |
57 |
|
@Target(ElementType.METHOD) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
58 |
|
public static @interface Initialized |
59 |
|
{ |
60 |
|
} |
61 |
|
|
62 |
|
@Retention(RetentionPolicy.RUNTIME) |
63 |
|
@Target(ElementType.TYPE) |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
64 |
|
public static @interface Scope |
65 |
|
{ |
66 |
|
|
67 |
|
@return |
68 |
|
|
69 |
|
String value() default ""; |
70 |
|
|
71 |
|
|
72 |
|
@return |
73 |
|
|
74 |
|
String pattern() default DEFAULT_PATTERN; |
75 |
|
} |
76 |
|
|
|
|
| 84.6% |
Uncovered Elements: 6 (39) |
Complexity: 15 |
Complexity Density: 0.6 |
|
77 |
|
private class TestClassRunnerForParameters extends BlockJUnit4ClassRunner |
78 |
|
{ |
79 |
|
private final MockitoComponentManager mockitoComponentManager = new MockitoComponentManager(); |
80 |
|
|
81 |
|
private final TestConfiguration configuration; |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
32 |
TestClassRunnerForParameters(Class< ? > type, TestConfiguration configuration) throws InitializationError... |
84 |
|
{ |
85 |
32 |
super(type); |
86 |
|
|
87 |
32 |
this.configuration = configuration; |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
32 |
@Override... |
91 |
|
public Object createTest() throws Exception |
92 |
|
{ |
93 |
32 |
return getTestClass().getOnlyConstructor().newInstance( |
94 |
|
new Object[] {this.configuration, getComponentManager()}); |
95 |
|
} |
96 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
97 |
64 |
@Override... |
98 |
|
protected String getName() |
99 |
|
{ |
100 |
64 |
return this.configuration.name != null ? this.configuration.name : super.getName(); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
32 |
@Override... |
104 |
|
protected String testName(final FrameworkMethod method) |
105 |
|
{ |
106 |
32 |
return getName(); |
107 |
|
} |
108 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
109 |
32 |
@Override... |
110 |
|
protected void validateConstructor(List<Throwable> errors) |
111 |
|
{ |
112 |
32 |
validateOnlyOneConstructor(errors); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
115 |
32 |
@Override... |
116 |
|
protected Statement classBlock(RunNotifier notifier) |
117 |
|
{ |
118 |
32 |
return childrenInvoker(notifier); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
@link |
123 |
|
|
124 |
|
|
|
|
| 75% |
Uncovered Elements: 3 (12) |
Complexity: 3 |
Complexity Density: 0.3 |
|
125 |
32 |
@Override... |
126 |
|
protected void runChild(FrameworkMethod method, RunNotifier notifier) |
127 |
|
{ |
128 |
32 |
initializeComponentManager(notifier); |
129 |
|
|
130 |
|
|
131 |
32 |
try { |
132 |
32 |
for (Method klassMethod : klassInstance.getClass().getMethods()) { |
133 |
289 |
Initialized componentManagerAnnotation = klassMethod.getAnnotation(Initialized.class); |
134 |
289 |
if (componentManagerAnnotation != null) { |
135 |
|
|
136 |
0 |
klassMethod.invoke(klassInstance, getComponentManager()); |
137 |
|
} |
138 |
|
} |
139 |
|
} catch (Exception e) { |
140 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), new RuntimeException( |
141 |
|
"Failed to call Component Manager initialization method", e))); |
142 |
|
} |
143 |
|
|
144 |
32 |
try { |
145 |
32 |
super.runChild(method, notifier); |
146 |
|
} finally { |
147 |
32 |
shutdownComponentManager(notifier); |
148 |
|
} |
149 |
|
} |
150 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
151 |
32 |
private void initializeComponentManager(RunNotifier notifier)... |
152 |
|
{ |
153 |
32 |
try { |
154 |
32 |
this.mockitoComponentManager.initializeTest(klassInstance); |
155 |
32 |
this.mockitoComponentManager.registerMemoryConfigurationSource(); |
156 |
|
} catch (Exception e) { |
157 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), new RuntimeException( |
158 |
|
"Failed to initialize Component Manager", e))); |
159 |
|
} |
160 |
|
|
161 |
|
} |
162 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
163 |
32 |
private void shutdownComponentManager(RunNotifier notifier)... |
164 |
|
{ |
165 |
32 |
try { |
166 |
32 |
this.mockitoComponentManager.shutdownTest(); |
167 |
|
} catch (Exception e) { |
168 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), new RuntimeException( |
169 |
|
"Failed to shutdown Component Manager", e))); |
170 |
|
} |
171 |
|
} |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
173 |
32 |
private ComponentManager getComponentManager() throws Exception... |
174 |
|
{ |
175 |
32 |
return this.mockitoComponentManager; |
176 |
|
} |
177 |
|
} |
178 |
|
|
179 |
|
private final ArrayList<Runner> runners = new ArrayList<Runner>(); |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 3 |
Complexity Density: 0.25 |
|
184 |
3 |
public FilterTestSuite(Class< ? > klass) throws Throwable... |
185 |
|
{ |
186 |
3 |
super(klass, Collections.<Runner> emptyList()); |
187 |
|
|
188 |
3 |
try { |
189 |
3 |
this.klassInstance = klass.newInstance(); |
190 |
|
} catch (Exception e) { |
191 |
0 |
throw new RuntimeException("Failed to construct instance of [" + klass.getName() + "]", e); |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
3 |
Scope scopeAnnotation = klass.getAnnotation(Scope.class); |
196 |
3 |
String packagePrefix = ""; |
197 |
3 |
String pattern = DEFAULT_PATTERN; |
198 |
3 |
if (scopeAnnotation != null) { |
199 |
2 |
packagePrefix = scopeAnnotation.value(); |
200 |
2 |
pattern = scopeAnnotation.pattern(); |
201 |
|
} |
202 |
|
|
203 |
3 |
for (TestConfiguration testConfiguration : GENERATOR.generateData(packagePrefix, pattern)) { |
204 |
32 |
this.runners.add(new TestClassRunnerForParameters(FilterTest.class, testConfiguration)); |
205 |
|
} |
206 |
|
} |
207 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
3 |
@Override... |
209 |
|
protected List<Runner> getChildren() |
210 |
|
{ |
211 |
3 |
return this.runners; |
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
|
@inheritDoc |
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
221 |
6 |
@Override... |
222 |
|
public Description getDescription() |
223 |
|
{ |
224 |
6 |
return Description.createSuiteDescription(getTestClass().getJavaClass()); |
225 |
|
} |
226 |
|
} |