13
0
geforkt von Mirrors/Paper

[Bleeding] Fixed potion tests.

By: Celtic Minstrel <celtic.minstrel.ca@some.place>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2012-02-25 17:57:42 -05:00
Ursprung e1b9154af1
Commit ed0584f930
2 geänderte Dateien mit 32 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -14,8 +14,6 @@ import org.bukkit.inventory.ItemStack;
public class Potion { public class Potion {
private boolean extended = false; private boolean extended = false;
private boolean splash = false; private boolean splash = false;
@Deprecated
private Tier tier = Tier.ONE;
private int level = 1; private int level = 1;
private int name = -1; private int name = -1;
private PotionType type; private PotionType type;
@ -194,7 +192,7 @@ public class Potion {
*/ */
@Deprecated @Deprecated
public Tier getTier() { public Tier getTier() {
return tier; return level == 2 ? Tier.TWO : Tier.ONE;
} }
/** /**
@ -267,7 +265,6 @@ public class Potion {
@Deprecated @Deprecated
public void setTier(Tier tier) { public void setTier(Tier tier) {
Validate.notNull(tier, "tier cannot be null"); Validate.notNull(tier, "tier cannot be null");
this.tier = tier;
this.level = (tier == Tier.TWO ? 2 : 1); this.level = (tier == Tier.TWO ? 2 : 1);
} }
@ -292,7 +289,6 @@ public class Potion {
int max = type.getMaxLevel(); int max = type.getMaxLevel();
Validate.isTrue(level > 0 && level <= max, "Level must be " + (max == 1 ? "" : "between 1 and ") + max + " for this potion"); Validate.isTrue(level > 0 && level <= max, "Level must be " + (max == 1 ? "" : "between 1 and ") + max + " for this potion");
this.level = level; this.level = level;
this.tier = level == 2 ? Tier.TWO : Tier.ONE;
} }
/** /**
@ -309,9 +305,9 @@ public class Potion {
// Without this, mundanePotion.toDamageValue() would return 0 // Without this, mundanePotion.toDamageValue() would return 0
damage = (short) (name == 0 ? 8192 : name); damage = (short) (name == 0 ? 8192 : name);
} else { } else {
damage = (short) level; damage = (short) (level - 1);
damage = (short) type.getDamageValue(); damage <<= TIER_SHIFT;
damage |= level << TIER_SHIFT; damage |= (short) type.getDamageValue();
} }
if (splash) { if (splash) {
damage |= SPLASH_BIT; damage |= SPLASH_BIT;

Datei anzeigen

@ -6,7 +6,6 @@ import static org.hamcrest.Matchers.is;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion.Tier;
import org.junit.Test; import org.junit.Test;
public class PotionTest { public class PotionTest {
@ -25,7 +24,7 @@ public class PotionTest {
potion = Potion.fromDamage(PotionType.POISON.getDamageValue() | SPLASH_BIT); potion = Potion.fromDamage(PotionType.POISON.getDamageValue() | SPLASH_BIT);
assertTrue(potion.getType() == PotionType.POISON && potion.isSplash()); assertTrue(potion.getType() == PotionType.POISON && potion.isSplash());
potion = Potion.fromDamage(0x25 /* Potion of Healing II */); potion = Potion.fromDamage(0x25 /* Potion of Healing II */);
assertTrue(potion.getType() == PotionType.INSTANT_HEAL && potion.getTier() == Tier.TWO); assertTrue(potion.getType() == PotionType.INSTANT_HEAL && potion.getLevel() == 2);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -45,6 +44,22 @@ public class PotionTest {
@Test @Test
public void setExtended() { 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); Potion potion = new Potion(PotionType.POISON);
assertFalse(potion.hasExtendedDuration()); assertFalse(potion.hasExtendedDuration());
potion.setHasExtendedDuration(true); potion.setHasExtendedDuration(true);
@ -62,32 +77,32 @@ public class PotionTest {
} }
@Test @Test
public void setTier() { public void setLevel() {
Potion potion = new Potion(PotionType.POISON); Potion potion = new Potion(PotionType.POISON);
assertThat(potion.getTier(), is(Tier.ONE)); assertEquals(1, potion.getLevel());
potion.setTier(Tier.TWO); potion.setLevel(2);
assertThat(potion.getTier(), is(Tier.TWO)); assertEquals(2, potion.getLevel());
assertTrue(potion.toDamageValue() == (PotionType.POISON.getDamageValue() | potion.getTier().getDamageBit())); assertTrue((potion.toDamageValue() & 0x3F) == (PotionType.POISON.getDamageValue() | 0x20));
} }
@Test @Test
public void useNulls() { public void useNulls() {
try { try {
new Potion(null); new Potion(null, 2);
fail("cannot use null type in constructor"); fail("cannot use null type in constructor with a level");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
} }
try { try {
new Potion(PotionType.POISON, null); new Potion(PotionType.POISON, 3);
fail("cannot use null tier in constructor"); fail("level must be less than 3 in constructor");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
} }
Potion potion = new Potion(PotionType.POISON); Potion potion = new Potion(PotionType.POISON);
try { try {
potion.setTier(null); potion.setLevel(3);
fail("cannot set a null tier"); fail("level must be set less than 3");
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
} }