ExternalResources { public String getString(@StringRes int resId) throws NotFoundException { String key = getApplicationResourceEntryName(resId); if (null == key) { throw new NotFoundException("String resource with resId: " + resId); } return getString(key); } private  ExternalResources(@NonNull Context context, @NonNull Converter converter,
      @NonNull Url url, @NonNull Options options, @Cache.Policy int cachePolicy,
      @Logger.Level int logLevel, @NonNull Resources defaultResources,
      @Nullable OnExternalResourcesLoadFailedListener failedListener,
      boolean useApplicationResources); @SuppressWarnings("ConstantConditions") static ExternalResources initialize(
      @NonNull Context context, Url url); @SuppressWarnings("ConstantConditions") static ExternalResources initialize(
      @NonNull Context context, @NonNull String baseUrl); @SuppressWarnings("ConstantConditions") static ExternalResources initialize(
      @NonNull ExternalResources externalResources); static ExternalResources getInstance(); void onConfigurationChanged(Configuration newConfig); boolean getBoolean(@BoolRes int resId); boolean getBoolean(@NonNull String key); @ColorInt int getColor(@ColorRes int resId); @ColorInt int getColor(@NonNull String key); float getDimension(@DimenRes int resId); float getDimension(@NonNull String key); String getString(@StringRes int resId); String getString(@NonNull String key); String getString(@StringRes int resId, Object... formatArgs); String getString(@NonNull String key, Object... formatArgs); String[] getStringArray(@ArrayRes int resId); String[] getStringArray(@NonNull String key); int getInteger(@IntegerRes int resId); int getInteger(@NonNull String key); int[] getIntArray(@ArrayRes int resId); int[] getIntArray(@NonNull String key); void register(OnExternalResourcesChangeListener listener); void unregister(OnExternalResourcesChangeListener listener); void removeFailListener(); static final String TAG; }
@Test public void testGetString() throws Exception { assertEquals(externalResources.getString("hello"), "Hello!"); assertEquals(externalResources.getString("hello_world"), "Hello world!"); assertEquals(externalResources.getString(R.string.hello_world), "Hello world!"); }
@SuppressWarnings("ResourceType") @Test(expected = NotFoundException.class) public void testGetStringNotFound() throws Exception { externalResources.getString("unknown"); }
@SuppressWarnings("ResourceType") @Test(expected = NotFoundException.class) public void testGetResStringNotFound() throws Exception { externalResources.getString(0); }
@Test public void testGetStringWithArguments() throws Exception { assertEquals("Hello Peter!", externalResources.getString("string_with_args", "Peter")); assertEquals("Hello world Peter!", externalResources.getString("hello_world_with_args", "Peter")); assertEquals("Hello world Peter!", externalResources.getString(R.string.hello_world_with_args, "Peter")); }
@Test(expected = NotFoundException.class) public void testGetStringWithArgumentsNotFound() throws Exception { externalResources.getString("unknown", "bar"); }
@Test(expected = NotFoundException.class) public void testGetResStringWithArgumentsNotFound() throws Exception { externalResources.getString(0, "bar"); }
@Test(expected = IllegalStateException.class) public void testGetResWithUseApplicationResourcesToFalse() { ExternalResources.Builder builder = new ExternalResources.Builder(context, new DefaultUrl("/")).useApplicationResources(false); builder.build().getString(R.string.hello_world); }
@Test(expected = NotFoundException.class) public void testGetWithUseApplicationResourcesToFalse() { ExternalResources.Builder builder = new ExternalResources.Builder(context, new DefaultUrl("/")).useApplicationResources(false); builder.build().getString("hello_world"); }