Skip to content

Commit

Permalink
Fix languages test
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jun 26, 2024
1 parent 1e9b127 commit bcaf163
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/faforever/client/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,7 +32,7 @@ public class I18n implements InitializingBean {
private final LocalizationPrefs localizationPrefs;
private final DataPrefs dataPrefs;

private final ObservableSet<Locale> availableLanguages = FXCollections.observableSet();
private final ReadOnlySetWrapper<Locale> availableLanguages = new ReadOnlySetWrapper<>(FXCollections.observableSet());

private Locale userSpecificLocale;

Expand Down Expand Up @@ -146,7 +146,7 @@ public String rounded(Number number, int digits) {
return String.format(userSpecificLocale, "%." + digits + "f", number.doubleValue());
}

public ReadOnlySetWrapper<Locale> getAvailableLanguages() {
return new ReadOnlySetWrapper<>(availableLanguages);
public ReadOnlySetProperty<Locale> getAvailableLanguages() {
return availableLanguages.getReadOnlyProperty();
}
}
16 changes: 10 additions & 6 deletions src/test/java/com/faforever/client/i18n/I18nTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -103,9 +102,14 @@ public void rounded() {
@Test
public void testLoadedLanguagesAreComplete() throws IOException {
final Path path = Path.of("src", "main", "resources", "i18n");
try (Stream<Path> 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));
}
});
}
}

0 comments on commit bcaf163

Please sign in to comment.