package net.sf.jabref.logic.l10n;

import java.util.Locale;

import net.sf.jabref.preferences.JabRefPreferences;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class LocalizationTest {

    private Locale locale;

    @Before
    public void storeDefaultLocale() {
        locale = Locale.getDefault();
    }

    @After
    public void restoreDefaultLocale() {
        Locale.setDefault(locale);
        javax.swing.JComponent.setDefaultLocale(locale);
        Localization.setLanguage(JabRefPreferences.getInstance().get(JabRefPreferences.LANGUAGE));
    }

    @Test
    public void testSetKnownLanguage() {
        Locale.setDefault(Locale.CHINA);
        Localization.setLanguage("en");
        assertEquals("en", Locale.getDefault().toString());
    }

    @Test
    public void testSetUnknownLanguage() {
        Locale.setDefault(Locale.CHINA);
        Localization.setLanguage("WHATEVER");
        assertEquals("en", Locale.getDefault().toString());
    }

    @Test
    public void testKnownTranslation() {
        Localization.setLanguage("en");
        String knownKey = "Groups";
        assertEquals(knownKey, Localization.lang(knownKey));
        assertEquals(knownKey, Localization.menuTitle(knownKey));
    }

    @Test
    public void testKnownTranslationWithCountryModifier() {
        Localization.setLanguage("en_US");
        String knownKey = "Groups";
        assertEquals(knownKey, Localization.lang(knownKey));
        assertEquals(knownKey, Localization.menuTitle(knownKey));
    }

    @Test
    public void testUnknownTranslation() {
        Localization.setLanguage("en");
        String knownKey = "WHATEVER";
        assertEquals(knownKey, Localization.lang(knownKey));
        assertEquals(knownKey, Localization.menuTitle(knownKey));
    }

    @Test
    public void testUnsetLanguageTranslation() {
        String knownKey = "Groups";
        assertEquals(knownKey, Localization.lang(knownKey));
        assertEquals(knownKey, Localization.menuTitle(knownKey));
    }

}

@@ -1235,37 +1235,104 @@
         
-assertEquals(knownKey
+String knownValueWithMnemonics = %22&Groups%22;%0A        assertEquals(knownValueWithMnemonics
 , Locali
@@ -1569,32 +1569,84 @@
 ang(knownKey));%0A
+        String knownValueWithMnemonics = %22&Groups%22;%0A
         assertEq
@@ -1647,35 +1647,50 @@
 sertEquals(known
-Key
+ValueWithMnemonics
 , Localization.m
@@ -2130,32 +2130,84 @@
 ang(knownKey));%0A
+        String knownValueWithMnemonics = %22&Groups%22;%0A
         assertEq
@@ -2208,35 +2208,50 @@
 sertEquals(known
-Key
+ValueWithMnemonics
 , Localization.m

fix failing localization tests