From 2775271b8b6f5ed6267b36b12691bc4ca8ff3ec9 Mon Sep 17 00:00:00 2001 From: Philip Schwarz Date: Sat, 2 Jul 2016 19:22:45 +0100 Subject: [PATCH] Add regression_test that uses https://github.com/approvals/ApprovalTests.Java to verify the system's output against Golden Master. When you add JUnit to the classpath to get GildedRoseTest to run, also add ApprovalTests.jar, found in the latest zip @ https://github.com/approvals/ApprovalTests.Java/releases. --- Java/com/gildedrose/GildedRoseTest.java | 13 ++ ...ildedRoseTest.regression_test.approved.txt | 121 ++++++++++++++++++ Java/com/gildedrose/TexttestFixture.java | 38 ++++-- 3 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 Java/com/gildedrose/GildedRoseTest.regression_test.approved.txt diff --git a/Java/com/gildedrose/GildedRoseTest.java b/Java/com/gildedrose/GildedRoseTest.java index d679c458..f28dafd5 100644 --- a/Java/com/gildedrose/GildedRoseTest.java +++ b/Java/com/gildedrose/GildedRoseTest.java @@ -2,10 +2,18 @@ package com.gildedrose; import static org.junit.Assert.*; +import org.approvaltests.Approvals; +import org.approvaltests.reporters.JunitReporter; +import org.approvaltests.reporters.UseReporter; import org.junit.Test; +import java.io.File; + +@UseReporter(JunitReporter.class) public class GildedRoseTest { + public static final File OUTPUT_FILE = new File("com/gildedrose/GildedRoseTest.regression_test.received.txt"); + @Test public void foo() { Item[] items = new Item[] { new Item("foo", 0, 0) }; @@ -14,4 +22,9 @@ public class GildedRoseTest { assertEquals("fixme", app.items[0].name); } + @Test + public void regression_test() throws Exception { + TexttestFixture.updateQualityOverTenDays(OUTPUT_FILE); + Approvals.verify(OUTPUT_FILE); + } } diff --git a/Java/com/gildedrose/GildedRoseTest.regression_test.approved.txt b/Java/com/gildedrose/GildedRoseTest.regression_test.approved.txt new file mode 100644 index 00000000..19004387 --- /dev/null +++ b/Java/com/gildedrose/GildedRoseTest.regression_test.approved.txt @@ -0,0 +1,121 @@ +OMGHAI! +-------- day 0 -------- +name, sellIn, quality ++5 Dexterity Vest, 10, 20 +Aged Brie, 2, 0 +Elixir of the Mongoose, 5, 7 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 15, 200 +Backstage passes to a TAFKAL80ETC concert, 10, 49 +Backstage passes to a TAFKAL80ETC concert, 5, 49 +Conjured Mana Cake, 3, 6 + +-------- day 1 -------- +name, sellIn, quality ++5 Dexterity Vest, 9, 19 +Aged Brie, 1, 1 +Elixir of the Mongoose, 4, 6 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 14, 200 +Backstage passes to a TAFKAL80ETC concert, 9, 50 +Backstage passes to a TAFKAL80ETC concert, 4, 50 +Conjured Mana Cake, 2, 5 + +-------- day 2 -------- +name, sellIn, quality ++5 Dexterity Vest, 8, 18 +Aged Brie, 0, 2 +Elixir of the Mongoose, 3, 5 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 13, 200 +Backstage passes to a TAFKAL80ETC concert, 8, 50 +Backstage passes to a TAFKAL80ETC concert, 3, 50 +Conjured Mana Cake, 1, 4 + +-------- day 3 -------- +name, sellIn, quality ++5 Dexterity Vest, 7, 17 +Aged Brie, -1, 4 +Elixir of the Mongoose, 2, 4 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 12, 200 +Backstage passes to a TAFKAL80ETC concert, 7, 50 +Backstage passes to a TAFKAL80ETC concert, 2, 50 +Conjured Mana Cake, 0, 3 + +-------- day 4 -------- +name, sellIn, quality ++5 Dexterity Vest, 6, 16 +Aged Brie, -2, 6 +Elixir of the Mongoose, 1, 3 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 11, 200 +Backstage passes to a TAFKAL80ETC concert, 6, 50 +Backstage passes to a TAFKAL80ETC concert, 1, 50 +Conjured Mana Cake, -1, 1 + +-------- day 5 -------- +name, sellIn, quality ++5 Dexterity Vest, 5, 15 +Aged Brie, -3, 8 +Elixir of the Mongoose, 0, 2 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 10, 200 +Backstage passes to a TAFKAL80ETC concert, 5, 50 +Backstage passes to a TAFKAL80ETC concert, 0, 50 +Conjured Mana Cake, -2, 0 + +-------- day 6 -------- +name, sellIn, quality ++5 Dexterity Vest, 4, 14 +Aged Brie, -4, 10 +Elixir of the Mongoose, -1, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 9, 200 +Backstage passes to a TAFKAL80ETC concert, 4, 50 +Backstage passes to a TAFKAL80ETC concert, -1, 0 +Conjured Mana Cake, -3, 0 + +-------- day 7 -------- +name, sellIn, quality ++5 Dexterity Vest, 3, 13 +Aged Brie, -5, 12 +Elixir of the Mongoose, -2, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 8, 200 +Backstage passes to a TAFKAL80ETC concert, 3, 50 +Backstage passes to a TAFKAL80ETC concert, -2, 0 +Conjured Mana Cake, -4, 0 + +-------- day 8 -------- +name, sellIn, quality ++5 Dexterity Vest, 2, 12 +Aged Brie, -6, 14 +Elixir of the Mongoose, -3, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 7, 200 +Backstage passes to a TAFKAL80ETC concert, 2, 50 +Backstage passes to a TAFKAL80ETC concert, -3, 0 +Conjured Mana Cake, -5, 0 + +-------- day 9 -------- +name, sellIn, quality ++5 Dexterity Vest, 1, 11 +Aged Brie, -7, 16 +Elixir of the Mongoose, -4, 0 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 6, 200 +Backstage passes to a TAFKAL80ETC concert, 1, 50 +Backstage passes to a TAFKAL80ETC concert, -4, 0 +Conjured Mana Cake, -6, 0 + diff --git a/Java/com/gildedrose/TexttestFixture.java b/Java/com/gildedrose/TexttestFixture.java index 821b7f1d..43fdb1b4 100644 --- a/Java/com/gildedrose/TexttestFixture.java +++ b/Java/com/gildedrose/TexttestFixture.java @@ -1,8 +1,22 @@ package com.gildedrose; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; + public class TexttestFixture { public static void main(String[] args) { - System.out.println("OMGHAI!"); + int days = getDays(args); + updateQuality(days, System.out); + } + + public static void updateQualityOverTenDays(File outputFile) throws FileNotFoundException { + int days = 10; + updateQuality(days, new PrintStream(outputFile)); + } + + private static void updateQuality(int days, PrintStream out) { + out.println("OMGHAI!"); Item[] items = new Item[] { new Item("+5 Dexterity Vest", 10, 20), // @@ -10,7 +24,7 @@ public class TexttestFixture { 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", 15, 200), 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 @@ -18,20 +32,22 @@ public class TexttestFixture { GildedRose app = new GildedRose(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"); + out.println("-------- day " + i + " --------"); + out.println("name, sellIn, quality"); for (Item item : items) { - System.out.println(item); + out.println(item); } - System.out.println(); + out.println(); app.updateQuality(); } } + private static int getDays(String[] args) { + int days = 2; + if (args.length > 0) { + days = Integer.parseInt(args[0]) + 1; + } + return days; + } }