LocaleHelper { public static Locale getLocale() { return getLocale(OFFApplication.getInstance()); } private  LocaleHelper(); static int find(List<LanguageData> availableLanguageForImage, String language); static Context setLocale(Context context, Locale locale); static Context onCreate(Context context); static Context onCreate(Context context, String defaultLanguage); static List<LanguageData> getLanguageData(Collection<String> codes, boolean supported); static LanguageData getLanguageData(String code, boolean supported); static Locale getLocale(); @SuppressWarnings("unused") static Context setLocale(Locale locale); static String getLanguage(Context context); static String getLCOrDefault(String languageCode); static Locale getLocale(Context context); static Context setLocale(Context context, String language); static Locale getLocale(String locale); static final String USER_COUNTRY_PREFERENCE_KEY; }
@Test public void getLocale_fr() { Locale locale = LocaleHelper.getLocale("fr"); assertThat(locale).isEqualTo(Locale.FRENCH); }
@Test public void getLocale_en() { Locale locale = LocaleHelper.getLocale("en"); assertThat(locale).isEqualTo(Locale.ENGLISH); }
@Test public void getLocale_en_US() { Locale locale = LocaleHelper.getLocale("en-US"); assertThat(locale).isEqualTo(Locale.US); }
@Test public void getLocale_FromContext(){ Context context = Mockito.mock(Context.class); Resources resources = Mockito.mock(Resources.class); Configuration configuration = Mockito.mock(Configuration.class); Locale locale = LocaleHelper.getLocale("en-US"); configuration.locale = locale; Mockito.when(context.getResources()).thenReturn(resources); Mockito.when(resources.getConfiguration()).thenReturn(configuration); assertThat(LocaleHelper.getLocale(context)).isEqualTo(locale); }