public static void applyLocaleToContext(@NonNull Context context, @Nullable String localeString) {
    final Locale forceLocale = LocaleTools.getLocaleForLocaleString(localeString);

    final Configuration configuration = context.getResources().getConfiguration();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      configuration.setLocale(forceLocale);
    } else {
      //noinspection deprecation
      configuration.locale = forceLocale;
    }
    context.getResources().updateConfiguration(configuration, null);
  }
@Test
  @Config(sdk = Build.VERSION_CODES.LOLLIPOP)
  public void testSetAndResetValueAPI21() {
    Assert.assertEquals(
        "English (United States)",
        mContext.getResources().getConfiguration().locale.getDisplayName());

    LocaleTools.applyLocaleToContext(mContext, "ru");

    Assert.assertEquals("ru", mContext.getResources().getConfiguration().locale.getLanguage());
    Assert.assertEquals(
        "Russian", mContext.getResources().getConfiguration().locale.getDisplayName());

    LocaleTools.applyLocaleToContext(mContext, "");

    Assert.assertEquals(
        Locale.getDefault().getLanguage(),
        mContext.getResources().getConfiguration().locale.getLanguage());

    LocaleTools.applyLocaleToContext(mContext, "NONE_EXISTING");
    // in this API level, Android is more strict, we can not set invalid values.
    Assert.assertEquals("en", mContext.getResources().getConfiguration().locale.getLanguage());
  }