01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.ioc.internal.util;
16:
17: import org.apache.tapestry.ioc.MessageFormatter;
18: import org.apache.tapestry.ioc.Messages;
19: import org.apache.tapestry.ioc.test.IOCTestCase;
20: import org.testng.annotations.Test;
21:
22: public class MessagesImplTest extends IOCTestCase {
23: private final Messages _messages = MessagesImpl
24: .forClass(TargetMessages.class);
25:
26: @Test
27: public void contains_key() {
28: assertTrue(_messages.contains("no-args"));
29: assertFalse(_messages.contains("xyzzyx"));
30: }
31:
32: @Test
33: public void contains_key_is_case_insensitive() {
34: assertTrue(_messages.contains("No-Args"));
35: assertFalse(_messages.contains("Xyzzyx"));
36: }
37:
38: @Test
39: public void get_message_from_catalog() {
40: assertEquals(_messages.get("no-args"), "No arguments.");
41: assertEquals(_messages.get("something-failed"),
42: "Something failed: %s");
43: }
44:
45: @Test
46: public void get_message_from_catalog_is_case_insensitive() {
47: assertEquals(_messages.get("No-args"), "No arguments.");
48: assertEquals(_messages.get("Something-Failed"),
49: "Something failed: %s");
50: }
51:
52: @Test
53: public void get_unknown_message_from_catalog() {
54: assertEquals(_messages.get("does-not-exist"),
55: "[[missing key: does-not-exist]]");
56: }
57:
58: @Test
59: public void format_message() {
60: assertEquals(_messages.format("result", "good"),
61: "The result is 'good'.");
62: }
63:
64: @Test
65: public void format_message_is_case_insensitive() {
66: assertEquals(_messages.format("Result", "good"),
67: "The result is 'good'.");
68: }
69:
70: @Test
71: public void get_formatter() {
72: MessageFormatter mf = _messages.getFormatter("result");
73:
74: assertEquals(mf.format("great"), "The result is 'great'.");
75: }
76:
77: @Test
78: public void formatters_are_cached() {
79: MessageFormatter mf1 = _messages.getFormatter("result");
80: // Throw in a case-insensitive check:
81: MessageFormatter mf2 = _messages.getFormatter("Result");
82:
83: assertSame(mf2, mf1);
84: }
85:
86: @Test
87: public void format_unknown_key() {
88: assertEquals(_messages.format("rezult", "good"),
89: "[[missing key: rezult]]");
90: }
91: }
|