@@ -1,6 +1,8 @@
|
||||
package org.bukkit;
|
||||
|
||||
import static org.bukkit.support.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import net.minecraft.core.EnumDirection;
|
||||
import net.minecraft.world.level.block.BlockCake;
|
||||
import net.minecraft.world.level.block.BlockChest;
|
||||
@@ -11,8 +13,7 @@ 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 org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BlockDataTest extends AbstractTestingBase {
|
||||
|
||||
@@ -21,48 +22,48 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
|
||||
|
||||
BlockData materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]");
|
||||
Assert.assertThat(materialString, is(cakeTest));
|
||||
assertThat(materialString, is(cakeTest));
|
||||
|
||||
BlockData combined = CraftBlockData.newData(null, "cake[bites=3]");
|
||||
Assert.assertThat(combined, is(cakeTest));
|
||||
assertThat(combined, is(cakeTest));
|
||||
|
||||
BlockData combinedMinecraft = CraftBlockData.newData(null, "minecraft:cake[bites=3]");
|
||||
Assert.assertThat(combinedMinecraft, is(cakeTest));
|
||||
assertThat(combinedMinecraft, is(cakeTest));
|
||||
|
||||
BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString());
|
||||
Assert.assertThat(inverted, is(cakeTest));
|
||||
assertThat(inverted, is(cakeTest));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testBadMaterial() {
|
||||
CraftBlockData.newData(null, "invalid");
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "invalid"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testBadSyntax() {
|
||||
CraftBlockData.newData(null, "minecraft:cake[bites=3");
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "minecraft:cake[bites=3"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testDoubleMaterial() {
|
||||
CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]");
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testMistake() {
|
||||
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
|
||||
|
||||
CraftBlockData.newData(Material.CAKE, cakeTest.toString());
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.CAKE, cakeTest.toString()));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testItem() {
|
||||
CraftBlockData.newData(Material.DIAMOND_AXE, null);
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(Material.DIAMOND_AXE, null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testItemParse() {
|
||||
CraftBlockData.newData(null, "minecraft:diamond_axe");
|
||||
assertThrows(IllegalArgumentException.class, () -> CraftBlockData.newData(null, "minecraft:diamond_axe"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,11 +71,11 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.defaultBlockState().setValue(BlockCake.BITES, 3));
|
||||
Cake clone = (Cake) cakeTest.clone();
|
||||
|
||||
Assert.assertFalse("Clone did not return new object", cakeTest == clone);
|
||||
Assert.assertThat("Clone is not equal", clone, is(cakeTest));
|
||||
assertNotSame(cakeTest, clone, "Clone did not return new object");
|
||||
assertThat(clone, is(cakeTest), "Clone is not equal");
|
||||
|
||||
clone.setBites(1);
|
||||
Assert.assertThat("Clone is not actually clone", clone, is(not(cakeTest)));
|
||||
assertThat(clone, is(not(cakeTest)), "Clone is not actually clone");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,13 +86,13 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
|
||||
BlockData candidate;
|
||||
|
||||
Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(waterlogged));
|
||||
assertNotEquals(trueTarget, waterlogged, "Target and match are not yet equal");
|
||||
candidate = trueTarget.merge(waterlogged);
|
||||
Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate));
|
||||
assertEquals(trueTarget, candidate, "Target and candidate are now equal");
|
||||
|
||||
Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(waterlogged));
|
||||
assertNotEquals(falseTarget, waterlogged, "Target and match are not yet equal");
|
||||
candidate = falseTarget.merge(waterlogged);
|
||||
Assert.assertFalse("Target and candidate are still not equal", falseTarget.equals(candidate));
|
||||
assertNotEquals(falseTarget, candidate, "Target and candidate are still not equal");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,24 +103,24 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
|
||||
BlockData candidate;
|
||||
|
||||
Assert.assertFalse("Target and match are not yet equal", trueTarget.equals(any));
|
||||
assertNotEquals(trueTarget, any, "Target and match are not yet equal");
|
||||
candidate = trueTarget.merge(any);
|
||||
Assert.assertTrue("Target and candidate are now equal", trueTarget.equals(candidate));
|
||||
assertEquals(trueTarget, candidate, "Target and candidate are now equal");
|
||||
|
||||
Assert.assertFalse("Target and match are not yet equal", falseTarget.equals(any));
|
||||
assertNotEquals(falseTarget, any, "Target and match are not yet equal");
|
||||
candidate = falseTarget.merge(any);
|
||||
Assert.assertTrue("Target and candidate are now equal", falseTarget.equals(candidate));
|
||||
assertEquals(falseTarget, candidate, "Target and candidate are now equal");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCannotMerge1() {
|
||||
Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]");
|
||||
Chest two = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState());
|
||||
|
||||
one.merge(two);
|
||||
assertThrows(IllegalArgumentException.class, () -> one.merge(two));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void testCannotMerge2() {
|
||||
Chest one = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
|
||||
Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]");
|
||||
@@ -127,30 +128,30 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
one.merge(two);
|
||||
|
||||
two.setFacing(BlockFace.NORTH);
|
||||
one.merge(two);
|
||||
assertThrows(IllegalArgumentException.class, () -> one.merge(two));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
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);
|
||||
assertThrows(IllegalArgumentException.class, () -> 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]")));
|
||||
assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
|
||||
assertFalse(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
|
||||
assertTrue(CraftBlockData.newData(null, "minecraft:chest[facing=east,waterlogged=true]").matches(CraftBlockData.newData(null, "minecraft:chest")));
|
||||
assertFalse(CraftBlockData.newData(null, "minecraft:trapped_chest[facing=east,waterlogged=false]").matches(CraftBlockData.newData(null, "minecraft:chest[waterlogged=true]")));
|
||||
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.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST));
|
||||
Chest two = (Chest) CraftBlockData.newData(null, "minecraft:chest[waterlogged=false]");
|
||||
|
||||
Assert.assertTrue(one.matches(two));
|
||||
Assert.assertFalse(two.matches(one));
|
||||
assertTrue(one.matches(two));
|
||||
assertFalse(two.matches(one));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,15 +159,15 @@ public class BlockDataTest extends AbstractTestingBase {
|
||||
String dataString = "minecraft:chest[facing=east,waterlogged=true]";
|
||||
BlockData data = CraftBlockData.newData(null, dataString);
|
||||
|
||||
Assert.assertThat(data.getAsString(true), is(dataString));
|
||||
Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]"));
|
||||
assertThat(data.getAsString(true), is(dataString));
|
||||
assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=true]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAsString2() {
|
||||
Chest data = (Chest) CraftBlockData.fromData(Blocks.CHEST.defaultBlockState().setValue(BlockChest.FACING, EnumDirection.EAST));
|
||||
|
||||
Assert.assertThat(data.getAsString(true), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
|
||||
Assert.assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
|
||||
assertThat(data.getAsString(true), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
|
||||
assertThat(data.getAsString(false), is("minecraft:chest[facing=east,type=single,waterlogged=false]"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user