summaryrefslogtreecommitdiff
path: root/src/test/java/sevenUnitsGUI/I18nTest.java
diff options
context:
space:
mode:
authorAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
committerAdrien Hopkins <adrien.p.hopkins@gmail.com>2025-06-15 19:42:01 -0500
commit2fdbc084fd1d78f0b7633db34460b1195de264f3 (patch)
tree4c908950d9b049394f8160b8159b498aec586ecc /src/test/java/sevenUnitsGUI/I18nTest.java
parented53492243ecad8d975401a97f5b634328ad2c71 (diff)
parentbccb5b5e3452421c81c1fb58f83391ba6584807c (diff)
Merge release 1.0.0 into stable branchHEADstable
See the tag 'v1.0.0' or the changelog for more information about this release.
Diffstat (limited to 'src/test/java/sevenUnitsGUI/I18nTest.java')
-rw-r--r--src/test/java/sevenUnitsGUI/I18nTest.java95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/test/java/sevenUnitsGUI/I18nTest.java b/src/test/java/sevenUnitsGUI/I18nTest.java
new file mode 100644
index 0000000..2f90d76
--- /dev/null
+++ b/src/test/java/sevenUnitsGUI/I18nTest.java
@@ -0,0 +1,95 @@
+/**
+ * Copyright (C) 2025 Adrien Hopkins
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package sevenUnitsGUI;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+/**
+ * Tests for the internationalization system.
+ *
+ * @since v1.0.0
+ */
+class I18nTest {
+ private static final Stream<String> testLocaleSupported() {
+ return Stream.of("en", "fr");
+ }
+
+ private static final Stream<Arguments> testLocalization() {
+ return Stream.of(Arguments.of("tv.title", "en", "7Units [v]"),
+ Arguments.of("tv.title", "fr", "7Unités [v]"),
+ Arguments.of("tv.convert_units.title", "en", "Convert Units"),
+ Arguments.of("tv.convert_units.title", "fr", "Convertir Unités"));
+ }
+
+ /**
+ * Tests that the default locale is supported.
+ *
+ * @since v1.0.0
+ * @see Presenter#DEFAULT_LOCALE
+ */
+ @Test
+ void testDefaultLocaleSupported() {
+ final var p = new Presenter(new ViewBot());
+ assertNotNull(p.locales.get(Presenter.DEFAULT_LOCALE),
+ "Default locale is not supported.");
+ }
+
+ /**
+ * Ensures that the system supports the provided locale.
+ *
+ * @param localeName locale to test for support
+ *
+ * @since 2025-06-04
+ * @since v1.0.0
+ */
+ @ParameterizedTest
+ @MethodSource
+ void testLocaleSupported(String localeName) {
+ final var p = new Presenter(new ViewBot());
+ assertNotNull(p.locales.get(localeName),
+ "Locale \"" + localeName + "\" is not supported.");
+ }
+
+ /**
+ * Tests that the system can correctly localize text, using the default
+ * locales.
+ *
+ * @param key key of text to localize
+ * @param locale locale to use
+ * @param expected expected value of output text
+ *
+ * @since 2025-06-04
+ * @since v1.0.0
+ */
+ @ParameterizedTest
+ @MethodSource
+ void testLocalization(String key, String locale, String expected) {
+ final var p = new Presenter(new ViewBot());
+ p.setUserLocale(locale);
+ final var actual = p.getLocalizedText(key);
+ assertEquals(expected, actual);
+ }
+
+}