craftbukkit/src/test/java/org/bukkit/potion/PotionTest.java

49 lines
1.6 KiB
Java
Raw Normal View History

package org.bukkit.potion;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;
import java.util.EnumMap;
2016-03-01 08:32:46 +11:00
import java.util.List;
import java.util.Map;
2016-03-01 08:32:46 +11:00
import net.minecraft.server.MobEffect;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.PotionRegistry;
import org.bukkit.support.AbstractTestingBase;
import org.junit.Test;
public class PotionTest extends AbstractTestingBase {
@Test
public void getEffects() {
for (PotionType type : PotionType.values()) {
for (PotionEffect effect : new Potion(type).getEffects()) {
PotionEffectType potionType = effect.getType();
assertThat(effect.getType(), is(sameInstance(PotionEffectType.getById(potionType.getId()))));
assertNotNull(potionType.getName(), PotionType.getByEffect(potionType));
}
}
}
@Test
public void testEffectCompleteness() throws Throwable {
Map<PotionType, String> effects = new EnumMap(PotionType.class);
2016-03-01 08:32:46 +11:00
for (PotionRegistry reg : PotionRegistry.a) {
List<MobEffect> eff = reg.a();
if (eff.size() != 1) continue;
int id = MobEffectList.getId(eff.get(0).getMobEffect());
PotionEffectType type = PotionEffectType.getById(id);
assertNotNull(String.valueOf(id), PotionEffectType.getById(id));
PotionType enumType = PotionType.getByEffect(type);
assertNotNull(type.getName(), enumType);
2016-03-01 08:32:46 +11:00
effects.put(enumType, enumType.name());
}
2016-03-01 08:32:46 +11:00
assertEquals(effects.entrySet().size(), PotionType.values().length - /* WATER */ 1);
}
}