From 05fd40b3066d63bcf7c85f4d9836b7d816eec189 Mon Sep 17 00:00:00 2001 From: Yair Morgenstern Date: Tue, 3 Dec 2019 22:11:04 +0200 Subject: [PATCH] Added tests to alert when we don't have translations for game basics --- .../jsons/Translations/Units,Promotions.json | 2 +- .../gdxtesting/examples/BasicTests.java | 3 +- .../gdxtesting/examples/TranslationTests.java | 85 +++++++++++++++++++ 3 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tests/src/de/tomgrill/gdxtesting/examples/TranslationTests.java diff --git a/android/assets/jsons/Translations/Units,Promotions.json b/android/assets/jsons/Translations/Units,Promotions.json index 5386912e37..30a814226b 100644 --- a/android/assets/jsons/Translations/Units,Promotions.json +++ b/android/assets/jsons/Translations/Units,Promotions.json @@ -2902,7 +2902,7 @@ Ukrainian:"Підрозділ отримає здоровʼя +50. Втрачається можливість поліпшення" } - "Medic I":{ + "Medic":{ Italian:"Medico I" Simplified_Chinese:"治疗I级" Traditional_Chinese:"治療I級" diff --git a/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java b/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java index e3132a0358..ee13654a15 100644 --- a/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java +++ b/tests/src/de/tomgrill/gdxtesting/examples/BasicTests.java @@ -25,10 +25,11 @@ public class BasicTests { @Test public void gameBasicsLoad() { - assertTrue("This test will only pass when the game.png exists", + assertTrue("This test will only pass when the jsons can be loaded", GameBasics.INSTANCE.getBuildings().size() > 0); } + // @Test // public void setMapEditorScreen() { // new UncivGame("").create(); // sets the current diff --git a/tests/src/de/tomgrill/gdxtesting/examples/TranslationTests.java b/tests/src/de/tomgrill/gdxtesting/examples/TranslationTests.java new file mode 100644 index 0000000000..53999af975 --- /dev/null +++ b/tests/src/de/tomgrill/gdxtesting/examples/TranslationTests.java @@ -0,0 +1,85 @@ +// Taken from https://github.com/TomGrill/gdx-testing + +package de.tomgrill.gdxtesting.examples; + +import com.unciv.models.gamebasics.GameBasics; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.Set; + +import de.tomgrill.gdxtesting.GdxTestRunner; + +import static org.junit.Assert.assertTrue; + +// DO NOT attempt to Kotlinize until you're sure that running gradle tests:test actually checks stuff! + +@RunWith(GdxTestRunner.class) +public class TranslationTests { + + @Test + public void translationsLoad() { + assertTrue("This test will only pass there are translations", + GameBasics.INSTANCE.getTranslations().size() > 0); + } + + @Test + public void allUnitsHaveTranslation() { + Boolean allUnitsHaveTranslation = allStringAreTranslated(GameBasics.INSTANCE.getUnits().keySet()); + assertTrue("This test will only pass when there is a translation for all units", + allUnitsHaveTranslation); + } + + @Test + public void allBuildingsHaveTranslation() { + Boolean allBuildingsHaveTranslation = allStringAreTranslated(GameBasics.INSTANCE.getBuildings().keySet()); + assertTrue("This test will only pass when there is a translation for all buildings", + allBuildingsHaveTranslation); + } + + @Test + public void allTerrainsHaveTranslation() { + Set strings = GameBasics.INSTANCE.getTerrains().keySet(); + Boolean allStringsHaveTranslation = allStringAreTranslated(strings); + assertTrue("This test will only pass when there is a translation for all buildings", + allStringsHaveTranslation); + } + + @Test + public void allImprovementsHaveTranslation() { + Set strings = GameBasics.INSTANCE.getTileImprovements().keySet(); + Boolean allStringsHaveTranslation = allStringAreTranslated(strings); + assertTrue("This test will only pass when there is a translation for all improvements", + allStringsHaveTranslation); + } + + @Test + public void allTechnologiesHaveTranslation() { + Set strings = GameBasics.INSTANCE.getTechnologies().keySet(); + Boolean allStringsHaveTranslation = allStringAreTranslated(strings); + assertTrue("This test will only pass when there is a translation for all technologies", + allStringsHaveTranslation); + } + + @Test + public void allPromotionsHaveTranslation() { + Set strings = GameBasics.INSTANCE.getUnitPromotions().keySet(); + Boolean allStringsHaveTranslation = allStringAreTranslated(strings); + assertTrue("This test will only pass when there is a translation for all promotions", + allStringsHaveTranslation); + } + + private Boolean allStringAreTranslated(Set strings) { + boolean allBuildingsHaveTranslation = true; + for (String unitName : strings) { + if (!GameBasics.INSTANCE.getTranslations().containsKey(unitName)) { + allBuildingsHaveTranslation = false; + System.out.println(unitName); + } + } + return allBuildingsHaveTranslation; + } + + +} \ No newline at end of file