BundleStrings implements StringLocalizer { @Override public LocalizableString getString(final String key, final String... parameters) { return new LocalizableString() { @Override public String getString(Locale locale) { return BundleStrings.this.getString(key, locale, parameters); } @Override public String getKey() { return key; } }; } BundleStrings();  BundleStrings(Bundle bundle); @Override LocalizableString getString(final String key, final String... parameters); @Override String getString(String key, Locale locale, String... parameters); void setBundle(Bundle bundle);  }
@Test public void testNoSpecificEntryForLocale_shouldLookupStringFromDefaultEntry() throws Exception { BundleStrings bl = new BundleStrings(createBundle()); assertThat(bl.getString("unique_key", new Locale("a", "b", "c")), is("default")); }
@Test public void testSearchingAllEntriesInBundle_shouldSearchWithRightDirectoryAndFilePattern() throws Exception { Bundle bundle = mock(Bundle.class); mockHeaders(bundle); BundleStrings bl = new BundleStrings(bundle); bl.getString("a"); verify(bundle).findEntries("bundle_locales/OSGI-INF/l10n", "bundle*.properties", false); }
@Test public void testEntryExistsForLocale_shouldReturnKeyFromEntry() throws Exception { BundleStrings bl = new BundleStrings(createBundle()); assertThat(bl.getString("abc", new Locale("a", "b", "c")), is("c")); }
@Test public void testNoEntryForLocale_shouldReturnKeyFromNextSpecificEntry() throws Exception { BundleStrings bl = new BundleStrings(createBundle()); assertThat(bl.getString("ab", new Locale("a", "b", "c")), is("b")); assertThat(bl.getString("a", new Locale("a", "b", "c")), is("a")); assertThat(bl.getString("a", new Locale("a", "b")), is("a")); }
@Test public void testPassThroughLocalizer_shouldReturnKey() throws Exception { assertThat(new PassThroughStringLocalizer().getString("a", Locale.GERMAN), is("a")); }