mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
🔨 refactoring
This commit is contained in:
parent
9cf04ec63a
commit
ab3f5032dd
@ -14,7 +14,7 @@ public class ItemFactory {
|
||||
private ItemFactory() {
|
||||
}
|
||||
|
||||
public static ItemType getItem(Item item) {
|
||||
public static ItemType getItemType(Item item) {
|
||||
validateQuality(item);
|
||||
ItemName itemName = getItemName(item.name);
|
||||
switch (itemName) {
|
||||
|
||||
@ -2,7 +2,7 @@ package com.gildedrose.main;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemFactory.getItem;
|
||||
import static com.gildedrose.item_helpers.ItemFactory.getItemType;
|
||||
import static java.util.Collections.singletonList;
|
||||
|
||||
public class GildedRose {
|
||||
@ -17,6 +17,6 @@ public class GildedRose {
|
||||
}
|
||||
|
||||
public void updateQuality() {
|
||||
items.forEach(item -> getItem(item).updateQuality());
|
||||
items.forEach(item -> getItemType(item).updateQuality());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,77 +0,0 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.*;
|
||||
|
||||
class GildedRoseTest {
|
||||
|
||||
@Test
|
||||
void testNormalItem() {
|
||||
int days = 20;
|
||||
Item normalItem = new Item(NORMAL.toString(), 10, 20);
|
||||
GildedRose app = new GildedRose(normalItem);
|
||||
app.updateQuality();
|
||||
for (int i = 0; i < days; i++) {
|
||||
app.updateQuality();
|
||||
System.out.println("name, sell-in, quality");
|
||||
System.out.println(normalItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConjuredItem() {
|
||||
int days = 20;
|
||||
Item normalItem = new Item(CONJURED.toString(), 10, 40);
|
||||
GildedRose app = new GildedRose(normalItem);
|
||||
for (int i = 0; i < days; i++) {
|
||||
app.updateQuality();
|
||||
System.out.println("name, sell-in, quality");
|
||||
System.out.println(normalItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLegendaryItem() {
|
||||
int days = 20;
|
||||
Item legendaryItem = new Item(LEGENDARY.toString(), 10, 80);
|
||||
GildedRose app = new GildedRose(legendaryItem);
|
||||
for (int i = 0; i < days; i++) {
|
||||
app.updateQuality();
|
||||
System.out.println("name, sell-in, quality");
|
||||
System.out.println(legendaryItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAgedBrieItem() {
|
||||
int days = 20;
|
||||
Item agedBrie = new Item(AGED_BRIE.toString(), 10, 40);
|
||||
GildedRose app = new GildedRose(agedBrie);
|
||||
for (int i = 0; i < days; i++) {
|
||||
app.updateQuality();
|
||||
System.out.println("name, sell-in, quality");
|
||||
System.out.println(agedBrie);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBackstagePassItem() {
|
||||
int days = 20;
|
||||
List<Item> backStagePass = Arrays.asList(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49));
|
||||
GildedRose app = new GildedRose(backStagePass);
|
||||
for (int i = 0; i < days; i++) {
|
||||
app.updateQuality();
|
||||
System.out.println("name, sell-in, quality");
|
||||
System.out.println(backStagePass);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class TexttestFixture {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("OMGHAI!");
|
||||
|
||||
Item[] items = new Item[]{
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)};
|
||||
|
||||
GildedRose app = new GildedRose(asList(items));
|
||||
|
||||
int days = 2;
|
||||
if (args.length > 0) {
|
||||
days = Integer.parseInt(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < days; i++) {
|
||||
System.out.println("-------- day " + i + " --------");
|
||||
System.out.println("name, sellIn, quality");
|
||||
for (Item item : items) {
|
||||
System.out.println(item);
|
||||
}
|
||||
System.out.println();
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class TexttestFixtureTemp {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("OMGHAI!");
|
||||
|
||||
Item[] items = new Item[]{
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||
// this conjured item does not work properly yet
|
||||
new Item("Conjured Mana Cake", 3, 6)};
|
||||
|
||||
GildedRose app = new GildedRose(asList(items));
|
||||
|
||||
int days = 20;
|
||||
if (args.length > 0) {
|
||||
days = Integer.parseInt(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < days; i++) {
|
||||
System.out.println("-------- day " + i + " --------");
|
||||
System.out.println("name, sellIn, quality");
|
||||
for (Item item : items) {
|
||||
System.out.println(item);
|
||||
}
|
||||
System.out.println();
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.helper;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.items;
|
||||
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.AGED_BRIE;
|
||||
import static com.gildedrose.items.TestHelper.testItem;
|
||||
import static com.gildedrose.items.TestHelper.testItemException;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItemException;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class AgedBrieItemTest {
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.items;
|
||||
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.BACKSTAGE_PASS;
|
||||
import static com.gildedrose.items.TestHelper.testItem;
|
||||
import static com.gildedrose.items.TestHelper.testItemException;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItemException;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class BackstagePassItemTest {
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.items;
|
||||
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.CONJURED;
|
||||
import static com.gildedrose.items.TestHelper.testItem;
|
||||
import static com.gildedrose.items.TestHelper.testItemException;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItemException;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class ConjuredItemTest {
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.items;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
@ -10,8 +10,8 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
import static com.gildedrose.item_helpers.ItemName.LEGENDARY;
|
||||
import static com.gildedrose.items.LegendaryItem.LEGENDARY_ITEM_QUALITY;
|
||||
import static com.gildedrose.items.LegendaryItem.NOT_LEGENDARY_ITEM_ERROR_MESSAGE;
|
||||
import static com.gildedrose.items.TestHelper.testItem;
|
||||
import static com.gildedrose.items.TestHelper.testItemException;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItemException;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.items;
|
||||
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
@ -7,8 +7,8 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.NORMAL;
|
||||
import static com.gildedrose.items.TestHelper.testItem;
|
||||
import static com.gildedrose.items.TestHelper.testItemException;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItem;
|
||||
import static com.gildedrose.items.helper.TestHelper.testItemException;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class NormalItemTest {
|
||||
@ -0,0 +1,26 @@
|
||||
package com.gildedrose.items.main;
|
||||
|
||||
import com.gildedrose.main.Item;
|
||||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static com.gildedrose.item_helpers.ItemName.AGED_BRIE;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
@TestMethodOrder(OrderAnnotation.class)
|
||||
class ItemClassTest {
|
||||
|
||||
private final Item item = new Item(AGED_BRIE.toString(), 5, 20);
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void testItemSuccess() {
|
||||
assertEquals(AGED_BRIE.toString(), item.name);
|
||||
assertEquals(5, item.sellIn);
|
||||
assertEquals(20, item.quality);
|
||||
assertEquals("Aged Brie, 5, 20", item.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose.items;
|
||||
package com.gildedrose.items.multiple_items;
|
||||
|
||||
import com.gildedrose.main.GildedRose;
|
||||
import com.gildedrose.main.Item;
|
||||
Loading…
Reference in New Issue
Block a user