1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.core.context;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20 import static org.hamcrest.Matchers.nullValue;
21
22 import java.util.Locale;
23
24 import org.junit.Before;
25 import org.junit.Test;
26
27 import de.smartics.testdoc.annotations.Uut;
28
29
30
31
32 public class LocaleFinderCalcLocaleTest
33 {
34
35
36
37
38
39
40 @Uut(method = "calcLocale(String)")
41 private LocaleFinder uut;
42
43
44
45
46
47
48
49 @Before
50 public void setUp()
51 {
52 this.uut = new LocaleFinder();
53 }
54
55
56
57
58
59 @Test
60 public void returnsNullIfNoLocaleIsProvided()
61 {
62 final String urlString = "fileName.txt";
63 final Locale locale = uut.calcLocale(urlString);
64 assertThat(locale, is(nullValue()));
65 }
66
67 @Test
68 public void returnsNullIfNoLocaleIsProvidedWithPath()
69 {
70 final String urlString = "my/path/fileName.txt";
71 final Locale locale = uut.calcLocale(urlString);
72 assertThat(locale, is(nullValue()));
73 }
74
75 @Test
76 public void returnsNullIfNoLocaleIsProvidedOnAFileWithNoExtension()
77 {
78 final String urlString = "fileName";
79 final Locale locale = uut.calcLocale(urlString);
80 assertThat(locale, is(nullValue()));
81 }
82
83 @Test
84 public void returnsALanguageLocale()
85 {
86 final String urlString = "fileName_de.txt";
87 final Locale locale = uut.calcLocale(urlString);
88 assertThat(locale, is(Locale.GERMAN));
89 }
90
91 @Test
92 public void returnsACountryLocale()
93 {
94 final String urlString = "fileName_de_DE.txt";
95 final Locale locale = uut.calcLocale(urlString);
96 assertThat(locale, is(Locale.GERMANY));
97 }
98
99 @Test
100 public void returnsVariantLocale()
101 {
102 final String urlString = "fileName_de_DE_test.txt";
103 final Locale locale = uut.calcLocale(urlString);
104 assertThat(locale, is(new Locale("de", "DE", "test")));
105 }
106
107 @Test
108 public void returnsRecognizedTheLocaleRelevantPartInAFileName()
109 {
110 final String urlString = "file_name_de.txt";
111 final Locale locale = uut.calcLocale(urlString);
112 assertThat(locale, is(Locale.GERMAN));
113 }
114
115 @Test
116 public void returnsRecognizedTheLocaleRelevantPartInAFileNameEvenWithoutExtension()
117 {
118 final String urlString = "file_name_de";
119 final Locale locale = uut.calcLocale(urlString);
120 assertThat(locale, is(Locale.GERMAN));
121 }
122
123 @Test
124 public void separatorWithoutLocaleAtEndOfFileName()
125 {
126 final String urlString = "file_";
127 final Locale locale = uut.calcLocale(urlString);
128 assertThat(locale, is(nullValue()));
129 }
130
131 @Test
132 public void separatorWithLocaleAtEndOfFileName()
133 {
134 final String urlString = "fileName_de_DE_test_";
135 final Locale locale = uut.calcLocale(urlString);
136 assertThat(locale, is(new Locale("de", "DE", "test_")));
137 }
138 }