1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
45 |
|
@RunWith(RenderingTestSuite.class) |
|
|
| 50% |
Uncovered Elements: 21 (42) |
Complexity: 16 |
Complexity Density: 0.67 |
|
46 |
|
public class IntegrationTests |
47 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
48 |
6 |
@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 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
60 |
6 |
{... |
61 |
6 |
allowing(localizationManager).getTranslation("some.translation", Locale.ENGLISH); |
62 |
6 |
will(returnValue(new Translation() |
63 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
64 |
3 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
0 |
@Override... |
72 |
|
public Block render(Object... parameters) |
73 |
|
{ |
74 |
0 |
return render(null, parameters); |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
@Override... |
78 |
|
public String getRawSource() |
79 |
|
{ |
80 |
0 |
return "entranslationmessagesource"; |
81 |
|
} |
82 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
83 |
0 |
@Override... |
84 |
|
public Locale getLocale() |
85 |
|
{ |
86 |
0 |
return Locale.ENGLISH; |
87 |
|
} |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
89 |
0 |
@Override... |
90 |
|
public String getKey() |
91 |
|
{ |
92 |
0 |
return "some.translation"; |
93 |
|
} |
94 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
0 |
@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 |
|
{ |
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
105 |
1 |
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
112 |
0 |
@Override... |
113 |
|
public Block render(Object... parameters) |
114 |
|
{ |
115 |
0 |
return render(null, parameters); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
118 |
0 |
@Override... |
119 |
|
public String getRawSource() |
120 |
|
{ |
121 |
0 |
return "frtranslationmessagesource"; |
122 |
|
} |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
@Override... |
125 |
|
public Locale getLocale() |
126 |
|
{ |
127 |
0 |
return Locale.FRENCH; |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
130 |
0 |
@Override... |
131 |
|
public String getKey() |
132 |
|
{ |
133 |
0 |
return "some.translation"; |
134 |
|
} |
135 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
0 |
@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 |
|
} |