package org.apache.maven.xdoc.util;

/* ====================================================================
 *   Copyright 2001-2004 The Apache Software Foundation.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 * ====================================================================
 */
import java.util.Locale;

import org.apache.maven.xdoc.util.LocaleUtil;

import junit.framework.TestCase;

/**
 * LocaleUtil Test class. 
 *
 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
 * @version $Id$
 */
public class LocaleUtilTest extends TestCase {

  public void testCodeToLocale1() {
    Locale locale = LocaleUtil.codeToLocale("en");
    assertEquals(locale.toString(), "en");
  }

  public void testCodeToLocale2() {
    Locale locale = LocaleUtil.codeToLocale("en_CA");
    assertEquals(locale.toString(), "en_CA");
  }
  
  public void testCodeToLocaleAsNull() {
    Locale locale = LocaleUtil.codeToLocale(null);
    assertNull(locale);
  }

  public void testCodeToLocaleAsDefault() {
    Locale locale = LocaleUtil.codeToLocale("default");
    assertEquals(locale, Locale.getDefault());
  }
  
  public void testCodesToLocales() {
    Locale[] locales = LocaleUtil.codesToLocales("en, en_CA");
    assertEquals(locales[0].toString(), "en");
    assertEquals(locales[1].toString(), "en_CA");
  }
  
  public void testCodesToLocalesAsNull() {
    Locale[] locales = LocaleUtil.codesToLocales(null);
    assertNull(locales);
  }
  
  public void testDisplayName() {
    Locale locale = new Locale("fr");
    String result = LocaleUtil.displayName(locale, locale);
    assertEquals(result, "Fran\u00e7ais");
  }
}
