Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-24 15:20:11 +01:00
1c14586c49
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.
67 Zeilen
2.1 KiB
Java
67 Zeilen
2.1 KiB
Java
package org.bukkit;
|
|
|
|
import static org.hamcrest.CoreMatchers.is;
|
|
import static org.hamcrest.Matchers.hasSize;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
import java.util.EnumMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import net.minecraft.server.EnumArt;
|
|
|
|
import org.bukkit.craftbukkit.CraftArt;
|
|
import org.junit.Test;
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
public class ArtTest {
|
|
private static final int UNIT_MULTIPLIER = 16;
|
|
|
|
@Test
|
|
public void verifyMapping() {
|
|
List<Art> arts = Lists.newArrayList(Art.values());
|
|
|
|
for (EnumArt enumArt : EnumArt.values()) {
|
|
int id = enumArt.ordinal();
|
|
String name = enumArt.B;
|
|
int width = enumArt.C / UNIT_MULTIPLIER;
|
|
int height = enumArt.D / UNIT_MULTIPLIER;
|
|
|
|
Art subject = Art.getById(id);
|
|
|
|
String message = String.format("org.bukkit.Art is missing id: %d named: '%s'", id - Achievement.STATISTIC_OFFSET, name);
|
|
assertNotNull(message, subject);
|
|
|
|
assertThat(Art.getByName(name), is(subject));
|
|
assertThat("Art." + subject + "'s width", subject.getBlockWidth(), is(width));
|
|
assertThat("Art." + subject + "'s height", subject.getBlockHeight(), is(height));
|
|
|
|
arts.remove(subject);
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|