mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 11:05:40 +00:00
More tests. Substitutions now work, and a fix is included. *sigh* Closes too many bugs to count.
This commit is contained in:
1 parent
22394f87d5
commit
7d4bf619fe
6 files changed
+123
-5
No files matched your search
@@ -13,9 +13,8 @@ import org.junit.runners.JUnit4;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
/**
|
||||
* Uses {@code ResettingClassLoader} to load the test class, meaning the
|
||||
* {@code Quarantine} annotation can be used to ensure certain classes are
|
||||
* loaded separately.
|
||||
* Uses {@code ResettingClassLoader} to load the test class. Minecraft and Forge
|
||||
* classes are loaded using the separate class loader.
|
||||
*
|
||||
* Use of a separate class loader allows classes to be reloaded for each test
|
||||
* class, which is handy when you're testing frameworks that make use of static
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package net.minecraftforge.fml.common.registry;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
/**
|
||||
* Run the full suite of tests
|
||||
*/
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({VanillaRegistryTests.class, FreezingTests.class, SubstitutionTests.class})
|
||||
public class RegistryTestSuite
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
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 SubstitutionTests
|
||||
{
|
||||
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 testSubstitution() throws Exception
|
||||
{
|
||||
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 removed when told by remote operation? The substitute should NOT be found in the registry
|
||||
final PersistentRegistryManager.GameDataSnapshot snapshot = PersistentRegistryManager.takeSnapshot();
|
||||
snapshot.entries.get(PersistentRegistryManager.BLOCKS).substitutions.clear();
|
||||
PersistentRegistryManager.injectSnapshot(snapshot, false, false);
|
||||
ObjectHolderRegistry.INSTANCE.applyObjectHolders();
|
||||
fnd = blockRegistry.getValue(myDirt);
|
||||
currDirt = Blocks.DIRT;
|
||||
assertNotEquals("Got my dirt substitute - Blocks", toSub, currDirt);
|
||||
assertEquals("Got my dirt substitute - Blocks and registry", currDirt, fnd);
|
||||
assertNotEquals("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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user