1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.cli2.resource;
20
21 import java.util.Locale;
22 import java.util.MissingResourceException;
23 import java.util.ResourceBundle;
24
25 import junit.framework.TestCase;
26
27
28
29
30
31
32 public class ResourceHelperTest extends TestCase {
33
34 private static final String PROP_LOCALE = "org.apache.commons.cli2.resource.bundle";
35
36 private static ResourceHelper helper;
37
38
39 private ResourceBundle bundle;
40
41 public void setUp() {
42 System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.TestBundle");
43 helper = ResourceHelper.getResourceHelper();
44 }
45
46 public void tearDown() {
47 System.setProperty(PROP_LOCALE, "org.apache.commons.cli2.resource.CLIMessageBundle_en_US.properties");
48 }
49
50
51
52
53 public ResourceHelperTest() {
54 super("ResourceHelperTest");
55 }
56
57 public void testOverridden() {
58 assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper"));
59 }
60
61 public void testNewMessage1Param() {
62 assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message"));
63 }
64
65 public void testNewMessage2Params() {
66 assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some"));
67 }
68
69 public void testNewMessage3Params() {
70 assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might"));
71 }
72
73 public void testNewMessage4Params() {
74 assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might", "say"));
75 }
76
77 public void testDefaultBundle() {
78 System.setProperty(PROP_LOCALE, "madeupname.properties");
79 helper = ResourceHelper.getResourceHelper();
80 assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper"));
81 }
82 }