mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Junit test cases & loggers for each items
This commit is contained in:
parent
d1f7a4c85e
commit
45c0a3a53b
@ -0,0 +1,23 @@
|
|||||||
|
package com.gildedrose.logger;
|
||||||
|
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class GildedRoseLogger {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(GildedRoseLogger.class.getName());
|
||||||
|
|
||||||
|
private GildedRoseLogger() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
ConsoleHandler handler = new ConsoleHandler();
|
||||||
|
logger.addHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Logger getLogger() {
|
||||||
|
return logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,36 +1,39 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
|
import com.gildedrose.config.ProductFactory;
|
||||||
|
import com.gildedrose.enums.ProductType;
|
||||||
|
import com.gildedrose.generic.ItemType;
|
||||||
|
import com.gildedrose.logger.GildedRoseLogger;
|
||||||
|
|
||||||
public class TexttestFixture {
|
public class TexttestFixture {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("OMGHAI!");
|
GildedRoseLogger.getLogger().info("OMGHAI!");
|
||||||
|
|
||||||
Item[] items = new Item[] {
|
Item[] items = new Item[] {
|
||||||
new Item("+5 Dexterity Vest", 10, 20), //
|
new Item("+5 Dexterity Vest", 2, 84),
|
||||||
new Item("Aged Brie", 2, 0), //
|
new Item("Aged Brie", 5, 10),
|
||||||
new Item("Elixir of the Mongoose", 5, 7), //
|
new Item("Elixir of the Mongoose", 5, 7),
|
||||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
new Item("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||||
new Item("Sulfuras, Hand of Ragnaros", -1, 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", 15, 20),
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
// this conjured item does not work properly yet
|
new Item("Conjured Mana Cake", 10, 14)
|
||||||
new Item("Conjured Mana Cake", 3, 6) };
|
};
|
||||||
|
|
||||||
GildedRose app = new GildedRose(items);
|
int days = 20;
|
||||||
|
|
||||||
int days = 2;
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
days = Integer.parseInt(args[0]) + 1;
|
days = Integer.parseInt(args[0]) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < days; i++) {
|
for (int i = 0; i < days; i++) {
|
||||||
System.out.println("-------- day " + i + " --------");
|
GildedRoseLogger.getLogger().info("-------- day " + i + " --------");
|
||||||
System.out.println("name, sellIn, quality");
|
GildedRoseLogger.getLogger().info("name, sellIn, quality");
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
System.out.println(item);
|
ItemType itemType = ProductFactory.get(ProductType.getEnumByString(item.name));
|
||||||
|
GildedRoseLogger.getLogger().info(item.toString());
|
||||||
|
itemType.updateQuality(item);
|
||||||
}
|
}
|
||||||
System.out.println();
|
|
||||||
app.updateQuality();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.gildedrose.config;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gildedrose.enums.ProductType;
|
||||||
|
import com.gildedrose.generic.ItemType;
|
||||||
|
import com.gildedrose.types.AgedBrie;
|
||||||
|
import com.gildedrose.types.Backstage;
|
||||||
|
import com.gildedrose.types.Others;
|
||||||
|
|
||||||
|
public class ProductFactoryTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetItems() {
|
||||||
|
ItemType agedBreiItemType = ProductFactory.get(ProductType.AGED_BRIE);
|
||||||
|
assertTrue(agedBreiItemType instanceof AgedBrie);
|
||||||
|
|
||||||
|
ItemType backstageItemType = ProductFactory.get(ProductType.BACKSTAGE_PASSES);
|
||||||
|
assertTrue(backstageItemType instanceof Backstage);
|
||||||
|
|
||||||
|
ItemType otherItemType = ProductFactory.get(null);
|
||||||
|
assertTrue(otherItemType instanceof Others);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
Java/src/test/java/com/gildedrose/types/AgedBrieTest.java
Normal file
21
Java/src/test/java/com/gildedrose/types/AgedBrieTest.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.gildedrose.types;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
import com.gildedrose.enums.ProductType;
|
||||||
|
|
||||||
|
public class AgedBrieTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAgedBrieUpdateQuality() {
|
||||||
|
Item item = new Item(ProductType.AGED_BRIE.name(), 2, 3);
|
||||||
|
AgedBrie agedBrie = new AgedBrie();
|
||||||
|
agedBrie.updateQuality(item);
|
||||||
|
assertEquals(item.quality, 4);
|
||||||
|
assertEquals(item.sellIn, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
Java/src/test/java/com/gildedrose/types/BackstageTest.java
Normal file
21
Java/src/test/java/com/gildedrose/types/BackstageTest.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.gildedrose.types;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
import com.gildedrose.enums.ProductType;
|
||||||
|
|
||||||
|
public class BackstageTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBackstageUpdateQuality() {
|
||||||
|
Item item = new Item(ProductType.BACKSTAGE_PASSES.name(), 2, 3);
|
||||||
|
Backstage backstage = new Backstage();
|
||||||
|
backstage.updateQuality(item);
|
||||||
|
assertEquals(item.quality, 4);
|
||||||
|
assertEquals(item.sellIn, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
20
Java/src/test/java/com/gildedrose/types/OthersTest.java
Normal file
20
Java/src/test/java/com/gildedrose/types/OthersTest.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package com.gildedrose.types;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
|
||||||
|
public class OthersTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOthersUpdateQuality() {
|
||||||
|
Item item = new Item("Other item", 2, 3);
|
||||||
|
Others others = new Others();
|
||||||
|
others.updateQuality(item);
|
||||||
|
assertEquals(item.quality, 2);
|
||||||
|
assertEquals(item.sellIn, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
21
Java/src/test/java/com/gildedrose/types/SulfurasTest.java
Normal file
21
Java/src/test/java/com/gildedrose/types/SulfurasTest.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.gildedrose.types;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.gildedrose.Item;
|
||||||
|
import com.gildedrose.enums.ProductType;
|
||||||
|
|
||||||
|
public class SulfurasTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSulfurasUpdateQuality() {
|
||||||
|
Item item = new Item(ProductType.SULFURAS.name(), -1, 80);
|
||||||
|
Sulfuras sulfuras = new Sulfuras();
|
||||||
|
sulfuras.updateQuality(item);
|
||||||
|
assertEquals(item.quality, 80);
|
||||||
|
assertEquals(item.sellIn, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user