Skip to content

Commit 9eaacde

Browse files
committed
add tests for locale package
1 parent bf5155f commit 9eaacde

File tree

9 files changed

+104
-0
lines changed

9 files changed

+104
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package net.lecousin.framework.core.tests.locale;
2+
3+
import net.lecousin.framework.application.LCCore;
4+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
5+
6+
import org.junit.Assert;
7+
import org.junit.Test;
8+
9+
public class TestLibraryLocaleFile extends LCCoreAbstractTest {
10+
11+
@Test(timeout=30000)
12+
public void test() {
13+
Assert.assertEquals("This is a test", LCCore.getApplication().getLocalizedProperties().localizeSync(new String[] { "en" }, "test", "Test"));
14+
Assert.assertEquals("Ceci est un test", LCCore.getApplication().getLocalizedProperties().localizeSync(new String[] { "fr" }, "test", "Test"));
15+
}
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package net.lecousin.framework.core.tests.locale;
2+
3+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
4+
import net.lecousin.framework.locale.ILocalizableString;
5+
import net.lecousin.framework.locale.annotations.LocalizableAnnotations;
6+
import net.lecousin.framework.locale.annotations.LocalizableProperty;
7+
import net.lecousin.framework.properties.Property;
8+
9+
import org.junit.Assert;
10+
import org.junit.Test;
11+
12+
public class TestLocalizableAnnotations extends LCCoreAbstractTest {
13+
14+
@LocalizableProperty(name="hello", namespace="test", key="test")
15+
public String myTest;
16+
17+
@Property(name="hello2", value="bonjour2")
18+
public String myTest2;
19+
20+
@Test(timeout=30000)
21+
public void testGet() throws Exception {
22+
ILocalizableString ls;
23+
24+
ls = LocalizableAnnotations.get(this.getClass().getField("myTest"), "hello");
25+
Assert.assertEquals("this is a test", ls.localizeSync("en"));
26+
27+
ls = LocalizableAnnotations.get(this.getClass().getField("myTest2"), "hello2");
28+
Assert.assertEquals("bonjour2", ls.localizeSync("en"));
29+
30+
ls = LocalizableAnnotations.get(this.getClass().getField("myTest2"), "hello3");
31+
Assert.assertNull(ls);
32+
}
33+
34+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package net.lecousin.framework.core.tests.locale;
2+
3+
import net.lecousin.framework.application.ApplicationClassLoader;
4+
import net.lecousin.framework.application.LCCore;
5+
import net.lecousin.framework.concurrent.synch.ISynchronizationPoint;
6+
import net.lecousin.framework.core.test.LCCoreAbstractTest;
7+
import net.lecousin.framework.locale.LocalizedProperties;
8+
9+
import org.junit.Assert;
10+
import org.junit.Test;
11+
12+
public class TestLocalizedProperties extends LCCoreAbstractTest {
13+
14+
@Test(timeout=30000)
15+
public void testErrors() {
16+
LocalizedProperties lp = LCCore.getApplication().getLocalizedProperties();
17+
ApplicationClassLoader cl = LCCore.getApplication().getClassLoader();
18+
19+
ISynchronizationPoint<Exception> sp = lp.registerNamespace("test-error", "does/not/exist", cl);
20+
try {
21+
sp.blockThrow(0);
22+
throw new AssertionError("Loading a namespace that does not exist must fail");
23+
} catch (Exception e) {
24+
// normal
25+
}
26+
27+
lp.registerNamespace("test-error2", "locale/error", cl);
28+
String s = lp.localizeSync(new String[] { "fr" }, "test-error2", "hello");
29+
Assert.assertTrue(s.startsWith("!! no compatible language"));
30+
s = lp.localizeSync(new String[] { "en" }, "test-error2", "hello");
31+
Assert.assertTrue(s.startsWith("!! no compatible language"));
32+
s = lp.localizeSync(new String[] { "en-us" }, "test-error2", "hello");
33+
Assert.assertTrue(s.startsWith("!! no compatible language"));
34+
s = lp.localizeSync(new String[] { "in" }, "test-error2", "hello");
35+
Assert.assertTrue(s.startsWith("!! missing key"));
36+
s = lp.localizeSync(new String[] { "ph" }, "test-error2", "hello");
37+
Assert.assertTrue(s.startsWith("!! missing key"));
38+
}
39+
40+
@Test(timeout=30000)
41+
public void test() {
42+
LocalizedProperties lp = LCCore.getApplication().getLocalizedProperties();
43+
// for coverage
44+
lp.getAvailableLanguageCodes();
45+
}
46+
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test=locale/test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
en-us,in,ph
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hi=hi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test=this is a test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test=ceci est un test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
en,fr

0 commit comments

Comments
 (0)