From 1e0c3ff55067eb886a0da121a3bdd6c64d987e1f Mon Sep 17 00:00:00 2001 From: teridax Date: Sun, 16 Jul 2023 23:25:39 +0200 Subject: [PATCH] added translator test --- src/me/teridax/jcash/lang/TranslatorTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/me/teridax/jcash/lang/TranslatorTest.java diff --git a/src/me/teridax/jcash/lang/TranslatorTest.java b/src/me/teridax/jcash/lang/TranslatorTest.java new file mode 100644 index 0000000..af3ae8e --- /dev/null +++ b/src/me/teridax/jcash/lang/TranslatorTest.java @@ -0,0 +1,41 @@ +package me.teridax.jcash.lang; + +import org.junit.Test; + +import java.util.Arrays; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertTrue; + +public class TranslatorTest { + + @Test + public void testLoading() { + // test if all locales are read + assertTrue(Arrays.deepEquals(Translator.availableLocales(), new String[]{"en_EN", "de_DE", "es_ES", "fr_FR", "zh_Hans"})); + } + + @Test + public void testTranslationBasic() { + // test if basic translation works + Translator.setTranslationLocale("de_DE"); + assertEquals(Translator.translate("Overdraft"), "Überziehungsbetrag"); + assertEquals(Translator.translate("Load database"), "Datenbank auswählen"); + assertEquals(Translator.translate("currency must not be blank"), "Betrag darf nicht leer sein"); + assertEquals(Translator.translate("Deposit money"), "Geld einzahlen"); + + Translator.setTranslationLocale("es_ES"); + assertEquals(Translator.translate("Account"), "Cuenta"); + assertEquals(Translator.translate("Faulty login attempt"), "Solicitud de autenticación no válida"); + assertEquals(Translator.translate("Transfer money"), "Transferencia de dinero"); + + // test if translation with no available translation works as expected + assertEquals(Translator.translate("Guppi guppi guppi"), "Guppi guppi guppi"); + } + + @Test + public void testInvalidLocales() { + // test if app crashes when invalid locale is loaded + Translator.setTranslationLocale("ar_TD"); + } +}