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.getBundleString;
25 import static de.aikiit.spamprotector.util.LocalizationHelper.getLanguage;
26 import static de.aikiit.spamprotector.util.LocalizationHelper.getLocale;
27 import static de.aikiit.spamprotector.util.LocalizationHelper.getParameterizedBundleString;
28 import static de.aikiit.spamprotector.util.LocalizationHelper.setLocale;
29 import static org.assertj.core.api.Assertions.assertThat;
30
31
32
33
34 public class LocalizationHelperTest {
35
36
37
38
39 @Test
40 public final void checkParametrizedValueExtraction() {
41 assertThat(getParameterizedBundleString("spamschutz.test.param", "Erfolg", 7))
42 .isEqualTo("Erfolg und dann folgt noch die 7");
43
44 assertThat(getParameterizedBundleString("spamschutz.test.param", new Object[]{}))
45 .isEqualTo("{0} und dann folgt noch die {1}");
46 }
47
48 @Test
49 public final void fallbackLocale() {
50
51 System.setProperty("user.language", "");
52 System.setProperty("user.country", "");
53 setLocale();
54
55 assertThat(getLocale()).isEqualTo(Locale.GERMANY);
56 assertThat(getLanguage()).isEqualTo("de");
57 }
58
59 @Test
60 public final void setLocaleViaSystemProperties() {
61
62 final String french = "fr";
63 System.setProperty("user.language", french);
64 System.setProperty("user.country", "CA");
65 setLocale();
66
67 assertThat(getLocale()).isEqualTo(Locale.CANADA_FRENCH);
68 assertThat(getLanguage()).isEqualTo(french);
69 }
70
71 @Test
72 public final void umlautEncodingWorksCorrectly() {
73 assertThat(getBundleString("spamschutz.test.umlauts")).isEqualTo("ßäü");
74 }
75
76 @Test
77 public final void unknownKey() {
78 String unknown = "abcde.unknown";
79 assertThat(getBundleString(unknown)).isEqualTo(unknown);
80 }
81 }