Adds some tests, cleanup a bit

This commit is contained in:
Guillaume Tâche
2024-09-20 08:36:52 +02:00
parent 17086a87ef
commit 703a4c71ae
47 changed files with 1122 additions and 182 deletions

View File

@@ -17,9 +17,13 @@ import static org.mockito.Mockito.when;
class TestCombinedResourceBundle {
private static final ResourceBundle BUNDLE = new CombinedResourceBundle(
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundle", Locale.FRENCH),
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundleTwo", Locale.FRENCH));
private final ResourceBundle bundle;
TestCombinedResourceBundle() {
this.bundle = new CombinedResourceBundle(
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundle", Locale.FRENCH),
ResourceBundle.getBundle("com.github.gtache.autosubtitle.gui.impl.MultiBundleTwo", Locale.FRENCH));
}
@Test
void testIllegal() {
@@ -29,26 +33,26 @@ class TestCombinedResourceBundle {
@Test
void testWorks() {
assertEquals("deux", BUNDLE.getString("a"));
assertEquals("deux", BUNDLE.getString("b"));
assertEquals("trois", BUNDLE.getString("c"));
assertEquals("un", BUNDLE.getString("d"));
assertEquals(Arrays.asList("a", "b", "c", "d"), Collections.list(BUNDLE.getKeys()));
assertEquals("deux", bundle.getString("a"));
assertEquals("deux", bundle.getString("b"));
assertEquals("trois", bundle.getString("c"));
assertEquals("un", bundle.getString("d"));
assertEquals(Arrays.asList("a", "b", "c", "d"), Collections.list(bundle.getKeys()));
}
@Test
void testNotFound() {
assertThrows(MissingResourceException.class, () -> BUNDLE.getString("e"));
assertThrows(MissingResourceException.class, () -> bundle.getString("e"));
}
@Test
void testLocale() {
final var bundle = mock(ResourceBundle.class);
when(bundle.keySet()).thenReturn(Set.of());
when(bundle.getString(anyString())).thenReturn("");
final var mocked = mock(ResourceBundle.class);
when(mocked.keySet()).thenReturn(Set.of());
when(mocked.getString(anyString())).thenReturn("");
final var locale = mock(Locale.class);
when(bundle.getLocale()).thenReturn(locale);
final var combined = new CombinedResourceBundle(bundle);
when(mocked.getLocale()).thenReturn(locale);
final var combined = new CombinedResourceBundle(mocked);
assertEquals(locale, combined.getLocale());
}
}