diff options
author | Wesley Wolfe <weswolf@aol.com> | 2012-11-01 03:38:25 -0500 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2012-11-02 00:24:11 -0500 |
commit | 3dd0580d50fe05afce8dba20cf9e383624f56ae4 (patch) | |
tree | 7a7f2a8d5965038500e5e1f86d8afb8f8febf443 /src | |
parent | 87d25c4cc68b23e5f4d06fb60d6002419e3c6d5e (diff) | |
download | craftbukkit-3dd0580d50fe05afce8dba20cf9e383624f56ae4.tar craftbukkit-3dd0580d50fe05afce8dba20cf9e383624f56ae4.tar.gz craftbukkit-3dd0580d50fe05afce8dba20cf9e383624f56ae4.tar.lz craftbukkit-3dd0580d50fe05afce8dba20cf9e383624f56ae4.tar.xz craftbukkit-3dd0580d50fe05afce8dba20cf9e383624f56ae4.zip |
Improved the potion test to detect missing PotionType values.
Diffstat (limited to 'src')
-rw-r--r-- | src/test/java/org/bukkit/potion/PotionTest.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/test/java/org/bukkit/potion/PotionTest.java b/src/test/java/org/bukkit/potion/PotionTest.java index edc308f8..1f0a2c52 100644 --- a/src/test/java/org/bukkit/potion/PotionTest.java +++ b/src/test/java/org/bukkit/potion/PotionTest.java @@ -1,6 +1,11 @@ package org.bukkit.potion; import static org.junit.Assert.*; +import static org.hamcrest.Matchers.*; + +import java.lang.reflect.Field; +import java.util.EnumMap; +import java.util.Map; import org.bukkit.craftbukkit.potion.CraftPotionBrewer; import org.junit.BeforeClass; @@ -9,6 +14,7 @@ import org.junit.Test; import net.minecraft.server.MobEffectList; public class PotionTest { + @BeforeClass public static void setUp() { Potion.setPotionBrewer(new CraftPotionBrewer()); @@ -20,8 +26,32 @@ public class PotionTest { public void getEffects() { for (PotionType type : PotionType.values()) { for (PotionEffect effect : new Potion(type).getEffects()) { - assertTrue(effect.getType() == PotionEffectType.getById(effect.getType().getId())); + PotionEffectType potionType = effect.getType(); + assertThat(effect.getType(), is(sameInstance(PotionEffectType.getById(potionType.getId())))); + + assertNotNull(potionType.getName(), PotionType.getByEffect(potionType)); } } } + + @Test + public void testEffectCompleteness() throws SecurityException, IllegalAccessException, NoSuchFieldException { + Field durationsField = net.minecraft.server.PotionBrewer.class.getDeclaredField("effectDurations"); + durationsField.setAccessible(true); + Map<Integer, ?> effectDurations = (Map<Integer, ?>) durationsField.get(null); + + 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); + + assertThat(enumType.name(), effects.put(enumType, enumType.name()), is((String)null)); + } + + assertThat(effects.entrySet(), hasSize(effectDurations.size())); + assertThat(effectDurations.entrySet(), hasSize(PotionType.values().length - /* WATER */ 1)); + } } |