SPIGOT-7267: Fix EntityType#getTranslationKey() and add unit test

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot 2023-02-20 19:35:39 +11:00
parent b83c3d9c17
commit 412e157d39
2 changed files with 12 additions and 1 deletions

View file

@ -377,7 +377,8 @@ public final class CraftMagicNumbers implements UnsafeValues {
@Override
public String getTranslationKey(EntityType entityType) {
return EntityTypes.byString(entityType.name()).map(EntityTypes::getDescriptionId).orElseThrow();
Preconditions.checkArgument(entityType.getName() != null, "Invalid name of EntityType %s for translation key", entityType);
return EntityTypes.byString(entityType.getName()).map(EntityTypes::getDescriptionId).orElseThrow();
}
@Override

View file

@ -27,4 +27,14 @@ public class EntityTypesTest extends AbstractTestingBase {
Assert.assertTrue("Unmapped bukkit entities " + allBukkit, allBukkit.isEmpty());
}
@Test
public void testTranslationKey() {
for (EntityType entityType : EntityType.values()) {
// Currently EntityType#getTranslationKey has a validation for null name then for test skip this and check correct names.
if (entityType.getName() != null) {
Assert.assertNotNull("Nulllable translation key for " + entityType, entityType.getTranslationKey());
}
}
}
}