✅ Add test for I18nContainer
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 27 Nov 2025 11:22:45 +0000 (12:22 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 27 Nov 2025 11:22:45 +0000 (12:22 +0100)
src/main/java/de/todesbaum/jsite/i18n/I18nContainer.java
src/test/java/de/todesbaum/jsite/i18n/I18nContainerTest.java [new file with mode: 0644]

index 80ae066..b212088 100644 (file)
@@ -88,4 +88,12 @@ public class I18nContainer implements Iterable<Runnable> {
                return allRunnables.iterator();
        }
 
+       /**
+        * Resets this {@link I18nContainer}. Should only be used for tests!
+        */
+       void reset() {
+               i18nRunnables.clear();
+               i18nPostRunnables.clear();
+       }
+
 }
diff --git a/src/test/java/de/todesbaum/jsite/i18n/I18nContainerTest.java b/src/test/java/de/todesbaum/jsite/i18n/I18nContainerTest.java
new file mode 100644 (file)
index 0000000..91e89ad
--- /dev/null
@@ -0,0 +1,47 @@
+package de.todesbaum.jsite.i18n;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.emptyIterable;
+
+public class I18nContainerTest {
+
+       @Test
+       public void newI18nContainerIsEmpty() {
+               assertThat(I18nContainer.getInstance(), emptyIterable());
+       }
+
+       @Test
+       public void registeringARunnableMakesRunnableAvailableForIteration() {
+               Runnable runnable = () -> {};
+               I18nContainer.getInstance().registerRunnable(runnable);
+               assertThat(I18nContainer.getInstance(), contains(runnable));
+       }
+
+       @Test
+       public void registeringAPostRunnableMakesPostRunnableAvailableForIteration() {
+               Runnable runnable = () -> {};
+               I18nContainer.getInstance().registerPostRunnable(runnable);
+               assertThat(I18nContainer.getInstance(), contains(runnable));
+       }
+
+       @Test
+       public void registeringRunnableAfterPostRunnableMakesRunnableAvailableBeforePostRunnable() {
+               Runnable runnable = () -> {};
+               Runnable postRunnable = () -> {};
+               I18nContainer.getInstance().registerPostRunnable(postRunnable);
+               I18nContainer.getInstance().registerRunnable(runnable);
+               assertThat(I18nContainer.getInstance(), contains(runnable, postRunnable));
+       }
+
+       @Before
+       @After
+       public void resetI18nContainer() {
+               I18nContainer.getInstance().reset();
+       }
+
+}