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
|
package org.bukkit.potion;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.is;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.junit.Test;
public class PotionTest {
@Test
public void applyToItemStack() {
Potion potion = new Potion(PotionType.POISON);
ItemStack stack = new ItemStack(Material.POTION, 1);
potion.apply(stack);
assertTrue(stack.getDurability() == potion.toDamageValue());
}
@Test
public void fromDamage() {
Potion potion = Potion.fromDamage(PotionType.POISON.getDamageValue());
assertTrue(potion.getType() == PotionType.POISON);
potion = Potion.fromDamage(PotionType.POISON.getDamageValue() | SPLASH_BIT);
assertTrue(potion.getType() == PotionType.POISON && potion.isSplash());
potion = Potion.fromDamage(0x25 /* Potion of Healing II */);
assertTrue(potion.getType() == PotionType.INSTANT_HEAL && potion.getLevel() == 2);
}
@Test(expected = IllegalArgumentException.class)
public void illegalApplyToItemStack() {
Potion potion = new Potion(PotionType.POISON);
potion.apply(new ItemStack(Material.AIR, 1));
}
@Test
public void ItemStackConversion() {
Potion potion = new Potion(PotionType.POISON);
ItemStack itemstack = potion.toItemStack(1);
assertThat(itemstack.getType(), is(Material.POTION));
assertTrue(itemstack.getAmount() == 1);
assertTrue(itemstack.getDurability() == potion.toDamageValue());
}
@Test
public void setExtended() {
PotionEffectType.registerPotionEffectType(new PotionEffectType(19){
@Override
public double getDurationModifier() {
return 1;
}
@Override
public String getName() {
return "Poison";
}
@Override
public boolean isInstant() {
return false;
}
});
Potion potion = new Potion(PotionType.POISON);
assertFalse(potion.hasExtendedDuration());
potion.setHasExtendedDuration(true);
assertTrue(potion.hasExtendedDuration());
assertTrue((potion.toDamageValue() & EXTENDED_BIT) != 0);
}
@Test
public void setSplash() {
Potion potion = new Potion(PotionType.POISON);
assertFalse(potion.isSplash());
potion.setSplash(true);
assertTrue(potion.isSplash());
assertTrue((potion.toDamageValue() & SPLASH_BIT) != 0);
}
@Test
public void setLevel() {
Potion potion = new Potion(PotionType.POISON);
assertEquals(1, potion.getLevel());
potion.setLevel(2);
assertEquals(2, potion.getLevel());
assertTrue((potion.toDamageValue() & 0x3F) == (PotionType.POISON.getDamageValue() | 0x20));
}
@Test(expected=IllegalArgumentException.class)
public void nullType() {
new Potion(null, 2);
}
@Test(expected=IllegalArgumentException.class)
public void maxLevelConstruct() {
new Potion(PotionType.POISON, 3);
}
@Test(expected=IllegalArgumentException.class)
public void maxLevelSet() {
Potion potion = new Potion(PotionType.POISON);
potion.setLevel(3);
}
@Test(expected=IllegalArgumentException.class)
public void nullStack() {
Potion potion = new Potion(PotionType.POISON);
potion.apply((ItemStack) null);
}
@Test(expected=IllegalArgumentException.class)
public void nullEntity() {
Potion potion = new Potion(PotionType.POISON);
potion.apply((LivingEntity) null);
}
@Test
public void water() {
Potion potion = new Potion(PotionType.WATER);
assertEquals(0, potion.getLevel());
assertFalse(potion.isSplash());
assertFalse(potion.hasExtendedDuration());
assertEquals(0, potion.toDamageValue());
}
@Test
public void mundane() {
Potion potion = new Potion(0);
assertFalse(potion.getType() == PotionType.WATER);
assertFalse(potion.toDamageValue() == 0);
assertEquals(8192, potion.toDamageValue());
Potion potion2 = Potion.fromDamage(8192);
assertEquals(potion, potion2);
assertEquals(0, potion.getLevel());
}
@Test
public void awkward() {
Potion potion = new Potion(16);
assertEquals(16, potion.getNameId());
assertFalse(potion.isSplash());
assertFalse(potion.hasExtendedDuration());
assertNull(potion.getType());
assertEquals(16, potion.toDamageValue());
}
private static final int EXTENDED_BIT = 0x40;
private static final int SPLASH_BIT = 0x4000;
}
|