13
0
geforkt von Mirrors/Paper

Add CraftArt mappings for Wither. Fixes BUKKIT-2667.

The static assertions are not normally evaluated in the JVM, and failed
to fail when the enums went from size 25 to size 26. This meant missing
values would not be detected at runtime and instead return null,
compounding problems later. The switches should never evaluate to null
so will instead throw runtime assertion errors.

Additional unit tests were added to detect new paintings and assure they
have proper, unique mappings. The test checks both that a mapping
exists, is not null, and does not duplicate another mapping.

By: Wesley Wolfe <weswolf@aol.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2012-11-01 03:06:47 -05:00
Ursprung 1816b5b800
Commit 6577736185
2 geänderte Dateien mit 30 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,7 @@ import org.bukkit.Art;
// Safety class, will break if either side changes // Safety class, will break if either side changes
public class CraftArt { public class CraftArt {
public static Art NotchToBukkit(EnumArt art) { public static Art NotchToBukkit(EnumArt art) {
switch (art) { switch (art) {
case KEBAB: return Art.KEBAB; case KEBAB: return Art.KEBAB;
@ -32,8 +33,10 @@ public class CraftArt {
case BURNINGSKULL: return Art.BURNINGSKULL; case BURNINGSKULL: return Art.BURNINGSKULL;
case SKELETON: return Art.SKELETON; case SKELETON: return Art.SKELETON;
case DONKEYKONG: return Art.DONKEYKONG; case DONKEYKONG: return Art.DONKEYKONG;
case WITHER: return Art.WITHER;
default:
throw new AssertionError(art);
} }
return null;
} }
public static EnumArt BukkitToNotch(Art art) { public static EnumArt BukkitToNotch(Art art) {
@ -63,12 +66,9 @@ public class CraftArt {
case BURNINGSKULL: return EnumArt.BURNINGSKULL; case BURNINGSKULL: return EnumArt.BURNINGSKULL;
case SKELETON: return EnumArt.SKELETON; case SKELETON: return EnumArt.SKELETON;
case DONKEYKONG: return EnumArt.DONKEYKONG; case DONKEYKONG: return EnumArt.DONKEYKONG;
case WITHER: return EnumArt.WITHER;
default:
throw new AssertionError(art);
} }
return null;
}
static {
assert (EnumArt.values().length == 25);
assert (Art.values().length == 25);
} }
} }

Datei anzeigen

@ -5,10 +5,13 @@ import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import java.util.EnumMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.minecraft.server.EnumArt; import net.minecraft.server.EnumArt;
import org.bukkit.craftbukkit.CraftArt;
import org.junit.Test; import org.junit.Test;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -40,4 +43,24 @@ public class ArtTest {
assertThat("org.bukkit.Art has too many arts", arts, hasSize(0)); assertThat("org.bukkit.Art has too many arts", arts, hasSize(0));
} }
@Test
public void testCraftArtToNotch() {
Map<EnumArt, Art> cache = new EnumMap(EnumArt.class);
for (Art art : Art.values()) {
EnumArt enumArt = CraftArt.BukkitToNotch(art);
assertNotNull(art.name(), enumArt);
assertThat(art.name(), cache.put(enumArt, art), is((Art) null));
}
}
@Test
public void testCraftArtToBukkit() {
Map<Art, EnumArt> cache = new EnumMap(Art.class);
for (EnumArt enumArt : EnumArt.values()) {
Art art = CraftArt.NotchToBukkit(enumArt);
assertNotNull(enumArt.name(), art);
assertThat(enumArt.name(), cache.put(art, enumArt), is((EnumArt) null));
}
}
} }