1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.nls;
45
46 import static org.junit.Assert.assertEquals;
47 import static org.junit.Assert.fail;
48
49 import java.util.Locale;
50
51 import org.eclipse.jgit.errors.TranslationBundleLoadingException;
52 import org.eclipse.jgit.errors.TranslationStringMissingException;
53 import org.junit.Test;
54
55 public class TranslationBundleTest {
56
57 @Test
58 public void testMissingPropertiesFile() {
59 try {
60 new NoPropertiesBundle().load(NLS.ROOT_LOCALE);
61 fail("Expected TranslationBundleLoadingException");
62 } catch (TranslationBundleLoadingException e) {
63 assertEquals(NoPropertiesBundle.class, e.getBundleClass());
64 assertEquals(NLS.ROOT_LOCALE, e.getLocale());
65
66 }
67 }
68
69 @Test
70 public void testMissingString() {
71 try {
72 new MissingPropertyBundle().load(NLS.ROOT_LOCALE);
73 fail("Expected TranslationStringMissingException");
74 } catch (TranslationStringMissingException e) {
75 assertEquals("nonTranslatedKey", e.getKey());
76 assertEquals(MissingPropertyBundle.class, e.getBundleClass());
77 assertEquals(NLS.ROOT_LOCALE, e.getLocale());
78
79 }
80 }
81
82 @Test
83 public void testNonTranslatedBundle() {
84 NonTranslatedBundle bundle = new NonTranslatedBundle();
85
86 bundle.load(NLS.ROOT_LOCALE);
87 assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
88 assertEquals("Good morning {0}", bundle.goodMorning);
89
90 bundle.load(Locale.ENGLISH);
91 assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
92 assertEquals("Good morning {0}", bundle.goodMorning);
93
94 bundle.load(Locale.GERMAN);
95 assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
96 assertEquals("Good morning {0}", bundle.goodMorning);
97 }
98
99 @Test
100 public void testGermanTranslation() {
101 GermanTranslatedBundle bundle = new GermanTranslatedBundle();
102
103 bundle.load(NLS.ROOT_LOCALE);
104 assertEquals(NLS.ROOT_LOCALE, bundle.effectiveLocale());
105 assertEquals("Good morning {0}", bundle.goodMorning);
106
107 bundle.load(Locale.GERMAN);
108 assertEquals(Locale.GERMAN, bundle.effectiveLocale());
109 assertEquals("Guten Morgen {0}", bundle.goodMorning);
110 }
111
112 }