1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.test.cts; |
21 |
|
|
22 |
|
import java.lang.reflect.Method; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.junit.runner.notification.Failure; |
26 |
|
import org.junit.runner.notification.RunNotifier; |
27 |
|
import org.junit.runners.BlockJUnit4ClassRunner; |
28 |
|
import org.junit.runners.model.FrameworkMethod; |
29 |
|
import org.junit.runners.model.InitializationError; |
30 |
|
import org.junit.runners.model.Statement; |
31 |
|
import org.xwiki.test.jmock.XWikiComponentInitializer; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
@since |
38 |
|
|
|
|
| 84.8% |
Uncovered Elements: 5 (33) |
Complexity: 11 |
Complexity Density: 0.46 |
|
39 |
|
public class RenderingTestClassRunner extends BlockJUnit4ClassRunner |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
private XWikiComponentInitializer componentInitializer = new XWikiComponentInitializer(); |
45 |
|
|
46 |
|
|
47 |
|
@see |
48 |
|
|
49 |
|
private Object testInstance; |
50 |
|
|
51 |
|
|
52 |
|
@see |
53 |
|
|
54 |
|
private TestData testData; |
55 |
|
|
56 |
|
|
57 |
|
@see |
58 |
|
|
59 |
|
private String metadataSyntaxId; |
60 |
|
|
61 |
|
|
62 |
|
@param |
63 |
|
|
64 |
|
@param@link |
65 |
|
@param |
66 |
|
@param |
67 |
|
@throws@link |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
69 |
537 |
RenderingTestClassRunner(Object testInstance, Class<?> testClass, TestData testData, String metadataSyntaxId)... |
70 |
|
throws InitializationError |
71 |
|
{ |
72 |
537 |
super(testClass); |
73 |
537 |
this.testInstance = testInstance; |
74 |
537 |
this.testData = testData; |
75 |
537 |
this.metadataSyntaxId = metadataSyntaxId; |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
78 |
537 |
@Override... |
79 |
|
public Object createTest() throws Exception |
80 |
|
{ |
81 |
537 |
return getTestClass().getOnlyConstructor().newInstance( |
82 |
|
this.testData, this.metadataSyntaxId, this.componentInitializer.getComponentManager()); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
1074 |
@Override... |
86 |
|
protected String getName() |
87 |
|
{ |
88 |
1074 |
return this.testData.computeTestName(); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
537 |
@Override... |
92 |
|
protected String testName(final FrameworkMethod method) |
93 |
|
{ |
94 |
537 |
return getName(); |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
537 |
@Override... |
98 |
|
protected void validateConstructor(List<Throwable> errors) |
99 |
|
{ |
100 |
537 |
validateOnlyOneConstructor(errors); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
103 |
537 |
@Override... |
104 |
|
protected Statement classBlock(RunNotifier notifier) |
105 |
|
{ |
106 |
537 |
return childrenInvoker(notifier); |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
@inheritDoc |
111 |
|
|
112 |
|
|
113 |
|
@link |
114 |
|
|
115 |
|
|
116 |
|
|
|
|
| 70.6% |
Uncovered Elements: 5 (17) |
Complexity: 5 |
Complexity Density: 0.33 |
|
117 |
537 |
@Override... |
118 |
|
protected void runChild(FrameworkMethod method, RunNotifier notifier) |
119 |
|
{ |
120 |
537 |
try { |
121 |
537 |
this.componentInitializer.initializeConfigurationSource(); |
122 |
537 |
this.componentInitializer.initializeExecution(); |
123 |
|
} catch (Exception e) { |
124 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), |
125 |
|
new RuntimeException("Failed to initialize Component Manager", e))); |
126 |
|
} |
127 |
|
|
128 |
|
|
129 |
537 |
try { |
130 |
537 |
for (Method klassMethod : this.testInstance.getClass().getMethods()) { |
131 |
4833 |
Initialized componentManagerAnnotation = klassMethod.getAnnotation(Initialized.class); |
132 |
4833 |
if (componentManagerAnnotation != null) { |
133 |
|
|
134 |
0 |
klassMethod.invoke(this.testInstance, this.componentInitializer.getComponentManager()); |
135 |
|
} |
136 |
|
} |
137 |
|
} catch (Exception e) { |
138 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), |
139 |
|
new RuntimeException("Failed to call Component Manager initialization method", e))); |
140 |
|
} |
141 |
|
|
142 |
537 |
try { |
143 |
537 |
super.runChild(method, notifier); |
144 |
|
} finally { |
145 |
537 |
try { |
146 |
537 |
this.componentInitializer.shutdown(); |
147 |
|
} catch (Exception e) { |
148 |
0 |
notifier.fireTestFailure(new Failure(getDescription(), |
149 |
|
new RuntimeException("Failed to shutdown Component Manager", e))); |
150 |
|
} |
151 |
|
} |
152 |
|
} |
153 |
|
} |