1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.localization.macro

File IntegrationTests.java

 

Coverage histogram

../../../../img/srcFileCovDistChart5.png
74% of files have more coverage

Code metrics

4
24
14
1
151
107
16
0.67
1.71
14
1.14

Classes

Class Line # Actions
IntegrationTests 46 24 0% 16 21
0.550%
 

Contributing tests

This file is covered by 4 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.localization.macro;
21   
22    import java.util.Arrays;
23    import java.util.Locale;
24   
25    import org.jmock.Expectations;
26    import org.jmock.Mockery;
27    import org.jmock.integration.junit4.JUnit4Mockery;
28    import org.junit.runner.RunWith;
29    import org.xwiki.localization.TranslationBundle;
30    import org.xwiki.localization.LocalizationContext;
31    import org.xwiki.localization.LocalizationManager;
32    import org.xwiki.localization.Translation;
33    import org.xwiki.rendering.block.Block;
34    import org.xwiki.rendering.block.WordBlock;
35    import org.xwiki.rendering.test.integration.RenderingTestSuite;
36    import org.xwiki.test.jmock.MockingComponentManager;
37   
38    /**
39    * Run all tests found in {@code *.test} files located in the classpath. These {@code *.test} files must follow the
40    * conventions described in {@link org.xwiki.rendering.test.integration.TestDataParser}.
41    *
42    * @version $Id: a1bae6cbc7a929561ddfd1075e7a16efbed0c57d $
43    * @since 3.4M2
44    */
45    @RunWith(RenderingTestSuite.class)
 
46    public class IntegrationTests
47    {
 
48  6 toggle @RenderingTestSuite.Initialized
49    public void initialize(MockingComponentManager componentManager) throws Exception
50    {
51  6 Mockery mockery = new JUnit4Mockery();
52   
53  6 final LocalizationManager localizationManager =
54    componentManager.registerMockComponent(mockery, LocalizationManager.class);
55  6 final LocalizationContext localizationContext =
56    componentManager.registerMockComponent(mockery, LocalizationContext.class);
57   
58  6 mockery.checking(new Expectations()
59    {
 
60  6 toggle {
61  6 allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH);
62  6 will(returnValue(new Translation()
63    {
 
64  3 toggle @Override
65    public Block render(Locale locale, Object... parameters)
66    {
67  3 return parameters.length > 0 ? new WordBlock("entranslationmessage"
68    + Arrays.toString(parameters)) : new WordBlock("entranslationmessage");
69    }
70   
 
71  0 toggle @Override
72    public Block render(Object... parameters)
73    {
74  0 return render(null, parameters);
75    }
76   
 
77  0 toggle @Override
78    public String getRawSource()
79    {
80  0 return "entranslationmessagesource";
81    }
82   
 
83  0 toggle @Override
84    public Locale getLocale()
85    {
86  0 return Locale.ENGLISH;
87    }
88   
 
89  0 toggle @Override
90    public String getKey()
91    {
92  0 return "some.translation";
93    }
94   
 
95  0 toggle @Override
96    public TranslationBundle getBundle()
97    {
98  0 return null;
99    }
100    }));
101   
102  6 allowing(localizationManager).getTranslation("some.translation", Locale.FRENCH);
103  6 will(returnValue(new Translation()
104    {
 
105  1 toggle @Override
106    public Block render(Locale locale, Object... parameters)
107    {
108  1 return parameters.length > 0 ? new WordBlock("frtranslationmessage"
109    + Arrays.toString(parameters)) : new WordBlock("frtranslationmessage");
110    }
111   
 
112  0 toggle @Override
113    public Block render(Object... parameters)
114    {
115  0 return render(null, parameters);
116    }
117   
 
118  0 toggle @Override
119    public String getRawSource()
120    {
121  0 return "frtranslationmessagesource";
122    }
123   
 
124  0 toggle @Override
125    public Locale getLocale()
126    {
127  0 return Locale.FRENCH;
128    }
129   
 
130  0 toggle @Override
131    public String getKey()
132    {
133  0 return "some.translation";
134    }
135   
 
136  0 toggle @Override
137    public TranslationBundle getBundle()
138    {
139  0 return null;
140    }
141    }));
142   
143  6 allowing(localizationManager).getTranslation("unexisting.translation", Locale.ENGLISH);
144  6 will(returnValue(null));
145   
146  6 allowing(localizationContext).getCurrentLocale();
147  6 will(returnValue(Locale.ENGLISH));
148    }
149    });
150    }
151    }