1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.groovy.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.codehaus.groovy.ast.ClassNode; |
27 |
|
import org.codehaus.groovy.classgen.GeneratorContext; |
28 |
|
import org.codehaus.groovy.control.CompilationFailedException; |
29 |
|
import org.codehaus.groovy.control.CompilePhase; |
30 |
|
import org.codehaus.groovy.control.SourceUnit; |
31 |
|
import org.codehaus.groovy.control.customizers.CompilationCustomizer; |
32 |
|
import org.jmock.Expectations; |
33 |
|
import org.junit.Assert; |
34 |
|
import org.junit.Test; |
35 |
|
import org.xwiki.component.manager.ComponentManager; |
36 |
|
import org.xwiki.configuration.ConfigurationSource; |
37 |
|
import org.xwiki.groovy.GroovyCompilationCustomizer; |
38 |
|
import org.xwiki.groovy.GroovyConfiguration; |
39 |
|
import org.xwiki.test.jmock.AbstractMockingComponentTestCase; |
40 |
|
import org.xwiki.test.jmock.annotation.MockingRequirement; |
41 |
|
|
42 |
|
|
43 |
|
@link |
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
48 |
|
@MockingRequirement(DefaultGroovyConfiguration.class) |
|
|
| 95.8% |
Uncovered Elements: 1 (24) |
Complexity: 5 |
Complexity Density: 0.26 |
|
49 |
|
public class DefaultGroovyConfigurationTest extends AbstractMockingComponentTestCase<GroovyConfiguration> |
50 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void getCustomizersWhenNoCustomizersDeclared() throws Exception |
53 |
|
{ |
54 |
1 |
final ConfigurationSource source = getComponentManager().getInstance(ConfigurationSource.class); |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
55 |
1 |
getMockery().checking(new Expectations() {{... |
56 |
1 |
oneOf(source).getProperty("groovy.compilationCustomizers", Collections.emptyList()); |
57 |
1 |
will(returnValue(Collections.emptyList())); |
58 |
|
}}); |
59 |
|
|
60 |
1 |
List<CompilationCustomizer> customizers = getMockedComponent().getCompilationCustomizers(); |
61 |
1 |
Assert.assertEquals(0, customizers.size()); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void getCustomizersWhenCustomizersDeclared() throws Exception |
66 |
|
{ |
67 |
1 |
final ConfigurationSource source = getComponentManager().getInstance(ConfigurationSource.class); |
68 |
1 |
final ComponentManager componentManager = getComponentManager().getInstance(ComponentManager.class); |
69 |
1 |
final GroovyCompilationCustomizer customizer = getMockery().mock(GroovyCompilationCustomizer.class); |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
71 |
1 |
getMockery().checking(new Expectations() {{... |
72 |
1 |
oneOf(source).getProperty("groovy.compilationCustomizers", Collections.emptyList()); |
73 |
1 |
will(returnValue(Arrays.asList("mycustomizer"))); |
74 |
1 |
oneOf(componentManager).getInstance(GroovyCompilationCustomizer.class, "mycustomizer"); |
75 |
1 |
will(returnValue(customizer)); |
76 |
1 |
oneOf(customizer).createCustomizer(); |
77 |
1 |
will(returnValue(new CompilationCustomizer(CompilePhase.PARSING) |
78 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
79 |
0 |
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)... |
80 |
|
throws CompilationFailedException |
81 |
|
{ |
82 |
|
|
83 |
|
} |
84 |
|
})); |
85 |
|
}}); |
86 |
|
|
87 |
1 |
List<CompilationCustomizer> customizers = getMockedComponent().getCompilationCustomizers(); |
88 |
1 |
Assert.assertEquals(1, customizers.size()); |
89 |
1 |
Assert.assertTrue(customizers.get(0) instanceof CompilationCustomizer); |
90 |
|
} |
91 |
|
} |