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