Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-19 14:30:17 +01:00
Fix test
Dieser Commit ist enthalten in:
Ursprung
1271505c26
Commit
e99759d701
@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.geyser.configuration;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.common.returnsreceiver.qual.This;
|
||||
import org.geysermc.geyser.Constants;
|
||||
@ -75,7 +76,10 @@ public final class ConfigLoader {
|
||||
--------------------------------
|
||||
""";
|
||||
|
||||
private final GeyserBootstrap bootstrap;
|
||||
/**
|
||||
* Only nullable for testing.
|
||||
*/
|
||||
private final @Nullable GeyserBootstrap bootstrap;
|
||||
private @Nullable Consumer<CommentedConfigurationNode> transformer;
|
||||
private File configFile;
|
||||
|
||||
@ -84,6 +88,12 @@ public final class ConfigLoader {
|
||||
configFile = new File(bootstrap.getConfigFolder().toFile(), "config.yml");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
ConfigLoader(File file) {
|
||||
this.bootstrap = null;
|
||||
configFile = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the directory as indicated by {@link GeyserBootstrap#getConfigFolder()}
|
||||
*/
|
||||
@ -236,7 +246,9 @@ public final class ConfigLoader {
|
||||
|
||||
config.advanced(advancedConfig);
|
||||
|
||||
bootstrap.getGeyserLogger().setDebug(config.debugMode());
|
||||
if (this.bootstrap != null) { // Null for testing only.
|
||||
this.bootstrap.getGeyserLogger().setDebug(config.debugMode());
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
@ -292,9 +304,12 @@ public final class ConfigLoader {
|
||||
.file(file)
|
||||
.indent(2)
|
||||
.nodeStyle(NodeStyle.BLOCK)
|
||||
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options, builder ->
|
||||
.defaultOptions(options -> InterfaceDefaultOptions.addTo(options, builder -> {
|
||||
if (this.bootstrap != null) { // Testing only.
|
||||
builder.addProcessor(ExcludePlatform.class, excludePlatform(bootstrap.platformType().platformName()))
|
||||
.addProcessor(PluginSpecific.class, integrationSpecific(bootstrap.platformType() != PlatformType.STANDALONE)))
|
||||
.addProcessor(PluginSpecific.class, integrationSpecific(bootstrap.platformType() != PlatformType.STANDALONE));
|
||||
}
|
||||
})
|
||||
.shouldCopyDefaults(false) // If we use ConfigurationNode#get(type, default), do not write the default back to the node.
|
||||
.header(header)
|
||||
.serializers(builder -> builder.register(new LowercaseEnumSerializer())))
|
||||
|
@ -31,7 +31,12 @@ import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.util.CheckedConsumer;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class ConfigLoaderTest {
|
||||
|
||||
@ -49,23 +54,23 @@ public class ConfigLoaderTest {
|
||||
File file = tempDirectory.resolve("config.yml").toFile();
|
||||
|
||||
// Sorry Konicai...
|
||||
// forAllConfigs(type -> {
|
||||
// ConfigLoader.load(file, type, n -> this.config1 = n.copy());
|
||||
// long initialModification = file.lastModified();
|
||||
// assertTrue(file.exists()); // should have been created
|
||||
// List<String> firstContents = Files.readAllLines(file.toPath());
|
||||
//
|
||||
// ConfigLoader.load(file, type, n -> this.config2 = n.copy());
|
||||
// List<String> secondContents = Files.readAllLines(file.toPath());
|
||||
//
|
||||
// assertEquals(initialModification, file.lastModified()); // should not have been touched
|
||||
// assertEquals(firstContents, secondContents);
|
||||
//
|
||||
// // Must ignore this, as when the config is read back, the header is interpreted as a comment on the first node in the map
|
||||
// config1.node("java").comment(null);
|
||||
// config2.node("java").comment(null);
|
||||
// assertEquals(config1, config2);
|
||||
// });
|
||||
forAllConfigs(type -> {
|
||||
new ConfigLoader(file).transformer(n -> this.config1 = n.copy()).load(type);
|
||||
long initialModification = file.lastModified();
|
||||
assertTrue(file.exists()); // should have been created
|
||||
List<String> firstContents = Files.readAllLines(file.toPath());
|
||||
|
||||
new ConfigLoader(file).transformer(n -> this.config2 = n.copy()).load(type);
|
||||
List<String> secondContents = Files.readAllLines(file.toPath());
|
||||
|
||||
assertEquals(initialModification, file.lastModified()); // should not have been touched
|
||||
assertEquals(firstContents, secondContents);
|
||||
|
||||
// Must ignore this, as when the config is read back, the header is interpreted as a comment on the first node in the map
|
||||
config1.node("java").comment(null);
|
||||
config2.node("java").comment(null);
|
||||
assertEquals(config1, config2);
|
||||
});
|
||||
}
|
||||
|
||||
void forAllConfigs(CheckedConsumer<Class<? extends GeyserConfig>, Exception> consumer) throws Exception {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren