
package org.teavm.classlib.java.util;

import static org.junit.Assert.*;
import java.util.Locale;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.teavm.junit.TeaVMProperties;
import org.teavm.junit.TeaVMProperty;
import org.teavm.junit.TeaVMTestRunner;

@RunWith(TeaVMTestRunner.class)
@TeaVMProperties(@TeaVMProperty(key = "java.util.Locale.available", value = "en, en_US, en_GB, ru, ru_RU"))
public class LocaleTest {
    @Test
    public void availableLocalesFound() {
        assertNotEquals(0, Locale.getAvailableLocales().length);
    }

    @Test
    public void languageNamesProvided() {
        Locale english = new Locale("en", "");
        Locale usEnglish = new Locale("en", "US");
        Locale russian = new Locale("ru", "RU");
        assertEquals("English", english.getDisplayLanguage(english));
        assertEquals("English", english.getDisplayLanguage(usEnglish));
        assertEquals("Russian", russian.getDisplayLanguage(english));
        assertEquals("English", english.getDisplayLanguage(usEnglish));
        assertEquals("Russian", russian.getDisplayLanguage(usEnglish));
        assertEquals("английский", english.getDisplayLanguage(russian));
        assertEquals("русский", russian.getDisplayLanguage(russian));
    }

    @Test
    public void countryNamesProvided() {
        Locale usEnglish = new Locale("en", "US");
        Locale gbEnglish = new Locale("en", "GB");
        Locale russian = new Locale("ru", "RU");
        assertEquals("United Kingdom", gbEnglish.getDisplayCountry(usEnglish));
        assertEquals("United States", usEnglish.getDisplayCountry(usEnglish));
        assertEquals("Russia", russian.getDisplayCountry(usEnglish));
        // JVM gives here name that differs to the name provided by CLDR
        //assertEquals("Соединенное Королевство", gbEnglish.getDisplayCountry(russian));
        assertEquals("Соединенные Штаты", usEnglish.getDisplayCountry(russian));
        assertEquals("Россия", russian.getDisplayCountry(russian));
    }
}
