Resources { @Nonnull public String string(@Nonnull String key) { DockerCloudUtils.requireNonNull(key, "Resource key cannot be null."); return queryString(key); } Resources(@Nonnull ResourceBundle... resourceBundles); String text(@Nonnull String key); @Nonnull String text(@Nonnull String key, @Nonnull Object... args); @Nonnull String string(@Nonnull String key);  }
@Test public void string() { TestResourceBundle bundle = new TestResourceBundle(); bundle.getResourcesMap().put("test.key", "'foo'"); Resources resources = new Resources(bundle); assertThat(resources.string("test.key")).isEqualTo("'foo'"); }
@Test public void stringMultipleBundles() { TestResourceBundle bundle1 = new TestResourceBundle(); TestResourceBundle bundle2 = new TestResourceBundle(); TestResourceBundle bundle3 = new TestResourceBundle(); bundle1.getResourcesMap().put("A", "1"); bundle2.getResourcesMap().put("A", "2"); bundle3.getResourcesMap().put("A", "3"); bundle2.getResourcesMap().put("B", "2"); bundle3.getResourcesMap().put("B", "3"); Resources resources = new Resources(bundle1, bundle2, bundle3); assertThat(resources.string("A")).isEqualTo("1"); assertThat(resources.string("B")).isEqualTo("2"); }
@Test public void stringInvalidInput() { TestResourceBundle bundle = new TestResourceBundle(); bundle.getResourcesMap().put("test.key", "'foo'"); Resources resources = new Resources(bundle); assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> resources.string(null)); assertThatExceptionOfType(MissingResourceException.class).isThrownBy(() -> resources.string("missing.key")); }