01: package org.strecks.message;
02:
03: /*
04: * Copyright 2005-2006 the original author or authors.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
07: * in compliance with the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software distributed under the License
12: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13: * or implied. See the License for the specific language governing permissions and limitations under
14: * the License.
15: */
16:
17: import static org.testng.Assert.assertEquals;
18:
19: import java.util.Locale;
20:
21: import org.apache.struts.util.MessageResources;
22: import org.apache.struts.util.MessageResourcesFactory;
23: import org.apache.struts.util.PropertyMessageResourcesFactory;
24: import org.testng.annotations.BeforeMethod;
25: import org.testng.annotations.Test;
26:
27: public class TestMessageResourcesHelper {
28:
29: protected MessageResources resources;
30:
31: @BeforeMethod
32: public void beforeClass() {
33: MessageResourcesFactory factory = new PropertyMessageResourcesFactory();
34: resources = factory
35: .createResources("org.strecks.message.TestMessageResources");
36: }
37:
38: @Test(expectedExceptions=IllegalArgumentException.class)
39: public void testNull() {
40: new MessageResourcesHelperImpl(Locale.getDefault(), null);
41: }
42:
43: @Test
44: public void testDefaultLocale() {
45: MessageResourcesHelperImpl impl = new MessageResourcesHelperImpl(
46: Locale.getDefault(), resources);
47: assertEquals(impl.getMessage("message.with.no.params"),
48: "Message with no params");
49: assertEquals(impl.getMessage("message.with.five.params", "one",
50: 1, 3L, "four", 5),
51: "Message with five params one, 1, 3, four, 5");
52: }
53:
54: @Test
55: public void testNullLocale() {
56: MessageResourcesHelperImpl impl = new MessageResourcesHelperImpl(
57: null, resources);
58: assertEquals(impl.getMessage("message.with.no.params"),
59: "Message with no params");
60: }
61:
62: @Test
63: public void testGermanLocale() {
64: MessageResourcesHelperImpl impl = new MessageResourcesHelperImpl(
65: Locale.GERMAN, resources);
66: assertEquals(impl.getMessage("message.with.no.params"),
67: "Mit keinen params");
68: assertEquals(impl.getMessage("message.with.five.params", "one",
69: 1, 3L, "four", 5), "Mit funf params one, 1, 3, four, 5");
70: }
71:
72: }
|