From 7e752644d95ddcb188e00472efb744ac7f7cbbcb Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 3 Sep 2024 23:20:36 -0400 Subject: [PATCH] NPE fix --- .../java/electrosphere/entity/types/item/ItemUtils.java | 8 ++++++++ .../entity/types/item/ItemUtilsUnitTests.java | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/electrosphere/entity/types/item/ItemUtils.java b/src/main/java/electrosphere/entity/types/item/ItemUtils.java index bc40f068..9f4955dc 100644 --- a/src/main/java/electrosphere/entity/types/item/ItemUtils.java +++ b/src/main/java/electrosphere/entity/types/item/ItemUtils.java @@ -466,7 +466,15 @@ public class ItemUtils { return (String)item.getData(EntityDataStrings.ITEM_ICON); } + /** + * Gets the equip class of the item + * @param item The item + * @return The equip class of the item. Null if null is passed in + */ public static String getEquipClass(Entity item){ + if(item == null){ + return null; + } return (String)item.getData(EntityDataStrings.ITEM_EQUIP_CLASS); } diff --git a/src/test/java/electrosphere/entity/types/item/ItemUtilsUnitTests.java b/src/test/java/electrosphere/entity/types/item/ItemUtilsUnitTests.java index f57b55f2..0c0b221b 100644 --- a/src/test/java/electrosphere/entity/types/item/ItemUtilsUnitTests.java +++ b/src/test/java/electrosphere/entity/types/item/ItemUtilsUnitTests.java @@ -24,4 +24,11 @@ public class ItemUtilsUnitTests { Assertions.assertEquals(false, result); } + @UnitTest + @FastTest + public void getEquipClass_NullEntity_False(){ + String result = ItemUtils.getEquipClass(null); + Assertions.assertEquals(null, result); + } + }