ReactAppController { String getValidLocaleFromCookie(String localeCookieValue) { String validLocale; try { Locale localeFromCookie = new Locale.Builder().setLanguageTag(localeCookieValue).build(); validLocale = localeFromCookie.toLanguageTag(); } catch (NullPointerException | IllformedLocaleException e) { logger.debug("Invalid localeCookieValue, fallback to en"); validLocale = "en"; } return validLocale; }    }
@Test public void testGetValidLocalFromCookie() { String localeCookieValue = "fr-FR"; ReactAppController instance = new ReactAppController(); String expResult = "fr-FR"; String result = instance.getValidLocaleFromCookie(localeCookieValue); assertEquals(expResult, result); }
@Test public void testGetValidLocalFromCookieInvalidValue() { String localeCookieValue = "dsfsazfsdf dsfdsfsfdsf"; ReactAppController instance = new ReactAppController(); String expResult = "en"; String result = instance.getValidLocaleFromCookie(localeCookieValue); assertEquals(expResult, result); }
@Test public void testGetValidLocalFromCookieNullValue() { String localeCookieValue = null; ReactAppController instance = new ReactAppController(); String expResult = "en"; String result = instance.getValidLocaleFromCookie(localeCookieValue); assertEquals(expResult, result); }