1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.aikiit.spamprotector.util;
19
20 import org.junit.Test;
21
22 import java.util.Locale;
23
24 import static de.aikiit.spamprotector.util.LocalizationHelper.*;
25
26 import static org.junit.Assert.assertEquals;
27
28
29
30
31 public class LocalizationHelperTest {
32
33
34
35
36 @Test
37 public final void checkParametrizedValueExtraction() {
38 assertEquals("Erfolg und dann folgt noch die 7", getParameterizedBundleString("spamschutz.test.param",
39 "Erfolg", 7));
40
41 assertEquals("{0} und dann folgt noch die {1}", getParameterizedBundleString("spamschutz.test.param",
42 new Object[]{}));
43 }
44
45 @Test
46 public final void fallbackLocale() {
47
48 System.setProperty("user.language", "");
49 System.setProperty("user.country", "");
50 setLocale();
51
52 assertEquals(Locale.GERMANY, getLocale());
53 assertEquals("de", getLanguage());
54 }
55
56 @Test
57 public final void setLocaleViaSystemProperties() {
58
59 final String french = "fr";
60 System.setProperty("user.language", french);
61 System.setProperty("user.country", "CA");
62 setLocale();
63
64 assertEquals(Locale.CANADA_FRENCH, getLocale());
65 assertEquals(french, getLanguage());
66 }
67
68 @Test
69 public final void umlautEncodingWorksCorrectly() {
70 assertEquals("ßäü", getBundleString("spamschutz.test.umlauts"));
71 }
72
73 @Test
74 public final void unknownKey() {
75 String unknown = "abcde.unknown";
76 assertEquals(unknown, getBundleString(unknown));
77 }
78 }