1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.localization.jar.internal; |
21 |
|
|
22 |
|
import java.util.Locale; |
23 |
|
|
24 |
|
import org.junit.Assert; |
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.component.internal.ContextComponentManagerProvider; |
29 |
|
import org.xwiki.context.internal.DefaultExecution; |
30 |
|
import org.xwiki.localization.LocalizationManager; |
31 |
|
import org.xwiki.localization.Translation; |
32 |
|
import org.xwiki.localization.internal.DefaultLocalizationManager; |
33 |
|
import org.xwiki.localization.internal.DefaultTranslationBundleContext; |
34 |
|
import org.xwiki.localization.messagetool.internal.MessageToolTranslationMessageParser; |
35 |
|
import org.xwiki.model.internal.DefaultModelContext; |
36 |
|
import org.xwiki.rendering.internal.parser.plain.PlainTextBlockParser; |
37 |
|
import org.xwiki.test.annotation.ComponentList; |
38 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
39 |
|
|
40 |
|
@ComponentList({MessageToolTranslationMessageParser.class, PlainTextBlockParser.class, |
41 |
|
ContextComponentManagerProvider.class, DefaultLocalizationManager.class, DefaultTranslationBundleContext.class, |
42 |
|
DefaultExecution.class, DefaultModelContext.class, RootClassLoaderTranslationBundle.class}) |
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.44 |
|
43 |
|
public class RootClassLoaderTranslationBundleTest |
44 |
|
{ |
45 |
|
@Rule |
46 |
|
public final MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule(); |
47 |
|
|
48 |
|
private LocalizationManager localizationManager; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
1 |
@Before... |
51 |
|
public void setUp() throws Exception |
52 |
|
{ |
53 |
|
|
54 |
|
|
55 |
1 |
this.localizationManager = this.componentManager.getInstance(LocalizationManager.class); |
56 |
|
} |
57 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
58 |
3 |
private void assertTranslation(String key, String message, Locale locale)... |
59 |
|
{ |
60 |
3 |
Translation translation = this.localizationManager.getTranslation(key, locale); |
61 |
|
|
62 |
3 |
if (message != null) { |
63 |
3 |
Assert.assertNotNull("Could not find translation for key [" + key + "] and locale [" + locale + "]", |
64 |
|
translation); |
65 |
3 |
Assert.assertEquals(message, translation.getRawSource()); |
66 |
|
} else { |
67 |
0 |
Assert.assertNull("Found translation for key [" + key + "] and locale [" + locale + "]", translation); |
68 |
|
} |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void getTranslations() |
75 |
|
{ |
76 |
1 |
assertTranslation("test.key", "default translation", Locale.ROOT); |
77 |
1 |
assertTranslation("test.key", "en translation", Locale.ENGLISH); |
78 |
1 |
assertTranslation("test.key", "en_US translation", Locale.US); |
79 |
|
} |
80 |
|
} |