summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorfullwall <fullwall@optusnet.com>2012-01-09 14:39:06 +0800
committerEvilSeph <evilseph@gmail.com>2012-02-10 17:26:38 -0500
commitd99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6 (patch)
treef9b8f32218a2a35d3a90e35eda71d2c297106ee4 /src/test/java
parentec01da91bbba8d4a1d928df6273389923491e75e (diff)
downloadbukkit-d99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6.tar
bukkit-d99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6.tar.gz
bukkit-d99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6.tar.lz
bukkit-d99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6.tar.xz
bukkit-d99c95f6d1b9a91f5f9c254b8e2fa615ea31e3c6.zip
[Bleeding] Added Potions API. Fixes BUKKIT-389
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/bukkit/plugin/messaging/TestPlayer.java27
-rw-r--r--src/test/java/org/bukkit/potion/PotionTest.java109
2 files changed, 136 insertions, 0 deletions
diff --git a/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java b/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java
index 95e02c76..63180720 100644
--- a/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java
+++ b/src/test/java/org/bukkit/plugin/messaging/TestPlayer.java
@@ -1,6 +1,7 @@
package org.bukkit.plugin.messaging;
import java.net.InetSocketAddress;
+import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -23,6 +24,8 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
+import org.bukkit.potion.PotionEffect;
+import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public class TestPlayer implements Player {
@@ -621,4 +624,28 @@ public class TestPlayer implements Player {
public boolean canSee(Player player) {
throw new UnsupportedOperationException("Not supported yet.");
}
+
+ public boolean addPotionEffect(PotionEffect effect) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean addPotionEffect(PotionEffect effect, boolean force) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean addPotionEffects(Collection<PotionEffect> effects) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public boolean hasPotionEffect(PotionEffectType type) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public void removePotionEffect(PotionEffectType type) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ public Collection<PotionEffect> getActivePotionEffects() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
}
diff --git a/src/test/java/org/bukkit/potion/PotionTest.java b/src/test/java/org/bukkit/potion/PotionTest.java
new file mode 100644
index 00000000..fe641b86
--- /dev/null
+++ b/src/test/java/org/bukkit/potion/PotionTest.java
@@ -0,0 +1,109 @@
+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.bukkit.potion.Potion.Tier;
+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.getTier() == Tier.TWO);
+ }
+
+ @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() {
+ 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 setTier() {
+ Potion potion = new Potion(PotionType.POISON);
+ assertThat(potion.getTier(), is(Tier.ONE));
+ potion.setTier(Tier.TWO);
+ assertThat(potion.getTier(), is(Tier.TWO));
+ assertTrue(potion.toDamageValue() == (PotionType.POISON.getDamageValue() | potion.getTier().getDamageBit()));
+ }
+
+ @Test
+ public void useNulls() {
+ try {
+ new Potion(null);
+ fail("cannot use null type in constructor");
+ } catch (IllegalArgumentException ex) {
+ }
+
+ try {
+ new Potion(PotionType.POISON, null);
+ fail("cannot use null tier in constructor");
+ } catch (IllegalArgumentException ex) {
+ }
+
+ Potion potion = new Potion(PotionType.POISON);
+ try {
+ potion.setTier(null);
+ fail("cannot set a null tier");
+ } catch (IllegalArgumentException ex) {
+ }
+
+ try {
+ potion.apply((ItemStack) null);
+ fail("cannot apply to a null itemstack");
+ } catch (IllegalArgumentException ex) {
+ }
+
+ try {
+ potion.apply((LivingEntity) null);
+ fail("cannot apply to a null entity");
+ } catch (IllegalArgumentException ex) {
+ }
+ }
+
+ private static final int EXTENDED_BIT = 0x40;
+ private static final int SPLASH_BIT = 0x4000;
+}