Create Golden Master Approval Test

This commit is contained in:
Roberto de la Banda 2021-09-11 11:28:28 +02:00
parent 69618dd6bd
commit e9864f986a
4 changed files with 2721 additions and 1 deletions

View File

@ -11,7 +11,7 @@ class GildedRoseTest {
Item[] items = new Item[] { new Item("foo", 0, 0) };
GildedRose app = new GildedRose(items);
app.updateQuality();
assertEquals("fixme", app.items[0].name);
assertEquals("foo", app.items[0].name);
}
}

View File

@ -0,0 +1,42 @@
package com.gildedrose;
import org.approvaltests.combinations.CombinationApprovals;
import org.junit.jupiter.api.Test;
import java.util.stream.IntStream;
class GoldenMasterApprovalTest {
@Test
void
gildedRoseApprovalTest() {
CombinationApprovals.verifyAllCombinations(
this::updateItem,
itemTypes(),
qualityRangeValues(),
sellInRangeValues()
);
}
private String[] itemTypes() {
return new String[]{"common item", "Aged Brie", "Backstage passes to a TAFKAL80ETC concert", "Sulfuras, Hand of Ragnaros"};
}
private Integer[] sellInRangeValues() {
return IntStream.range(-1, 12).boxed().toArray(Integer[]::new);
}
private Integer[] qualityRangeValues() {
return IntStream.range(0, 51).boxed().toArray(Integer[]::new);
}
private Item updateItem(String name, int quality, int sellIn) {
final Item item = new ItemBuilder()
.setName(name)
.setSellIn(sellIn)
.setQuality(quality)
.createItem();
new GildedRose(new Item[]{item}).updateQuality();
return item;
}
}

View File

@ -0,0 +1,26 @@
package com.gildedrose;
public class ItemBuilder {
private String name;
private int sellIn;
private int quality;
public ItemBuilder setName(String name) {
this.name = name;
return this;
}
public ItemBuilder setSellIn(int sellIn) {
this.sellIn = sellIn;
return this;
}
public ItemBuilder setQuality(int quality) {
this.quality = quality;
return this;
}
public Item createItem() {
return new Item(name, sellIn, quality);
}
}