KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > services > impl > TestLocalizedPropertySource


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.services.impl;
16
17 import java.util.Locale JavaDoc;
18
19 import org.apache.hivemind.test.HiveMindTestCase;
20 import org.apache.tapestry.engine.IPropertySource;
21 import org.easymock.MockControl;
22
23 /**
24  * Tests for {@link org.apache.tapestry.services.impl.LocalizedPropertySource}.
25  *
26  * @author Howard M. Lewis Ship
27  * @since 4.0
28  */

29 public class TestLocalizedPropertySource extends HiveMindTestCase
30 {
31     public void testFound()
32     {
33         MockControl control = newControl(IPropertySource.class);
34         IPropertySource ps = (IPropertySource) control.getMock();
35
36         ps.getPropertyValue("property-name_en");
37         control.setReturnValue(null);
38
39         ps.getPropertyValue("property-name");
40         control.setReturnValue("fred");
41
42         replayControls();
43
44         LocalizedPropertySource lps = new LocalizedPropertySource(ps);
45
46         String JavaDoc result = lps.getPropertyValue("property-name", Locale.ENGLISH);
47
48         assertEquals("fred", result);
49
50         verifyControls();
51     }
52
53     public void testNotFound()
54     {
55         MockControl control = newControl(IPropertySource.class);
56         IPropertySource ps = (IPropertySource) control.getMock();
57
58         ps.getPropertyValue("property-name_fr");
59         control.setReturnValue(null);
60
61         ps.getPropertyValue("property-name");
62         control.setReturnValue(null);
63
64         replayControls();
65
66         LocalizedPropertySource lps = new LocalizedPropertySource(ps);
67
68         assertNull(lps.getPropertyValue("property-name", Locale.FRENCH));
69
70         verifyControls();
71     }
72 }
Popular Tags