2012-01-09 15:51:32 +08:00
|
|
|
package org.bukkit.potion;
|
|
|
|
|
|
|
|
import static org.junit.Assert.*;
|
2012-11-01 03:38:25 -05:00
|
|
|
import static org.hamcrest.Matchers.*;
|
|
|
|
|
|
|
|
import java.util.EnumMap;
|
|
|
|
import java.util.Map;
|
2012-01-09 15:51:32 +08:00
|
|
|
|
2012-12-17 01:31:41 -06:00
|
|
|
import org.bukkit.support.AbstractTestingBase;
|
2012-12-14 02:02:02 -06:00
|
|
|
import org.bukkit.support.Util;
|
2012-01-09 15:51:32 +08:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2012-12-17 01:31:41 -06:00
|
|
|
public class PotionTest extends AbstractTestingBase {
|
2012-01-09 15:51:32 +08:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void getEffects() {
|
|
|
|
for (PotionType type : PotionType.values()) {
|
|
|
|
for (PotionEffect effect : new Potion(type).getEffects()) {
|
2012-11-01 03:38:25 -05:00
|
|
|
PotionEffectType potionType = effect.getType();
|
|
|
|
assertThat(effect.getType(), is(sameInstance(PotionEffectType.getById(potionType.getId()))));
|
|
|
|
|
|
|
|
assertNotNull(potionType.getName(), PotionType.getByEffect(potionType));
|
2012-01-09 15:51:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-01 03:38:25 -05:00
|
|
|
|
|
|
|
@Test
|
2012-12-17 01:31:41 -06:00
|
|
|
public void testEffectCompleteness() throws Throwable {
|
2012-12-14 02:02:02 -06:00
|
|
|
Map<Integer, ?> effectDurations = Util.getInternalState(net.minecraft.server.PotionBrewer.class, null, "effectDurations");
|
2012-11-01 03:38:25 -05:00
|
|
|
|
|
|
|
Map<PotionType, String> effects = new EnumMap(PotionType.class);
|
|
|
|
for (int id : effectDurations.keySet()) {
|
|
|
|
PotionEffectType type = PotionEffectType.getById(id);
|
|
|
|
assertNotNull(String.valueOf(id), PotionEffectType.getById(id));
|
|
|
|
|
|
|
|
PotionType enumType = PotionType.getByEffect(type);
|
|
|
|
assertNotNull(type.getName(), enumType);
|
|
|
|
|
2012-12-17 01:31:41 -06:00
|
|
|
assertThat(enumType.name(), effects.put(enumType, enumType.name()), is(nullValue()));
|
2012-11-01 03:38:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assertThat(effects.entrySet(), hasSize(effectDurations.size()));
|
|
|
|
assertThat(effectDurations.entrySet(), hasSize(PotionType.values().length - /* WATER */ 1));
|
|
|
|
}
|
2012-01-09 15:51:32 +08:00
|
|
|
}
|