From fef68513a53926a20e8308438c0a173b91f2f221 Mon Sep 17 00:00:00 2001 From: Velizar Todorov Date: Tue, 30 Nov 2021 19:12:11 +0100 Subject: [PATCH] :hammer: refactor `LegendaryItem` validation --- src/main/java/com/gildedrose/item_helpers/ItemType.java | 1 - src/main/java/com/gildedrose/items/LegendaryItem.java | 7 ++++--- src/test/java/com/gildedrose/items/LegendaryItemTest.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gildedrose/item_helpers/ItemType.java b/src/main/java/com/gildedrose/item_helpers/ItemType.java index 9ab83a1f..bc19e142 100644 --- a/src/main/java/com/gildedrose/item_helpers/ItemType.java +++ b/src/main/java/com/gildedrose/item_helpers/ItemType.java @@ -12,7 +12,6 @@ public interface ItemType { String QUALITY_ERROR_MESSAGE = "Quality cannot be negative! Current value: "; String OUT_OF_BOUND_QUALITY_MESSAGE = "Quality cannot be above 50! Current value: "; - String NOT_LEGENDARY_ITEM_ERROR_MESSAGE = "Item is legendary, quality must be always 80! Current value: "; static boolean qualityIsNegative(Item item) { return item.quality < 0; diff --git a/src/main/java/com/gildedrose/items/LegendaryItem.java b/src/main/java/com/gildedrose/items/LegendaryItem.java index 9ccfd3de..125ac0fd 100644 --- a/src/main/java/com/gildedrose/items/LegendaryItem.java +++ b/src/main/java/com/gildedrose/items/LegendaryItem.java @@ -7,6 +7,7 @@ public class LegendaryItem implements ItemType { public static final int LEGENDARY_ITEM_QUALITY = 80; public static final String LEGENDARY = "Sulfuras, Hand of Ragnaros"; + public static final String NOT_LEGENDARY_ITEM_ERROR_MESSAGE = "Item is legendary, quality must be always 80! Current value: "; private final Item item; @@ -22,7 +23,7 @@ public class LegendaryItem implements ItemType { @Override public void validateQuality() { - if (isLegendaryWrongQuality(item)) { + if (qualityIsNotLegendary(item)) { throw new IllegalArgumentException(NOT_LEGENDARY_ITEM_ERROR_MESSAGE + item.quality); } } @@ -36,8 +37,8 @@ public class LegendaryItem implements ItemType { item.sellIn--; } - public static boolean isLegendaryWrongQuality(Item item) { - return item.name.equals(LEGENDARY) && item.quality != LEGENDARY_ITEM_QUALITY; + public static boolean qualityIsNotLegendary(Item item) { + return item.quality != LEGENDARY_ITEM_QUALITY; } } diff --git a/src/test/java/com/gildedrose/items/LegendaryItemTest.java b/src/test/java/com/gildedrose/items/LegendaryItemTest.java index b352fc43..56404622 100644 --- a/src/test/java/com/gildedrose/items/LegendaryItemTest.java +++ b/src/test/java/com/gildedrose/items/LegendaryItemTest.java @@ -8,7 +8,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; import static com.gildedrose.helper.TestHelper.testItem; -import static com.gildedrose.item_helpers.ItemType.NOT_LEGENDARY_ITEM_ERROR_MESSAGE; +import static com.gildedrose.items.LegendaryItem.NOT_LEGENDARY_ITEM_ERROR_MESSAGE; import static com.gildedrose.items.LegendaryItem.LEGENDARY; import static com.gildedrose.items.LegendaryItem.LEGENDARY_ITEM_QUALITY; import static org.junit.jupiter.api.Assertions.assertThrows;