diff options
author | ryanbennitt <ryanbennitt@googlemail.com> | 2016-03-01 08:30:03 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2016-03-01 08:30:03 +1100 |
commit | f16cc648404ac87f5292ab67641395c818a477ab (patch) | |
tree | caf0a5479c547b1469113e19518785c4565e7cb4 /src/test/java | |
parent | d41eed2abe83527d2226ec004186cfefc5e1d032 (diff) | |
download | bukkit-f16cc648404ac87f5292ab67641395c818a477ab.tar bukkit-f16cc648404ac87f5292ab67641395c818a477ab.tar.gz bukkit-f16cc648404ac87f5292ab67641395c818a477ab.tar.lz bukkit-f16cc648404ac87f5292ab67641395c818a477ab.tar.xz bukkit-f16cc648404ac87f5292ab67641395c818a477ab.zip |
SPIGOT-1389: Fixed issues with setting tree species by expanding API
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/bukkit/materials/MaterialDataTest.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/materials/MaterialDataTest.java b/src/test/java/org/bukkit/materials/MaterialDataTest.java index e888381d..41dff993 100644 --- a/src/test/java/org/bukkit/materials/MaterialDataTest.java +++ b/src/test/java/org/bukkit/materials/MaterialDataTest.java @@ -4,8 +4,14 @@ import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import org.bukkit.Material; +import org.bukkit.TreeSpecies; import org.bukkit.block.BlockFace; import org.bukkit.material.Door; +import org.bukkit.material.Leaves; +import org.bukkit.material.Sapling; +import org.bukkit.material.Tree; +import org.bukkit.material.Wood; +import org.bukkit.material.WoodenStep; import org.junit.Test; public class MaterialDataTest { @@ -58,4 +64,171 @@ public class MaterialDataTest { } } } + + @Test + public void testWood() { + Wood wood = new Wood(); + assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.WOOD)); + assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + for (TreeSpecies species : allSpecies) { + wood = new Wood(species); + assertThat("Constructed with default wood type", wood.getItemType(), equalTo(Material.WOOD)); + assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + } + + Material[] types = new Material[]{Material.WOOD, Material.WOOD_DOUBLE_STEP}; + for (Material type : types) { + wood = new Wood(type); + assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); + assertThat("Constructed with default tree species", wood.getSpecies(), equalTo(TreeSpecies.GENERIC)); + + for (TreeSpecies species : allSpecies) { + wood = new Wood(type, species); + assertThat("Constructed with correct wood type", wood.getItemType(), equalTo(type)); + assertThat("Constructed with correct tree species", wood.getSpecies(), equalTo(species)); + } + } + } + + @Test + public void testTree() { + Tree tree = new Tree(); + assertThat("Constructed with default tree type", tree.getItemType(), equalTo(Material.LOG)); + assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + + tree = new Tree(Material.LOG); + assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(Material.LOG)); + assertThat("Constructed with default tree species", tree.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + + Material[] types = new Material[]{Material.LOG, Material.LOG_2}; + TreeSpecies[][] allSpecies = new TreeSpecies[][]{ + {TreeSpecies.GENERIC, TreeSpecies.REDWOOD, TreeSpecies.BIRCH, TreeSpecies.JUNGLE}, + {TreeSpecies.ACACIA, TreeSpecies.DARK_OAK} + }; + BlockFace[] allDirections = new BlockFace[]{BlockFace.UP, BlockFace.WEST, BlockFace.NORTH, BlockFace.SELF}; + for (int t = 0; t < types.length; t++) { + for (TreeSpecies species : allSpecies[t]) { + tree = new Tree(types[t], species); + assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); + assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + + // check item type is fixed automatically for invalid type-species combo + tree = new Tree(types[types.length - 1 - t], species); + assertThat("Constructed with fixed tree type", tree.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); + assertThat("Constructed with default direction", tree.getDirection(), equalTo(BlockFace.UP)); + for (BlockFace dir : allDirections) { + tree = new Tree(types[t], species, dir); + assertThat("Constructed with correct tree type", tree.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", tree.getSpecies(), equalTo(species)); + assertThat("Constructed with correct direction", tree.getDirection(), equalTo(dir)); + } + } + } + } + + @Test + public void testLeaves() { + Leaves leaves = new Leaves(); + assertThat("Constructed with default leaf type", leaves.getItemType(), equalTo(Material.LEAVES)); + assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); + assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + + leaves = new Leaves(Material.LEAVES); + assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(Material.LEAVES)); + assertThat("Constructed with default tree species", leaves.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); + assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + + Material[] types = new Material[]{Material.LEAVES, Material.LEAVES_2}; + TreeSpecies[][] allSpecies = new TreeSpecies[][]{ + {TreeSpecies.GENERIC, TreeSpecies.REDWOOD, TreeSpecies.BIRCH, TreeSpecies.JUNGLE}, + {TreeSpecies.ACACIA, TreeSpecies.DARK_OAK} + }; + boolean[] decayable = new boolean[]{true, false}; + boolean[] decaying = new boolean[]{true, false}; + for (int t = 0; t < types.length; t++) { + for (TreeSpecies species : allSpecies[t]) { + leaves = new Leaves(types[t], species); + assertThat("Constructed with correct leaf type", leaves.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); + assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); + assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + + // check item type is fixed automatically for invalid type-species combo + leaves = new Leaves(types[types.length - 1 - t], species); + assertThat("Constructed with fixed leaf type", leaves.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); + assertThat("Constructed with default decayable", leaves.isDecayable(), equalTo(true)); + assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + for (boolean isDecayable : decayable) { + leaves = new Leaves(types[t], species, isDecayable); + assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); + assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecayable)); + assertThat("Constructed with default decaying", leaves.isDecaying(), equalTo(false)); + for (boolean isDecaying : decaying) { + leaves = new Leaves(types[t], species, isDecayable); + leaves.setDecaying(isDecaying); + assertThat("Constructed with correct wood type", leaves.getItemType(), equalTo(types[t])); + assertThat("Constructed with correct tree species", leaves.getSpecies(), equalTo(species)); + assertThat("Constructed with correct decayable", leaves.isDecayable(), equalTo(isDecaying || isDecayable)); + assertThat("Constructed with correct decaying", leaves.isDecaying(), equalTo(isDecaying)); + } + } + } + } + } + + @Test + public void testWoodenStep() { + WoodenStep woodenStep = new WoodenStep(); + assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.WOOD_STEP)); + assertThat("Constructed with default tree species", woodenStep.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + boolean[] inversion = new boolean[]{true, false}; + for (TreeSpecies species : allSpecies) { + woodenStep = new WoodenStep(species); + assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.WOOD_STEP)); + assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); + assertThat("Constructed with default inversion", woodenStep.isInverted(), equalTo(false)); + for (boolean isInverted : inversion) { + woodenStep = new WoodenStep(species, isInverted); + assertThat("Constructed with default step type", woodenStep.getItemType(), equalTo(Material.WOOD_STEP)); + assertThat("Constructed with correct tree species", woodenStep.getSpecies(), equalTo(species)); + assertThat("Constructed with correct inversion", woodenStep.isInverted(), equalTo(isInverted)); + } + } + } + + @Test + public void testSapling() { + Sapling sapling = new Sapling(); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with default tree species", sapling.getSpecies(), equalTo(TreeSpecies.GENERIC)); + assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + + TreeSpecies[] allSpecies = TreeSpecies.values(); + boolean[] growable = new boolean[]{true, false}; + for (TreeSpecies species : allSpecies) { + sapling = new Sapling(species); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); + assertThat("Constructed with default growable", sapling.isInstantGrowable(), equalTo(false)); + for (boolean isInstantGrowable : growable) { + sapling = new Sapling(species, isInstantGrowable); + assertThat("Constructed with default sapling type", sapling.getItemType(), equalTo(Material.SAPLING)); + assertThat("Constructed with correct tree species", sapling.getSpecies(), equalTo(species)); + assertThat("Constructed with correct growable", sapling.isInstantGrowable(), equalTo(isInstantGrowable)); + } + } + } } |