KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > util > TestLocalizedNameGenerator


1 // Copyright 2004, 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.hivemind.util;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import java.util.Locale JavaDoc;
20 import java.util.NoSuchElementException JavaDoc;
21
22 import junit.framework.AssertionFailedError;
23
24 import org.apache.hivemind.util.LocalizedNameGenerator;
25
26
27 /**
28  * Suite of tests for {@link org.apache.tapestry.util.LocalizedNameGenerator}.
29  *
30  * @author Howard Lewis Ship
31  */

32 public class TestLocalizedNameGenerator extends FrameworkTestCase
33 {
34
35     public void testBasic()
36     {
37         LocalizedNameGenerator g = new LocalizedNameGenerator("basic", Locale.US, ".test");
38
39         assertTrue(g.more());
40         assertEquals("basic_en_US.test", g.next());
41
42         assertTrue(g.more());
43         assertEquals("basic_en.test", g.next());
44
45         assertTrue(g.more());
46         assertEquals("basic.test", g.next());
47
48         assertTrue(!g.more());
49     }
50
51     public void testNoCountry()
52     {
53         LocalizedNameGenerator g = new LocalizedNameGenerator("noCountry", Locale.FRENCH, ".zap");
54
55         assertTrue(g.more());
56         assertEquals("noCountry_fr.zap", g.next());
57
58         assertTrue(g.more());
59         assertEquals("noCountry.zap", g.next());
60
61         assertTrue(!g.more());
62     }
63
64     public void testVariantWithoutCountry()
65     {
66         LocalizedNameGenerator g =
67             new LocalizedNameGenerator("fred", new Locale JavaDoc("en", "", "GEEK"), ".foo");
68
69         assertTrue(g.more());
70
71         // The double-underscore is correct, it's a kind
72
// of placeholder for the null country.
73
// JDK1.3 always converts the locale to upper case. JDK 1.4
74
// does not. To keep this test happyt, we selected an all-uppercase
75
// locale.
76

77         assertEquals("fred_en__GEEK.foo", g.next());
78
79         assertTrue(g.more());
80         assertEquals("fred_en.foo", g.next());
81
82         assertTrue(g.more());
83         assertEquals("fred.foo", g.next());
84
85         assertTrue(!g.more());
86     }
87
88     public void testNullLocale()
89     {
90         LocalizedNameGenerator g = new LocalizedNameGenerator("nullLocale", null, ".bar");
91
92         assertTrue(g.more());
93         assertEquals("nullLocale.bar", g.next());
94
95         assertTrue(!g.more());
96     }
97
98     public void testNullSuffix()
99     {
100         LocalizedNameGenerator g = new LocalizedNameGenerator("nullSuffix", null, null);
101
102         assertTrue(g.more());
103         assertEquals("nullSuffix", g.next());
104
105         assertTrue(!g.more());
106     }
107
108     public void testForException()
109     {
110         LocalizedNameGenerator g = new LocalizedNameGenerator("bob", null, ".foo");
111
112         assertTrue(g.more());
113         assertEquals("bob.foo", g.next());
114
115         assertTrue(!g.more());
116
117         try
118         {
119             g.next();
120
121             throw new AssertionFailedError("Unreachable.");
122         }
123         catch (NoSuchElementException JavaDoc ex)
124         {
125         }
126     }
127 }
128
Popular Tags