Some more substitution tests. It seems like it's working as it should.
This commit is contained in:
parent
7d4bf619fe
commit
a156d5e0fe
3 changed files with 79 additions and 3 deletions
|
@ -7,7 +7,7 @@ import org.junit.runners.Suite;
|
||||||
* Run the full suite of tests
|
* Run the full suite of tests
|
||||||
*/
|
*/
|
||||||
@RunWith(Suite.class)
|
@RunWith(Suite.class)
|
||||||
@Suite.SuiteClasses({VanillaRegistryTests.class, FreezingTests.class, SubstitutionTests.class})
|
@Suite.SuiteClasses({VanillaRegistryTests.class, FreezingTests.class, SubstitutionRemoveRestoreTest.class, SubstitutionInjectionTest.class})
|
||||||
public class RegistryTestSuite
|
public class RegistryTestSuite
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
package net.minecraftforge.fml.common.registry;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockDirt;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.init.Bootstrap;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.fml.common.DummyModContainer;
|
||||||
|
import net.minecraftforge.fml.common.Loader;
|
||||||
|
import net.minecraftforge.fml.common.ModMetadata;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Substitution test harness - tests that substitutions behave correctly
|
||||||
|
*/
|
||||||
|
@RunWith(ForgeTestRunner.class)
|
||||||
|
public class SubstitutionInjectionTest
|
||||||
|
{
|
||||||
|
private ResourceLocation myDirt = new ResourceLocation("minecraft:dirt");
|
||||||
|
private BlockDirt toSub = new BlockDirt() {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup()
|
||||||
|
{
|
||||||
|
Loader.instance();
|
||||||
|
Bootstrap.register();
|
||||||
|
Loader.instance().setupTestHarness(new DummyModContainer(new ModMetadata() {{
|
||||||
|
modId = "test";
|
||||||
|
}}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSubstitutionInjection() throws Exception
|
||||||
|
{
|
||||||
|
// Capture snapshot prior to registering the substitution - this is a world state "pre-substitute"
|
||||||
|
final PersistentRegistryManager.GameDataSnapshot snapshot = PersistentRegistryManager.takeSnapshot();
|
||||||
|
|
||||||
|
GameRegistry.addSubstitutionAlias("minecraft:dirt", GameRegistry.Type.BLOCK, toSub);
|
||||||
|
PersistentRegistryManager.freezeData();
|
||||||
|
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
|
||||||
|
|
||||||
|
final FMLControlledNamespacedRegistry<Block> blockRegistry = (FMLControlledNamespacedRegistry<Block>)PersistentRegistryManager.findRegistryByType(Block.class);
|
||||||
|
|
||||||
|
// TEST 1: Does my substitute take effect? The substitute should be found in the registry
|
||||||
|
Block fnd = blockRegistry.getValue(myDirt);
|
||||||
|
Block currDirt = Blocks.DIRT;
|
||||||
|
assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
|
||||||
|
assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
|
||||||
|
assertEquals("Got my dirt substitute - registry", toSub, fnd);
|
||||||
|
|
||||||
|
// TEST 2: Does the substitute get injected when told by loading operation? The substitute should be found in the registry
|
||||||
|
PersistentRegistryManager.injectSnapshot(snapshot, true, true);
|
||||||
|
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
|
||||||
|
fnd = blockRegistry.getValue(myDirt);
|
||||||
|
currDirt = Blocks.DIRT;
|
||||||
|
assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
|
||||||
|
assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
|
||||||
|
assertEquals("Got my dirt substitute - registry", toSub, fnd);
|
||||||
|
|
||||||
|
// TEST 3: Does the substitute get restored when reverting to frozen state? The substitute should be found in the registry again
|
||||||
|
PersistentRegistryManager.revertToFrozen();
|
||||||
|
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
|
||||||
|
fnd = blockRegistry.getValue(myDirt);
|
||||||
|
currDirt = Blocks.DIRT;
|
||||||
|
assertEquals("Got my dirt substitute - Blocks", toSub, currDirt);
|
||||||
|
assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
|
||||||
|
assertEquals("Got my dirt substitute - registry", toSub, fnd);
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ import static org.junit.Assert.assertNotEquals;
|
||||||
* Substitution test harness - tests that substitutions behave correctly
|
* Substitution test harness - tests that substitutions behave correctly
|
||||||
*/
|
*/
|
||||||
@RunWith(ForgeTestRunner.class)
|
@RunWith(ForgeTestRunner.class)
|
||||||
public class SubstitutionTests
|
public class SubstitutionRemoveRestoreTest
|
||||||
{
|
{
|
||||||
private ResourceLocation myDirt = new ResourceLocation("minecraft:dirt");
|
private ResourceLocation myDirt = new ResourceLocation("minecraft:dirt");
|
||||||
private BlockDirt toSub = new BlockDirt() {
|
private BlockDirt toSub = new BlockDirt() {
|
||||||
|
@ -37,7 +37,7 @@ public class SubstitutionTests
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubstitution() throws Exception
|
public void testSubstitutionRemovalAndRestore() throws Exception
|
||||||
{
|
{
|
||||||
GameRegistry.addSubstitutionAlias("minecraft:dirt", GameRegistry.Type.BLOCK, toSub);
|
GameRegistry.addSubstitutionAlias("minecraft:dirt", GameRegistry.Type.BLOCK, toSub);
|
||||||
PersistentRegistryManager.freezeData();
|
PersistentRegistryManager.freezeData();
|
Loading…
Reference in a new issue