From bcaf163eceb31ee586e532b19544267a09b4f29f Mon Sep 17 00:00:00 2001 From: Sheikah45 Date: Wed, 26 Jun 2024 06:46:28 -0400 Subject: [PATCH] Fix languages test --- .../java/com/faforever/client/i18n/I18n.java | 8 ++++---- .../java/com/faforever/client/i18n/I18nTest.java | 16 ++++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/faforever/client/i18n/I18n.java b/src/main/java/com/faforever/client/i18n/I18n.java index 10ba439956..8853c53821 100644 --- a/src/main/java/com/faforever/client/i18n/I18n.java +++ b/src/main/java/com/faforever/client/i18n/I18n.java @@ -3,9 +3,9 @@ import com.faforever.client.preferences.DataPrefs; import com.faforever.client.preferences.LocalizationPrefs; import com.google.common.base.Strings; +import javafx.beans.property.ReadOnlySetProperty; import javafx.beans.property.ReadOnlySetWrapper; import javafx.collections.FXCollections; -import javafx.collections.ObservableSet; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.InitializingBean; @@ -32,7 +32,7 @@ public class I18n implements InitializingBean { private final LocalizationPrefs localizationPrefs; private final DataPrefs dataPrefs; - private final ObservableSet availableLanguages = FXCollections.observableSet(); + private final ReadOnlySetWrapper availableLanguages = new ReadOnlySetWrapper<>(FXCollections.observableSet()); private Locale userSpecificLocale; @@ -146,7 +146,7 @@ public String rounded(Number number, int digits) { return String.format(userSpecificLocale, "%." + digits + "f", number.doubleValue()); } - public ReadOnlySetWrapper getAvailableLanguages() { - return new ReadOnlySetWrapper<>(availableLanguages); + public ReadOnlySetProperty getAvailableLanguages() { + return availableLanguages.getReadOnlyProperty(); } } diff --git a/src/test/java/com/faforever/client/i18n/I18nTest.java b/src/test/java/com/faforever/client/i18n/I18nTest.java index d4375c648f..bc9806d4fc 100644 --- a/src/test/java/com/faforever/client/i18n/I18nTest.java +++ b/src/test/java/com/faforever/client/i18n/I18nTest.java @@ -14,11 +14,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Locale; -import java.util.stream.Stream; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsCollectionWithSize.hasSize; +import static org.junit.jupiter.api.Assertions.assertTrue; public class I18nTest extends ServiceTest { @@ -103,9 +102,14 @@ public void rounded() { @Test public void testLoadedLanguagesAreComplete() throws IOException { final Path path = Path.of("src", "main", "resources", "i18n"); - try (Stream walk = Files.walk(path)) { - final long messageFileCount = walk.filter(propertiesFile -> Files.isRegularFile(propertiesFile) && propertiesFile.getFileName().toString().endsWith(".properties")).count(); - assertThat(instance.getAvailableLanguages(), hasSize((int) messageFileCount)); - } + instance.getAvailableLanguages().forEach(locale -> { + if (locale.toString().equals("en_US")) { + assertTrue(Files.exists(path.resolve("messages.properties")), + "messages file for %s does not exist".formatted(locale)); + } else { + assertTrue(Files.exists(path.resolve("messages_" + locale + ".properties")), + "messages file for %s does not exist".formatted(locale)); + } + }); } }