1   package org.apache.maven.xdoc.util;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  import java.util.Locale;
21  
22  import org.apache.maven.xdoc.util.LocaleUtil;
23  
24  import junit.framework.TestCase;
25  
26  /**
27   * LocaleUtil Test class. 
28   *
29   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
30   * @version $Id: LocaleUtilTest.java 532339 2007-04-25 12:28:56Z ltheussl $
31   */
32  public class LocaleUtilTest extends TestCase {
33  
34    public void testCodeToLocale1() {
35      Locale locale = LocaleUtil.codeToLocale("en");
36      assertEquals(locale.toString(), "en");
37    }
38  
39    public void testCodeToLocale2() {
40      Locale locale = LocaleUtil.codeToLocale("en_CA");
41      assertEquals(locale.toString(), "en_CA");
42    }
43    
44    public void testCodeToLocaleAsNull() {
45      Locale locale = LocaleUtil.codeToLocale(null);
46      assertNull(locale);
47    }
48  
49    public void testCodeToLocaleAsDefault() {
50      Locale locale = LocaleUtil.codeToLocale("default");
51      assertEquals(locale, Locale.getDefault());
52    }
53    
54    public void testCodesToLocales() {
55      Locale[] locales = LocaleUtil.codesToLocales("en, en_CA");
56      assertEquals(locales[0].toString(), "en");
57      assertEquals(locales[1].toString(), "en_CA");
58    }
59    
60    public void testCodesToLocalesAsNull() {
61      Locale[] locales = LocaleUtil.codesToLocales(null);
62      assertNull(locales);
63    }
64    
65    public void testDisplayName() {
66      Locale locale = new Locale("fr");
67      String result = LocaleUtil.displayName(locale, locale);
68      assertEquals(result, "Fran\u00e7ais");
69    }
70  }