Fix unit tests

This commit is contained in:
shedaniel
2024-04-05 00:17:31 +09:00
parent deaee2ad65
commit 3cd4740780
2 changed files with 13 additions and 2 deletions

View File

@@ -25,8 +25,8 @@ public final class ModMetadataFiles {
private static final Map<String, Function<byte[], ModMetadataFile>> SINGLE_FILE_METADATA_TYPES = ImmutableMap.<String, Function<byte[], ModMetadataFile>>builder()
.put(QuiltModJson.FILE_NAME, QuiltModJson::of)
.put(ArchitecturyCommonJson.FILE_NAME, ArchitecturyCommonJson::of)
.put(ModsToml.FILE_PATH, onError(ModsToml::of, "Could not load mods.toml", () -> new ErroringModMetadataFile(ModsToml.FILE_PATH)))
.put(ModsToml.NEOFORGE_FILE_PATH, onError(ModsToml::of, "Could not load mods.toml", () -> new ErroringModMetadataFile(ModsToml.NEOFORGE_FILE_PATH)))
.put(ModsToml.FILE_PATH, onError(ModsToml::of, "Could not load mods.toml", () -> new ErroringModMetadataFile("mods.toml")))
.put(ModsToml.NEOFORGE_FILE_PATH, onError(ModsToml::of, "Could not load neoforge.mods.toml", () -> new ErroringModMetadataFile("neoforge.mods.toml")))
.build();
private static <A, B> Function<A, B> onError(Function<A, B> fn, String message, Supplier<B> onError) {

View File

@@ -118,6 +118,17 @@ class ModMetadataFilesTest extends Specification {
modMetadata.fileName == 'mods.toml [erroring]'
}
def "read broken neoforge.mods.toml from directory"() {
given:
Files.createDirectories(workingDir.resolve('META-INF'))
workingDir.resolve('META-INF/neoforge.mods.toml').text = ModsTomlTest.BROKEN_INPUT
when:
def modMetadata = ModMetadataFiles.fromDirectory(workingDir)
then:
modMetadata instanceof ErroringModMetadataFile
modMetadata.fileName == 'neoforge.mods.toml [erroring]'
}
def "read fabric.mod.json from directory"() {
given:
workingDir.resolve('fabric.mod.json').text = '''