1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.groovy.internal

File DefaultGroovyConfigurationTest.java

 

Code metrics

0
19
5
1
91
58
5
0.26
3.8
5
1

Classes

Class Line # Actions
DefaultGroovyConfigurationTest 49 19 0% 5 1
0.958333395.8%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link DefaultGroovyConfiguration}.
44    *
45    * @version $Id: d588334f63f85afacaa57162a15ad756bc070149 $
46    * @since 4.1M1
47    */
48    @MockingRequirement(DefaultGroovyConfiguration.class)
 
49    public class DefaultGroovyConfigurationTest extends AbstractMockingComponentTestCase<GroovyConfiguration>
50    {
 
51  1 toggle @Test
52    public void getCustomizersWhenNoCustomizersDeclared() throws Exception
53    {
54  1 final ConfigurationSource source = getComponentManager().getInstance(ConfigurationSource.class);
 
55  1 toggle 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   
 
64  1 toggle @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   
 
71  1 toggle 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    {
 
79  0 toggle @Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)
80    throws CompilationFailedException
81    {
82    // Stub for testing, do nothing.
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    }