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 java.util.Locale;
18:
19: import org.apache.tapestry.ioc.test.IOCTestCase;
20: import org.testng.annotations.Test;
21:
22: public class LocalizedNameGeneratorTest extends IOCTestCase {
23:
24: private void run(String path, Locale locale, String... expected) {
25: LocalizedNameGenerator g = new LocalizedNameGenerator(path,
26: locale);
27:
28: for (String s : expected) {
29: assertTrue(g.hasNext());
30: assertEquals(g.next(), s);
31: }
32:
33: assertFalse(g.hasNext());
34: }
35:
36: @Test
37: public void locale_with_language_and_country() {
38: run("basic.test", Locale.US, "basic_en_US.test",
39: "basic_en.test", "basic.test");
40: }
41:
42: @Test
43: public void locale_with_just_language() {
44: run("noCountry.zap", Locale.FRENCH, "noCountry_fr.zap",
45: "noCountry.zap");
46: }
47:
48: @Test
49: public void locale_with_variant_but_no_country() {
50:
51: // The double-underscore is correct, it's a kind
52: // of placeholder for the null country.
53: // JDK1.3 always converts the locale to upper case. JDK 1.4
54: // does not. To keep this test happyt, we selected an all-uppercase
55: // locale.
56:
57: run("fred.foo", new Locale("en", "", "GEEK"),
58: "fred_en__GEEK.foo", "fred_en.foo", "fred.foo");
59: }
60: }
|