|
1 | | -/* |
2 | | - * Licensed to the Apache Software Foundation (ASF) under one |
3 | | - * or more contributor license agreements. See the NOTICE file |
4 | | - * distributed with this work for additional information |
5 | | - * regarding copyright ownership. The ASF licenses this file |
6 | | - * to you under the Apache License, Version 2.0 (the |
7 | | - * "License"); you may not use this file except in compliance |
8 | | - * with the License. You may obtain a copy of the License at |
9 | | - * |
10 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | - * |
12 | | - * Unless required by applicable law or agreed to in writing, |
13 | | - * software distributed under the License is distributed on an |
14 | | - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | | - * KIND, either express or implied. See the License for the |
16 | | - * specific language governing permissions and limitations |
17 | | - * under the License. |
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 | | - * A utility class used to provide internationalisation support. |
29 | | - * |
30 | | - * @author John Keyes |
31 | | - */ |
32 | | -public class ResourceHelperTest extends TestCase { |
33 | | - /** system property */ |
34 | | - private static final String PROP_LOCALE = "org.apache.commons.cli2.resource.bundle"; |
35 | | - |
36 | | - private static ResourceHelper helper; |
37 | | - |
38 | | - /** resource bundle */ |
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 | | - * Create a new ResourceHelper for the specified class. |
52 | | - * |
53 | | - * @param clazz the Class that requires some resources |
54 | | - */ |
55 | | - public ResourceHelperTest() { |
56 | | - super("ResourceHelperTest"); |
57 | | - } |
58 | | - |
59 | | - public void testOverridden() { |
60 | | - assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); |
61 | | - } |
62 | | - |
63 | | - public void testNewMessage1Param() { |
64 | | - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message")); |
65 | | - } |
66 | | - |
67 | | - public void testNewMessage2Params() { |
68 | | - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some")); |
69 | | - } |
70 | | - |
71 | | - public void testNewMessage3Params() { |
72 | | - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might")); |
73 | | - } |
74 | | - |
75 | | - public void testNewMessage4Params() { |
76 | | - assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might", "say")); |
77 | | - } |
78 | | - |
79 | | - public void testDefaultBundle() { |
80 | | - System.setProperty(PROP_LOCALE, "madeupname.properties"); |
81 | | - helper = ResourceHelper.getResourceHelper(); |
82 | | - assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); |
83 | | - } |
84 | | -} |
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 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 | + * A utility class used to provide internationalisation support. |
| 29 | + * |
| 30 | + * @author John Keyes |
| 31 | + */ |
| 32 | +public class ResourceHelperTest extends TestCase { |
| 33 | + /** system property */ |
| 34 | + private static final String PROP_LOCALE = "org.apache.commons.cli2.resource.bundle"; |
| 35 | + |
| 36 | + private static ResourceHelper helper; |
| 37 | + |
| 38 | + /** resource bundle */ |
| 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 | + * Create a new ResourceHelper for the specified class. |
| 52 | + * |
| 53 | + * @param clazz the Class that requires some resources |
| 54 | + */ |
| 55 | + public ResourceHelperTest() { |
| 56 | + super("ResourceHelperTest"); |
| 57 | + } |
| 58 | + |
| 59 | + public void testOverridden() { |
| 60 | + assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); |
| 61 | + } |
| 62 | + |
| 63 | + public void testNewMessage1Param() { |
| 64 | + assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message")); |
| 65 | + } |
| 66 | + |
| 67 | + public void testNewMessage2Params() { |
| 68 | + assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some")); |
| 69 | + } |
| 70 | + |
| 71 | + public void testNewMessage3Params() { |
| 72 | + assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might")); |
| 73 | + } |
| 74 | + |
| 75 | + public void testNewMessage4Params() { |
| 76 | + assertEquals("wrong message", "Some might say we will find a brighter day.", helper.getMessage("test.message", "Some", "might", "say")); |
| 77 | + } |
| 78 | + |
| 79 | + public void testDefaultBundle() { |
| 80 | + System.setProperty(PROP_LOCALE, "madeupname.properties"); |
| 81 | + helper = ResourceHelper.getResourceHelper(); |
| 82 | + assertEquals("wrong message", "The class name \"ResourceHelper\" is invalid.", helper.getMessage("ClassValidator.bad.classname", "ResourceHelper")); |
| 83 | + } |
| 84 | +} |
0 commit comments