refactor: Move to ConfigLib, use lombok (#563)

* refactor: move to configlib, adjust config structure

* fix: huskclaims typos

* fix: don't generate `server.yml` in local mode

* fix: NPE with server name
This commit is contained in:
William authored and GitHub committed 2024-02-12 16:54:23 +00:00
1 parent c55631a30d
commit 1723aa44fc
84 files changed
+4334 -4832

No files matched your search

@@ -19,9 +19,8 @@
package net.william278.huskhomes.config;
import net.william278.annotaml.Annotaml;
import de.exlll.configlib.YamlConfigurations;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
@@ -30,28 +29,28 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.*;
@DisplayName("Locales Tests")
public class LocalesTests {
private static Locales englishLocales;
private Locales englishLocales;
@BeforeEach
@DisplayName("Test Loading English Locales")
@Test
public void testLoadEnglishLocales() {
try (InputStream resource = LocalesTests.class.getClassLoader().getResourceAsStream("locales/en-gb.yml")) {
Assertions.assertNotNull(resource, "en-gb.yml is missing from the locales folder");
englishLocales = Annotaml.create(Locales.class, resource).get();
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
try (InputStream locales = LocalesTests.class.getClassLoader().getResourceAsStream("locales/en-gb.yml")) {
assertNotNull(locales, "en-gb.yml is missing from the locales folder");
englishLocales = YamlConfigurations.read(locales, Locales.class);
} catch (Throwable e) {
fail("Failed to load en-gb.yml", e);
}
}
@@ -59,22 +58,19 @@ public class LocalesTests {
@DisplayName("Test All Locale Keys Present")
@MethodSource("provideLocaleFiles")
public void testAllLocaleKeysPresent(@NotNull File file, @SuppressWarnings("unused") @NotNull String keyName) {
try {
final Set<String> fileKeys = Annotaml.create(file, Locales.class).get().rawLocales.keySet();
englishLocales.rawLocales.keySet()
.forEach(key -> Assertions.assertTrue(fileKeys.contains(key),
"Locale key " + key + " is missing from " + file.getName()));
} catch (IOException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
final Set<String> fileKeys = YamlConfigurations.load(file.toPath(), Locales.class).getRawLocales().keySet();
englishLocales.getRawLocales().keySet().forEach(key -> assertTrue(
fileKeys.contains(key), "Locale key " + key + " is missing from " + file.getName()
));
}
@NotNull
private static Stream<Arguments> provideLocaleFiles() {
URL url = LocalesTests.class.getClassLoader().getResource("locales");
Assertions.assertNotNull(url, "locales folder is missing");
return Stream.of(Objects.requireNonNull(new File(url.getPath())
.listFiles(file -> file.getName().endsWith("yml") && !file.getName().equals("en-gb.yml"))))
.map(file -> Arguments.of(file, file.getName().replace(".yml", "")));
}
final URL url = LocalesTests.class.getClassLoader().getResource("locales");
assertNotNull(url, "locales folder is missing");
return Stream.of(Objects.requireNonNull(new File(url.getPath()).listFiles(
file -> file.getName().endsWith("yml") && !file.getName().equals("en-gb.yml")
))).map(file -> Arguments.of(file, file.getName().replace(".yml", "")));
}
}