mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Add test for all items
This commit is contained in:
parent
32b45befe9
commit
cc53ad07e0
@ -7,7 +7,6 @@ import com.sun.xml.internal.rngom.parse.host.Base;
|
||||
*/
|
||||
class GildedRoseItem {
|
||||
Item[] items;
|
||||
public static final String SULFURA = "Sulfuras, Hand of Ragnaros";
|
||||
private ItemFactory itemFactory;
|
||||
|
||||
public GildedRoseItem(Item[] items) {
|
||||
@ -15,18 +14,10 @@ class GildedRoseItem {
|
||||
itemFactory = new ItemFactory();
|
||||
}
|
||||
|
||||
private void updateNumberOfdayToSellRemaining(Item item) {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
|
||||
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
if (item.name.equals(SULFURA)) {
|
||||
continue;
|
||||
}
|
||||
ItemInterface typeItem = itemFactory.createItemType(item);
|
||||
updateNumberOfdayToSellRemaining(item);
|
||||
typeItem.updateNumberOfdayToSellRemaining();
|
||||
typeItem.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.items.*;
|
||||
|
||||
public class ItemFactory {
|
||||
|
||||
|
||||
public static final String SULFURA = "Sulfuras, Hand of Ragnaros";
|
||||
public static final String AGED_BRIE = "Aged Brie";
|
||||
public static final String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
||||
public static final String CONJURED = "Conjured Mana Cake";
|
||||
@ -15,6 +16,8 @@ public class ItemFactory {
|
||||
return new BackStageItem(item);
|
||||
} else if (item.name.equals(CONJURED)) {
|
||||
return new ConjuredItem(item);
|
||||
} else if (item.name.equals(SULFURA)) {
|
||||
return new SulfuraItem(item);
|
||||
} else {
|
||||
return new NormalItem(item);
|
||||
}
|
||||
|
||||
@ -2,4 +2,6 @@ package com.gildedrose;
|
||||
|
||||
public interface ItemInterface {
|
||||
void updateQuality();
|
||||
|
||||
void updateNumberOfdayToSellRemaining();
|
||||
}
|
||||
|
||||
@ -1,4 +1,8 @@
|
||||
package com.gildedrose;
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.BaseItem;
|
||||
import com.gildedrose.Item;
|
||||
import com.gildedrose.ItemInterface;
|
||||
|
||||
/**
|
||||
* Class for Aged Brie item inherited from NormalItem
|
||||
@ -16,4 +20,8 @@ public class AgedBrie extends BaseItem implements ItemInterface {
|
||||
increaseQualityBy(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNumberOfdayToSellRemaining() {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
package com.gildedrose;
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.BaseItem;
|
||||
import com.gildedrose.Item;
|
||||
import com.gildedrose.ItemInterface;
|
||||
|
||||
/**
|
||||
* Class Back Stage item inherited form NormalItem
|
||||
@ -23,4 +27,8 @@ public class BackStageItem extends BaseItem implements ItemInterface {
|
||||
item.quality -= item.quality;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNumberOfdayToSellRemaining() {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,8 @@
|
||||
package com.gildedrose;
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.BaseItem;
|
||||
import com.gildedrose.Item;
|
||||
import com.gildedrose.ItemInterface;
|
||||
import com.sun.xml.internal.rngom.parse.host.Base;
|
||||
|
||||
/**
|
||||
@ -16,4 +19,8 @@ public class ConjuredItem extends BaseItem implements ItemInterface {
|
||||
decreaseQualityBy(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNumberOfdayToSellRemaining() {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,8 @@
|
||||
package com.gildedrose;
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.BaseItem;
|
||||
import com.gildedrose.Item;
|
||||
import com.gildedrose.ItemInterface;
|
||||
|
||||
/**
|
||||
* Class for a regular item with business rule for normal item:
|
||||
@ -18,4 +22,8 @@ public class NormalItem extends BaseItem implements ItemInterface {
|
||||
decreaseQualityBy(1);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateNumberOfdayToSellRemaining() {
|
||||
item.sellIn -= 1;
|
||||
}
|
||||
}
|
||||
15
Java/src/main/java/com/gildedrose/items/SulfuraItem.java
Normal file
15
Java/src/main/java/com/gildedrose/items/SulfuraItem.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.gildedrose.items;
|
||||
|
||||
import com.gildedrose.Item;
|
||||
import com.gildedrose.BaseItem;
|
||||
import com.gildedrose.ItemInterface;
|
||||
|
||||
public class SulfuraItem extends BaseItem implements ItemInterface {
|
||||
public SulfuraItem(Item item) {
|
||||
this.item=item;
|
||||
}
|
||||
|
||||
public void updateQuality() { }
|
||||
|
||||
public void updateNumberOfdayToSellRemaining() { }
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseAgedBrieItemTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("Aged Brie", 2, 0)};
|
||||
|
||||
private GildedRoseItem app = new GildedRoseItem(itemsSample);
|
||||
|
||||
/**
|
||||
* Test if item.sellIn and item.quality is the same that expected after a number of day.
|
||||
*
|
||||
* @param items, contains values calculated by executeUpdateQuality function
|
||||
* @param map, contains values that we expect
|
||||
* @param message, to make difference between tests
|
||||
*/
|
||||
public void assertItems(Item[] items, HashMap<String, int[]> map, String message) {
|
||||
for (Item item : items) {
|
||||
switch (item.name) {
|
||||
case "Aged Brie":
|
||||
assertArrayEquals(message, map.get("Aged Brie"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
default:
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute n times the function update quality
|
||||
*
|
||||
* @param numberOfTimes, number of times that you want to execute that function
|
||||
*/
|
||||
private void executeUpdateQuality(int numberOfTimes) {
|
||||
for(int i=0;i<numberOfTimes;i++){
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_1_day() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{1, 1});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(1);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_2_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{0, 2});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(2);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_3_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-1, 4});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(3);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_4_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-2, 6});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(4);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_9_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-7, 16});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(9);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_10_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-8, 18});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(10);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_11_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-9, 20});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(11);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_aged_brie_after_25_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Aged Brie", new int[]{-23, 48});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(25);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,7 @@ import org.junit.Test;
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseItemTest {
|
||||
public class GildedRoseAllItemsTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
@ -0,0 +1,134 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseBackStageItemTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)};
|
||||
|
||||
private GildedRoseItem app = new GildedRoseItem(itemsSample);
|
||||
|
||||
/**
|
||||
* Test if item.sellIn and item.quality is the same that expected after a number of day.
|
||||
*
|
||||
* @param items, contains values calculated by executeUpdateQuality function
|
||||
* @param map, contains values that we expect
|
||||
* @param message, to make difference between tests
|
||||
*/
|
||||
public void assertItems(Item[] items, HashMap<String, int[]> map, String message) {
|
||||
for (Item item : items) {
|
||||
switch (item.name) {
|
||||
case "Backstage passes to a TAFKAL80ETC concert":
|
||||
assertArrayEquals(message, map.get("Backstage passes to a TAFKAL80ETC concert"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
default:
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute n times the function update quality
|
||||
*
|
||||
* @param numberOfTimes, number of times that you want to execute that function
|
||||
*/
|
||||
private void executeUpdateQuality(int numberOfTimes) {
|
||||
for(int i=0;i<numberOfTimes;i++){
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_1_day() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{14, 21});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(1);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_2_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{13, 22});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(2);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_3_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{12, 23});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(3);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_4_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{11, 24});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(4);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_9_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{6, 33});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(9);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_10_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{5, 35});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(10);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_11_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{4, 38});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(11);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_back_stage_after_25_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Backstage passes to a TAFKAL80ETC concert", new int[]{-10, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(25);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,134 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseConjuredItemTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("Conjured Mana Cake", 3, 6) };
|
||||
|
||||
private GildedRoseItem app = new GildedRoseItem(itemsSample);
|
||||
|
||||
/**
|
||||
* Test if item.sellIn and item.quality is the same that expected after a number of day.
|
||||
*
|
||||
* @param items, contains values calculated by executeUpdateQuality function
|
||||
* @param map, contains values that we expect
|
||||
* @param message, to make difference between tests
|
||||
*/
|
||||
public void assertItems(Item[] items, HashMap<String, int[]> map, String message) {
|
||||
for (Item item : items) {
|
||||
switch (item.name) {
|
||||
case "Conjured Mana Cake":
|
||||
assertArrayEquals(message, map.get("Conjured Mana Cake"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
default:
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute n times the function update quality
|
||||
*
|
||||
* @param numberOfTimes, number of times that you want to execute that function
|
||||
*/
|
||||
private void executeUpdateQuality(int numberOfTimes) {
|
||||
for(int i=0;i<numberOfTimes;i++){
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_1_day() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{2, 5});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(1);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_2_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{1, 4});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(2);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_3_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{0, 3});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(3);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_4_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{-1, 1});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(4);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_9_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{-6, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(9);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_10_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{-7, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(10);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_11_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{-8, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(11);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_conjured_after_25_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Conjured Mana Cake", new int[]{-22, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(25);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
}
|
||||
146
Java/src/test/java/com/gildedrose/GildedRoseNormalItemTest.java
Normal file
146
Java/src/test/java/com/gildedrose/GildedRoseNormalItemTest.java
Normal file
@ -0,0 +1,146 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseNormalItemTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Elixir of the Mongoose", 5, 7)};
|
||||
|
||||
private GildedRoseItem app = new GildedRoseItem(itemsSample);
|
||||
|
||||
/**
|
||||
* Test if item.sellIn and item.quality is the same that expected after a number of day.
|
||||
*
|
||||
* @param items, contains values calculated by executeUpdateQuality function
|
||||
* @param map, contains values that we expect
|
||||
* @param message, to make difference between tests
|
||||
*/
|
||||
public void assertItems(Item[] items, HashMap<String, int[]> map, String message) {
|
||||
for (Item item : items) {
|
||||
switch (item.name) {
|
||||
case "+5 Dexterity Vest":
|
||||
assertArrayEquals(message, map.get("+5 Dexterity Vest"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
case "Elixir of the Mongoose":
|
||||
assertArrayEquals(message, map.get("Elixir of the Mongoose"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
default:
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute n times the function update quality
|
||||
*
|
||||
* @param numberOfTimes, number of times that you want to execute that function
|
||||
*/
|
||||
private void executeUpdateQuality(int numberOfTimes) {
|
||||
for(int i=0;i<numberOfTimes;i++){
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_1_day() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{9, 19});
|
||||
put("Elixir of the Mongoose", new int[]{4, 6});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(1);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_2_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{8, 18});
|
||||
put("Elixir of the Mongoose", new int[]{3, 5});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(2);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_3_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{7, 17});
|
||||
put("Elixir of the Mongoose", new int[]{2, 4});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(3);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_4_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{6, 16});
|
||||
put("Elixir of the Mongoose", new int[]{1, 3});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(4);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_9_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{1, 11});
|
||||
put("Elixir of the Mongoose", new int[]{-4, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(9);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_10_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{0, 10});
|
||||
put("Elixir of the Mongoose", new int[]{-5, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(10);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_11_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{-1, 8});
|
||||
put("Elixir of the Mongoose", new int[]{-6, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(11);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_normal_after_25_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("+5 Dexterity Vest", new int[]{-15, 0});
|
||||
put("Elixir of the Mongoose", new int[]{-20, 0});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(25);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
}
|
||||
133
Java/src/test/java/com/gildedrose/GildedRoseSulfuraItemTest.java
Normal file
133
Java/src/test/java/com/gildedrose/GildedRoseSulfuraItemTest.java
Normal file
@ -0,0 +1,133 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Test the result of item.sellIn and item.quality after n days
|
||||
*/
|
||||
public class GildedRoseSulfuraItemTest {
|
||||
private Item[] itemsSample = new Item[]{new Item("Sulfuras, Hand of Ragnaros", 0, 80)};
|
||||
|
||||
private GildedRoseItem app = new GildedRoseItem(itemsSample);
|
||||
|
||||
/**
|
||||
* Test if item.sellIn and item.quality is the same that expected after a number of day.
|
||||
*
|
||||
* @param items, contains values calculated by executeUpdateQuality function
|
||||
* @param map, contains values that we expect
|
||||
* @param message, to make difference between tests
|
||||
*/
|
||||
public void assertItems(Item[] items, HashMap<String, int[]> map, String message) {
|
||||
for (Item item : items) {
|
||||
switch (item.name) {
|
||||
case "Sulfuras, Hand of Ragnaros":
|
||||
assertArrayEquals(message, map.get("Sulfuras, Hand of Ragnaros"), new int[]{item.sellIn, item.quality});
|
||||
break;
|
||||
default:
|
||||
System.out.println("oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute n times the function update quality
|
||||
*
|
||||
* @param numberOfTimes, number of times that you want to execute that function
|
||||
*/
|
||||
private void executeUpdateQuality(int numberOfTimes) {
|
||||
for(int i=0;i<numberOfTimes;i++){
|
||||
app.updateQuality();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_1_day() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});}
|
||||
};
|
||||
executeUpdateQuality(1);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_2_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(2);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_3_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(3);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_4_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(4);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_9_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(9);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_10_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(10);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_11_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(11);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sulfura_test_after_25_days() {
|
||||
HashMap<String,int[]> mapExpectedValued = new HashMap<String,int[]>(){
|
||||
{
|
||||
put("Sulfuras, Hand of Ragnaros", new int[]{0, 80});
|
||||
}
|
||||
};
|
||||
executeUpdateQuality(25);
|
||||
assertItems(itemsSample, mapExpectedValued, new Throwable().getStackTrace()[0].getMethodName());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user