01: package abbot.i18n;
02:
03: import java.io.File;
04: import java.io.FileOutputStream;
05: import java.util.Locale;
06: import java.util.MissingResourceException;
07: import java.util.Properties;
08: import junit.extensions.abbot.TestHelper;
09:
10: /** Test Resource loading. */
11: public class StringsTest extends junit.framework.TestCase {
12:
13: public void testMissingResource() throws Throwable {
14: File dir = TestHelper.getClasspathDirectory(StringsTest.class);
15: Properties p = new Properties();
16: p.put("default.properties.loaded", "yes");
17: p.store(new FileOutputStream(new File(dir, "test.properties")),
18: "test");
19: Strings.addBundle("test");
20: Locale oldLocale = Locale.getDefault();
21: try {
22: Locale.setDefault(Locale.FRENCH);
23: String name = "NoSuchResource";
24: assertEquals("Missing resource will be a flagged key", "#"
25: + name + "#", Strings.get(name));
26:
27: assertEquals(
28: "Missing i18n resource should get default value",
29: "yes", Strings.get("default.properties.loaded"));
30: } finally {
31: Locale.setDefault(oldLocale);
32: }
33: }
34:
35: public void testMissingPropertyFile() throws Throwable {
36: try {
37: Strings.addBundle("missing", getClass().getClassLoader());
38: fail("Expected a MissingResourceException");
39: } catch (MissingResourceException e) {
40: }
41: }
42:
43: public void testAlternateResource() throws Throwable {
44: File dir = TestHelper.getClasspathDirectory(StringsTest.class);
45: Properties p = new Properties();
46: p.put("test.property", "some value");
47: p.store(new FileOutputStream(new File(dir, "test.properties")),
48: "test");
49: Strings.addBundle("test", getClass().getClassLoader());
50: assertTrue("Should be able to load additional properties",
51: Strings.get("test.property") != null);
52:
53: }
54:
55: public static void main(String[] args) {
56: TestHelper.runTests(args, StringsTest.class);
57: }
58: }
|