KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > TestComponentMessageAccess


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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;
16
17 import org.apache.hivemind.Messages;
18 import org.apache.hivemind.test.HiveMindTestCase;
19 import org.apache.tapestry.test.Creator;
20 import org.easymock.MockControl;
21
22 /**
23  * Tests support for several deprecated methods on {@link org.apache.tapestry.AbstractComponent}
24  * related to accessing localized messages. This test case may be removed in 4.1, when the
25  * corresponding methods are removed.
26  *
27  * @author Howard Lewis Ship
28  * @since 4.0
29  */

30 public class TestComponentMessageAccess extends HiveMindTestCase
31 {
32     private AbstractComponent newComponent(Messages messages)
33     {
34         Creator c = new Creator();
35
36         return (AbstractComponent) c.newInstance(AbstractComponent.class, new Object JavaDoc[]
37         { "messages", messages });
38     }
39
40     public void testGetMessage()
41     {
42         MockControl control = newControl(Messages.class);
43         Messages m = (Messages) control.getMock();
44
45         m.getMessage("fred");
46         control.setReturnValue("flintstone");
47
48         AbstractComponent ac = newComponent(m);
49
50         replayControls();
51
52         assertEquals("flintstone", ac.getMessage("fred"));
53
54         verifyControls();
55     }
56
57     public void testFormat()
58     {
59         MockControl control = newControl(Messages.class);
60         Messages m = (Messages) control.getMock();
61
62         m.format("fred", "flintstone");
63         control.setReturnValue("Fred Flintstone");
64
65         AbstractComponent ac = newComponent(m);
66
67         replayControls();
68
69         assertEquals("Fred Flintstone", ac.format("fred", "flintstone"));
70
71         verifyControls();
72
73         m.format("fred", "wilma", "dino");
74         control.setReturnValue("flintstone family");
75
76         replayControls();
77
78         assertEquals("flintstone family", ac.format("fred", "wilma", "dino"));
79
80         verifyControls();
81
82         m.format("fred", "wilma", "dino", "pebbles");
83         control.setReturnValue("flintstone family 2");
84
85         replayControls();
86
87         assertEquals("flintstone family 2", ac.format("fred", "wilma", "dino", "pebbles"));
88
89         verifyControls();
90
91         Object JavaDoc[] arguments = new String JavaDoc[]
92         { "flinstone" };
93
94         m.format("fred", arguments);
95         control.setReturnValue("flintstone family 3");
96
97         replayControls();
98
99         assertEquals("flintstone family 3", ac.format("fred", arguments));
100
101         verifyControls();
102
103     }
104 }
105
Popular Tags