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