1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
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.*;
import org.junit.Assert;
import org.junit.Test;
public class BlockDataTest extends AbstractTestingBase {
@Test
public void testParsing() {
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3));
BlockData materialString = CraftBlockData.newData(Material.CAKE, "[bites=3]");
Assert.assertThat(materialString, is(cakeTest));
BlockData combined = CraftBlockData.newData(null, "cake[bites=3]");
Assert.assertThat(combined, is(cakeTest));
BlockData combinedMinecraft = CraftBlockData.newData(null, "minecraft:cake[bites=3]");
Assert.assertThat(combinedMinecraft, is(cakeTest));
BlockData inverted = CraftBlockData.newData(null, cakeTest.getAsString());
Assert.assertThat(inverted, is(cakeTest));
}
@Test(expected = IllegalArgumentException.class)
public void testBadMaterial() {
CraftBlockData.newData(null, "invalid");
}
@Test(expected = IllegalArgumentException.class)
public void testBadSyntax() {
CraftBlockData.newData(null, "minecraft:cake[bites=3");
}
@Test(expected = IllegalArgumentException.class)
public void testDoubleMaterial() {
CraftBlockData.newData(Material.CAKE, "minecraft:cake[bites=3]");
}
@Test(expected = IllegalArgumentException.class)
public void testMistake() {
BlockData cakeTest = CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(BlockCake.BITES, 3));
CraftBlockData.newData(Material.CAKE, cakeTest.toString());
}
@Test(expected = IllegalArgumentException.class)
public void testItem() {
CraftBlockData.newData(Material.DIAMOND_AXE, null);
}
@Test(expected = IllegalArgumentException.class)
public void testItemParse() {
CraftBlockData.newData(null, "minecraft:diamond_axe");
}
@Test
public void testClone() {
Cake cakeTest = (Cake) CraftBlockData.fromData(Blocks.CAKE.getBlockData().set(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));
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));
}
}
|