summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2018-08-06 14:40:06 +1000
committermd_5 <git@md-5.net>2018-08-06 14:40:06 +1000
commitcfc67965f397a7d1b930f4212eba07120a43b5f9 (patch)
treea0ec0a2055ce992b0e59c36774b90664ff004d69 /src/test
parenta9c796f12cf00276e4e22de8a54138235c1cea72 (diff)
downloadcraftbukkit-cfc67965f397a7d1b930f4212eba07120a43b5f9.tar
craftbukkit-cfc67965f397a7d1b930f4212eba07120a43b5f9.tar.gz
craftbukkit-cfc67965f397a7d1b930f4212eba07120a43b5f9.tar.lz
craftbukkit-cfc67965f397a7d1b930f4212eba07120a43b5f9.tar.xz
craftbukkit-cfc67965f397a7d1b930f4212eba07120a43b5f9.zip
Add merging and matching of parsed BlockData
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/bukkit/BlockDataTest.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/BlockDataTest.java b/src/test/java/org/bukkit/BlockDataTest.java
index e43de765..fb30a9e2 100644
--- a/src/test/java/org/bukkit/BlockDataTest.java
+++ b/src/test/java/org/bukkit/BlockDataTest.java
@@ -1,9 +1,13 @@
package org.bukkit;
import net.minecraft.server.BlockCake;
+import net.minecraft.server.BlockChest;
import net.minecraft.server.Blocks;
+import net.minecraft.server.EnumDirection;
+import org.bukkit.block.BlockFace;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.type.Cake;
+import org.bukkit.block.data.type.Chest;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.support.AbstractTestingBase;
import static org.hamcrest.Matchers.*;
@@ -72,4 +76,80 @@ public class BlockDataTest extends AbstractTestingBase {
clone.setBites(1);
Assert.assertThat("Clone is not actually clone", clone, is(not(cakeTest)));
}
+
+ @Test
+ public void testMerge() {
+ Chest trueTarget = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]");
+ Chest falseTarget = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]");
+ Chest waterlogged = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
+
+ BlockData candidate;
+
+ Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(waterlogged));
+ candidate = trueTarget.merge(waterlogged);
+ Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate));
+
+ Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(waterlogged));
+ candidate = falseTarget.merge(waterlogged);
+ Assert.assertFalse("Target and candidate are still not equal", falseTarget.equals(candidate));
+ }
+
+ @Test
+ public void testMergeAny() {
+ Chest trueTarget = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]");
+ Chest falseTarget = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]");
+ Chest any = (Chest) CraftBlockData.newData(null, "minecraft:chest");
+
+ BlockData candidate;
+
+ Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(any));
+ candidate = trueTarget.merge(any);
+ Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate));
+
+ Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(any));
+ candidate = falseTarget.merge(any);
+ Assert.assertTrue("Target and candidate are now equal", falseTarget.equals(candidate));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotMerge1() {
+ Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]");
+ Chest two = (Chest) CraftBlockData.fromData(Blocks.CHEST.getBlockData());
+
+ one.merge(two);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotMerge2() {
+ Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
+ Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
+
+ one.merge(two);
+
+ two.setFacing(BlockFace.NORTH);
+ one.merge(two);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCannotMerge3() {
+ Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
+ Chest two = (Chest) CraftBlockData.newData(null, "minecraft:trapped_chest[waterlogged=true]");
+
+ one.merge(two);
+ }
+
+ @Test
+ public void testMatch() {
+ Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
+ Assert.assertFalse(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
+ Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest")));
+ Assert.assertFalse(CraftBlockData.newData(null, "minecraft:trapped_chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
+ Assert.assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true,facing=east]")));
+
+ Chest one = (Chest) CraftBlockData.fromData(Blocks.CHEST.getBlockData().set(BlockChest.FACING, EnumDirection.EAST));
+ Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=false]");
+
+ Assert.assertTrue(one.matches(two));
+ Assert.assertFalse(two.matches(one));
+ }
}