mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
🔨 move item name to implementations
This commit is contained in:
parent
39a0e60141
commit
fa28c30215
@ -7,28 +7,28 @@ import com.gildedrose.items.LegendaryItem;
|
|||||||
import com.gildedrose.items.NormalItem;
|
import com.gildedrose.items.NormalItem;
|
||||||
import com.gildedrose.main.Item;
|
import com.gildedrose.main.Item;
|
||||||
|
|
||||||
import static com.gildedrose.item_helpers.ItemName.getItemName;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ItemFactory {
|
public class ItemFactory {
|
||||||
|
|
||||||
private ItemFactory() {
|
private ItemFactory() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemType getItemType(Item item) {
|
public static ItemType getItemType(Item item) {
|
||||||
QualityValidator.validateQuality(item);
|
QualityValidator.validateQuality(item);
|
||||||
ItemName itemName = getItemName(item.name);
|
ItemType itemType = getItems(item).get(item.name);
|
||||||
switch (itemName) {
|
if (itemType == null) {
|
||||||
case AGED_BRIE:
|
itemType = new NormalItem(item);
|
||||||
return new AgedBrieItem(item);
|
|
||||||
case LEGENDARY:
|
|
||||||
return new LegendaryItem(item);
|
|
||||||
case BACKSTAGE_PASS:
|
|
||||||
return new BackstagePassItem(item);
|
|
||||||
case CONJURED:
|
|
||||||
return new ConjuredItem(item);
|
|
||||||
default:
|
|
||||||
return new NormalItem(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, ItemType> getItems(Item item) {
|
||||||
|
return Stream.of(new NormalItem(item), new AgedBrieItem(item), new LegendaryItem(item),
|
||||||
|
new BackstagePassItem(item), new ConjuredItem(item))
|
||||||
|
.collect(Collectors.toMap(ItemType::getName, itemType -> itemType));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,30 +0,0 @@
|
|||||||
package com.gildedrose.item_helpers;
|
|
||||||
|
|
||||||
public enum ItemName {
|
|
||||||
|
|
||||||
LEGENDARY("Sulfuras, Hand of Ragnaros"),
|
|
||||||
NORMAL("Normal"),
|
|
||||||
AGED_BRIE("Aged Brie"),
|
|
||||||
BACKSTAGE_PASS("Backstage passes to a TAFKAL80ETC concert"),
|
|
||||||
CONJURED("Conjured Mana Cake");
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
|
|
||||||
ItemName(String input) {
|
|
||||||
this.name = input;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemName getItemName(String input) {
|
|
||||||
for (ItemName itemName : ItemName.values()) {
|
|
||||||
if (itemName.name.equalsIgnoreCase(input)) {
|
|
||||||
return itemName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NORMAL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,4 +2,6 @@ package com.gildedrose.item_helpers;
|
|||||||
|
|
||||||
public interface ItemType {
|
public interface ItemType {
|
||||||
void updateQuality();
|
void updateQuality();
|
||||||
|
|
||||||
|
String getName();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,27 @@ import com.gildedrose.main.Item;
|
|||||||
|
|
||||||
public class AgedBrieItem implements ItemType {
|
public class AgedBrieItem implements ItemType {
|
||||||
|
|
||||||
private final ItemHandler item;
|
public static final String AGED_BRIE = "Aged Brie";
|
||||||
|
|
||||||
public AgedBrieItem(Item item) {
|
private final ItemHandler item;
|
||||||
this.item = new ItemHandler(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public AgedBrieItem(Item item) {
|
||||||
public void updateQuality() {
|
this.item = new ItemHandler(item);
|
||||||
item.decrementSellInDate();
|
}
|
||||||
if (item.beforeSellInDate()) {
|
|
||||||
item.incrementQuality();
|
@Override
|
||||||
} else {
|
public void updateQuality() {
|
||||||
item.incrementQualityBy2();
|
item.decrementSellInDate();
|
||||||
}
|
if (item.beforeSellInDate()) {
|
||||||
|
item.incrementQuality();
|
||||||
|
} else {
|
||||||
|
item.incrementQualityBy2();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return AGED_BRIE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,24 +6,30 @@ import com.gildedrose.main.Item;
|
|||||||
|
|
||||||
public class BackstagePassItem implements ItemType {
|
public class BackstagePassItem implements ItemType {
|
||||||
|
|
||||||
private final ItemHandler item;
|
public static final String BACKSTAGE_PASS = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
|
private final ItemHandler item;
|
||||||
|
|
||||||
public BackstagePassItem(Item item) {
|
public BackstagePassItem(Item item) {
|
||||||
this.item = new ItemHandler(item);
|
this.item = new ItemHandler(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
item.decrementSellInDate();
|
item.decrementSellInDate();
|
||||||
if (item.moreThan10DaysToSellIn()) {
|
if (item.moreThan10DaysToSellIn()) {
|
||||||
item.incrementQuality();
|
item.incrementQuality();
|
||||||
} else if (item.lessThan10DaysToSellIn()) {
|
} else if (item.lessThan10DaysToSellIn()) {
|
||||||
item.incrementQualityBy2();
|
item.incrementQualityBy2();
|
||||||
} else if (item.lessThan5DaysToSellIn()) {
|
} else if (item.lessThan5DaysToSellIn()) {
|
||||||
item.incrementQualityBy3();
|
item.incrementQualityBy3();
|
||||||
} else {
|
} else {
|
||||||
item.makeQualityZero();
|
item.makeQualityZero();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return BACKSTAGE_PASS;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,27 @@ import com.gildedrose.main.Item;
|
|||||||
|
|
||||||
public class ConjuredItem implements ItemType {
|
public class ConjuredItem implements ItemType {
|
||||||
|
|
||||||
private final ItemHandler item;
|
public static final String CONJURED = "Conjured Mana Cake";
|
||||||
|
|
||||||
public ConjuredItem(Item item) {
|
private final ItemHandler item;
|
||||||
this.item = new ItemHandler(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ConjuredItem(Item item) {
|
||||||
public void updateQuality() {
|
this.item = new ItemHandler(item);
|
||||||
item.decrementSellInDate();
|
}
|
||||||
if (item.beforeSellInDate()) {
|
|
||||||
item.decrementQualityBy2();
|
@Override
|
||||||
} else {
|
public void updateQuality() {
|
||||||
item.decrementQualityBy4();
|
item.decrementSellInDate();
|
||||||
}
|
if (item.beforeSellInDate()) {
|
||||||
|
item.decrementQualityBy2();
|
||||||
|
} else {
|
||||||
|
item.decrementQualityBy4();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return CONJURED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,29 +4,33 @@ import com.gildedrose.item_helpers.ItemHandler;
|
|||||||
import com.gildedrose.item_helpers.ItemType;
|
import com.gildedrose.item_helpers.ItemType;
|
||||||
import com.gildedrose.main.Item;
|
import com.gildedrose.main.Item;
|
||||||
|
|
||||||
import static com.gildedrose.item_helpers.ItemName.LEGENDARY;
|
|
||||||
|
|
||||||
public class LegendaryItem implements ItemType {
|
public class LegendaryItem implements ItemType {
|
||||||
|
|
||||||
public static final int LEGENDARY_ITEM_QUALITY = 80;
|
public static final int LEGENDARY_ITEM_QUALITY = 80;
|
||||||
|
public static final String LEGENDARY = "Sulfuras, Hand of Ragnaros";
|
||||||
|
|
||||||
private final ItemHandler item;
|
private final ItemHandler item;
|
||||||
|
|
||||||
public LegendaryItem(Item item) {
|
public LegendaryItem(Item item) {
|
||||||
this.item = new ItemHandler(item);
|
this.item = new ItemHandler(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
item.decrementSellInDate();
|
item.decrementSellInDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLegendary(Item item) {
|
@Override
|
||||||
return item.name.equals(LEGENDARY.toString());
|
public String getName() {
|
||||||
}
|
return LEGENDARY;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean isNotLegendary(Item item) {
|
public static boolean isLegendary(Item item) {
|
||||||
return !item.name.equals(LEGENDARY.toString());
|
return item.name.equals(LEGENDARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isNotLegendary(Item item) {
|
||||||
|
return !item.name.equals(LEGENDARY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,20 +6,26 @@ import com.gildedrose.main.Item;
|
|||||||
|
|
||||||
public class NormalItem implements ItemType {
|
public class NormalItem implements ItemType {
|
||||||
|
|
||||||
private final ItemHandler item;
|
public static final String NORMAL = "Normal";
|
||||||
|
private final ItemHandler item;
|
||||||
|
|
||||||
public NormalItem(Item item) {
|
public NormalItem(Item item) {
|
||||||
this.item = new ItemHandler(item);
|
this.item = new ItemHandler(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
item.decrementSellInDate();
|
item.decrementSellInDate();
|
||||||
if (item.beforeSellInDate()) {
|
if (item.beforeSellInDate()) {
|
||||||
item.decrementQuality();
|
item.decrementQuality();
|
||||||
} else {
|
} else {
|
||||||
item.decrementQualityBy2();
|
item.decrementQualityBy2();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return NORMAL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,30 +8,30 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
|
|
||||||
import static com.gildedrose.helper.TestHelper.testItem;
|
import static com.gildedrose.helper.TestHelper.testItem;
|
||||||
import static com.gildedrose.helper.TestHelper.testItemException;
|
import static com.gildedrose.helper.TestHelper.testItemException;
|
||||||
import static com.gildedrose.item_helpers.ItemName.AGED_BRIE;
|
import static com.gildedrose.items.AgedBrieItem.AGED_BRIE;
|
||||||
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class AgedBrieItemTest {
|
class AgedBrieItemTest {
|
||||||
|
|
||||||
private final Item item = new Item(AGED_BRIE.toString(), 5, 20);
|
private final Item item = new Item(AGED_BRIE, 5, 20);
|
||||||
private final Item itemError = new Item(AGED_BRIE.toString(), 10, -5);
|
private final Item itemError = new Item(AGED_BRIE, 10, -5);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void incrementQualityByOneSuccess() {
|
void incrementQualityByOneSuccess() {
|
||||||
testItem(item, 2, 3, 22);
|
testItem(item, 2, 3, 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void incrementQualityByTwoSuccess() {
|
void incrementQualityByTwoSuccess() {
|
||||||
testItem(item, 7, -2, 29);
|
testItem(item, 7, -2, 29);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void negativeQualityFail() {
|
void negativeQualityFail() {
|
||||||
testItemException(itemError);
|
testItemException(itemError);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,42 +8,42 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
|
|
||||||
import static com.gildedrose.helper.TestHelper.testItem;
|
import static com.gildedrose.helper.TestHelper.testItem;
|
||||||
import static com.gildedrose.helper.TestHelper.testItemException;
|
import static com.gildedrose.helper.TestHelper.testItemException;
|
||||||
import static com.gildedrose.item_helpers.ItemName.BACKSTAGE_PASS;
|
import static com.gildedrose.items.BackstagePassItem.BACKSTAGE_PASS;
|
||||||
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class BackstagePassItemTest {
|
class BackstagePassItemTest {
|
||||||
|
|
||||||
private final Item item = new Item(BACKSTAGE_PASS.toString(), 15, 20);
|
private final Item item = new Item(BACKSTAGE_PASS, 15, 20);
|
||||||
private final Item itemError = new Item(BACKSTAGE_PASS.toString(), 10, -5);
|
private final Item itemError = new Item(BACKSTAGE_PASS, 10, -5);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void testIncrementQualityByOneSuccess() {
|
void testIncrementQualityByOneSuccess() {
|
||||||
testItem(item, 5, 10, 25);
|
testItem(item, 5, 10, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void testIncrementQualityByTwoSuccess() {
|
void testIncrementQualityByTwoSuccess() {
|
||||||
testItem(item, 10, 5, 35);
|
testItem(item, 10, 5, 35);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void testIncrementQualityByThreeSuccess() {
|
void testIncrementQualityByThreeSuccess() {
|
||||||
testItem(item, 15, 0, 50);
|
testItem(item, 15, 0, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
void testQualityZeroSuccess() {
|
void testQualityZeroSuccess() {
|
||||||
testItem(item, 16, -1, 0);
|
testItem(item, 16, -1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void negativeQualityFail() {
|
void negativeQualityFail() {
|
||||||
testItemException(itemError);
|
testItemException(itemError);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,29 +8,29 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
|
|
||||||
import static com.gildedrose.helper.TestHelper.testItem;
|
import static com.gildedrose.helper.TestHelper.testItem;
|
||||||
import static com.gildedrose.helper.TestHelper.testItemException;
|
import static com.gildedrose.helper.TestHelper.testItemException;
|
||||||
import static com.gildedrose.item_helpers.ItemName.CONJURED;
|
import static com.gildedrose.items.ConjuredItem.CONJURED;
|
||||||
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class ConjuredItemTest {
|
class ConjuredItemTest {
|
||||||
|
|
||||||
private final Item item = new Item(CONJURED.toString(), 5, 20);
|
private final Item item = new Item(CONJURED, 5, 20);
|
||||||
private final Item itemError = new Item(CONJURED.toString(), 10, -5);
|
private final Item itemError = new Item(CONJURED, 10, -5);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void decrementQualityByTwoSuccess() {
|
void decrementQualityByTwoSuccess() {
|
||||||
testItem(item, 2, 3, 16);
|
testItem(item, 2, 3, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void decrementQualityByFourSuccess() {
|
void decrementQualityByFourSuccess() {
|
||||||
testItem(item, 10, -5, 0);
|
testItem(item, 10, -5, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void negativeQualityFail() {
|
void negativeQualityFail() {
|
||||||
testItemException(itemError);
|
testItemException(itemError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import org.junit.jupiter.api.TestMethodOrder;
|
|||||||
|
|
||||||
import static com.gildedrose.helper.TestHelper.testItem;
|
import static com.gildedrose.helper.TestHelper.testItem;
|
||||||
import static com.gildedrose.item_helpers.QualityValidator.NOT_LEGENDARY_ITEM_ERROR_MESSAGE;
|
import static com.gildedrose.item_helpers.QualityValidator.NOT_LEGENDARY_ITEM_ERROR_MESSAGE;
|
||||||
import static com.gildedrose.item_helpers.ItemName.LEGENDARY;
|
import static com.gildedrose.items.LegendaryItem.LEGENDARY;
|
||||||
import static com.gildedrose.items.LegendaryItem.LEGENDARY_ITEM_QUALITY;
|
import static com.gildedrose.items.LegendaryItem.LEGENDARY_ITEM_QUALITY;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
@ -17,29 +17,28 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class LegendaryItemTest {
|
class LegendaryItemTest {
|
||||||
|
|
||||||
private final Item item = new Item(LEGENDARY.toString(), 5, 80);
|
private final Item item = new Item(LEGENDARY, 5, 80);
|
||||||
private final Item fakeLegendaryItem = new Item(LEGENDARY.toString(), 5, 75);
|
private final Item fakeLegendaryItem = new Item(LEGENDARY, 5, 75);
|
||||||
private final Item itemError = new Item(LEGENDARY.toString(), 10, -5);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void getLegendaryQualityBeforeSellInDateSuccess() {
|
void getLegendaryQualityBeforeSellInDateSuccess() {
|
||||||
testItem(item, 2, 3, LEGENDARY_ITEM_QUALITY);
|
testItem(item, 2, 3, LEGENDARY_ITEM_QUALITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void getLegendaryQualityPassSellInDateSuccess() {
|
void getLegendaryQualityPassSellInDateSuccess() {
|
||||||
testItem(item, 10, -5, LEGENDARY_ITEM_QUALITY);
|
testItem(item, 10, -5, LEGENDARY_ITEM_QUALITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void testFakeLegendaryItemExceptionFail() {
|
void testFakeLegendaryItemExceptionFail() {
|
||||||
GildedRose gildedRose = new GildedRose(fakeLegendaryItem);
|
GildedRose gildedRose = new GildedRose(fakeLegendaryItem);
|
||||||
Exception exception = assertThrows(IllegalArgumentException.class, gildedRose::updateQuality);
|
Exception exception = assertThrows(IllegalArgumentException.class, gildedRose::updateQuality);
|
||||||
String actualMessage = exception.getMessage();
|
String actualMessage = exception.getMessage();
|
||||||
assertTrue(actualMessage.contains(NOT_LEGENDARY_ITEM_ERROR_MESSAGE));
|
assertTrue(actualMessage.contains(NOT_LEGENDARY_ITEM_ERROR_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,36 +7,36 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
|
||||||
import static com.gildedrose.helper.TestHelper.*;
|
import static com.gildedrose.helper.TestHelper.*;
|
||||||
import static com.gildedrose.item_helpers.ItemName.NORMAL;
|
import static com.gildedrose.items.NormalItem.NORMAL;
|
||||||
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class NormalItemTest {
|
class NormalItemTest {
|
||||||
|
|
||||||
private final Item item = new Item(NORMAL.toString(), 5, 20);
|
private final Item item = new Item(NORMAL, 5, 20);
|
||||||
private final Item itemNegativeQuality = new Item(NORMAL.toString(), 10, -5);
|
private final Item itemNegativeQuality = new Item(NORMAL, 10, -5);
|
||||||
private final Item itemAboveLimitQuality = new Item(NORMAL.toString(), 10, 60);
|
private final Item itemAboveLimitQuality = new Item(NORMAL, 10, 60);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void decrementQualityByOneSuccess() {
|
void decrementQualityByOneSuccess() {
|
||||||
testItem(item, 2, 3, 18);
|
testItem(item, 2, 3, 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(2)
|
@Order(2)
|
||||||
void decrementQualityByTwoSuccess() {
|
void decrementQualityByTwoSuccess() {
|
||||||
testItem(item, 10, -5, 5);
|
testItem(item, 10, -5, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(3)
|
@Order(3)
|
||||||
void negativeQualityFail() {
|
void negativeQualityFail() {
|
||||||
testItemException(itemNegativeQuality);
|
testItemException(itemNegativeQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(4)
|
@Order(4)
|
||||||
void QualityAboveLimitFail() {
|
void QualityAboveLimitFail() {
|
||||||
testItemQualityAboveLimitException(itemAboveLimitQuality);
|
testItemQualityAboveLimitException(itemAboveLimitQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,21 +5,21 @@ import org.junit.jupiter.api.Order;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestMethodOrder;
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
|
||||||
import static com.gildedrose.item_helpers.ItemName.AGED_BRIE;
|
import static com.gildedrose.items.AgedBrieItem.AGED_BRIE;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
@TestMethodOrder(OrderAnnotation.class)
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
class ItemClassTest {
|
class ItemClassTest {
|
||||||
|
|
||||||
private final Item item = new Item(AGED_BRIE.toString(), 5, 20);
|
private final Item item = new Item(AGED_BRIE, 5, 20);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Order(1)
|
@Order(1)
|
||||||
void testItemSuccess() {
|
void testItemSuccess() {
|
||||||
assertEquals(AGED_BRIE.toString(), item.name);
|
assertEquals(AGED_BRIE, item.name);
|
||||||
assertEquals(5, item.sellIn);
|
assertEquals(5, item.sellIn);
|
||||||
assertEquals(20, item.quality);
|
assertEquals(20, item.quality);
|
||||||
assertEquals("Aged Brie, 5, 20", item.toString());
|
assertEquals("Aged Brie, 5, 20", item.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user