mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-25 22:44:51 +00:00
Leave custom data untouched when a versioned transformer fails
This commit is contained in:
6 files changed
+125
-53
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.gtnewhorizons.postea.api;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -30,4 +31,22 @@ class CustomDataReplacementManagerTest {
|
||||
assertEquals(5, VersionStamps.stored(stamps, "mod:absent"));
|
||||
assertEquals(2, VersionStamps.stored(saved, "mod:present"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aThrowingTransformerLeavesTheRootAsRead() {
|
||||
StubTransformer rewrites = new StubTransformer("mod:rewrites", 2);
|
||||
rewrites.customData = ctx -> ctx.root()
|
||||
.setString("data", "new");
|
||||
StubTransformer fails = new StubTransformer("mod:fails", 2);
|
||||
fails.customData = ctx -> { throw new IllegalStateException("broken"); };
|
||||
NBTTagCompound root = new NBTTagCompound();
|
||||
root.setString("data", "old");
|
||||
NBTTagCompound asRead = (NBTTagCompound) root.copy();
|
||||
|
||||
// The ReportedException's CrashReport initializes FML, which fails outside a launched game.
|
||||
assertThrows(
|
||||
Throwable.class,
|
||||
() -> CustomDataReplacementManager.transform("mod:storage", root, Arrays.asList(rewrites, fails)));
|
||||
assertEquals(asRead, root);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user