From 2a60407d6b375091931eb6494065c3226ddebb49 Mon Sep 17 00:00:00 2001 From: Xavier Levaux Date: Thu, 24 Sep 2020 17:02:46 +0200 Subject: [PATCH] Added tests to ensure no regression is introduced during refactoring --- Java/build.gradle | 8 +- .../java/com/gildedrose/GildedRoseTest.java | 27 ++++--- .../GildedRoseTest.updateQuality.approved.txt | 80 +++++++++++++++++++ 3 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 Java/src/test/java/com/gildedrose/GildedRoseTest.updateQuality.approved.txt diff --git a/Java/build.gradle b/Java/build.gradle index f3773536..24fb40d5 100644 --- a/Java/build.gradle +++ b/Java/build.gradle @@ -7,10 +7,10 @@ repositories { } dependencies { - testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' - testImplementation 'org.junit.jupiter:junit-jupiter-params:5.6.2' - testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2' - testImplementation 'com.approvaltests:approvaltests:5.0.0' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.0' + testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0' + testImplementation 'com.approvaltests:approvaltests:9.3.0' } group = 'com.gildedrose' diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.java b/Java/src/test/java/com/gildedrose/GildedRoseTest.java index 8ae29eec..efa8488c 100644 --- a/Java/src/test/java/com/gildedrose/GildedRoseTest.java +++ b/Java/src/test/java/com/gildedrose/GildedRoseTest.java @@ -1,17 +1,26 @@ package com.gildedrose; +import org.approvaltests.combinations.CombinationApprovals; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - class GildedRoseTest { - @Test - void foo() { - Item[] items = new Item[] { new Item("foo", 0, 0) }; - GildedRose app = new GildedRose(items); - app.updateQuality(); - assertEquals("fixme", app.items[0].name); - } + @Test + void updateQuality() { + CombinationApprovals + .verifyAllCombinations(this::doUpdateQuality, + new String[]{"foo", "Aged Brie", "Backstage passes to a TAFKAL80ETC concert", + "Sulfuras, Hand of Ragnaros"}, //name + new Integer[]{-1, 0, 5, 6, 11}, //sellIn + new Integer[]{0, 1, 49, 50} //quantity + ); + } + + private String doUpdateQuality(String name, int sellIn, int quality) { + Item[] items = new Item[]{new Item(name, sellIn, quality)}; + GildedRose app = new GildedRose(items); + app.updateQuality(); + return app.items[0].toString(); + } } diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.updateQuality.approved.txt b/Java/src/test/java/com/gildedrose/GildedRoseTest.updateQuality.approved.txt new file mode 100644 index 00000000..7627fe69 --- /dev/null +++ b/Java/src/test/java/com/gildedrose/GildedRoseTest.updateQuality.approved.txt @@ -0,0 +1,80 @@ +[foo, -1, 0] => foo, -2, 0 +[foo, -1, 1] => foo, -2, 0 +[foo, -1, 49] => foo, -2, 47 +[foo, -1, 50] => foo, -2, 48 +[foo, 0, 0] => foo, -1, 0 +[foo, 0, 1] => foo, -1, 0 +[foo, 0, 49] => foo, -1, 47 +[foo, 0, 50] => foo, -1, 48 +[foo, 5, 0] => foo, 4, 0 +[foo, 5, 1] => foo, 4, 0 +[foo, 5, 49] => foo, 4, 48 +[foo, 5, 50] => foo, 4, 49 +[foo, 6, 0] => foo, 5, 0 +[foo, 6, 1] => foo, 5, 0 +[foo, 6, 49] => foo, 5, 48 +[foo, 6, 50] => foo, 5, 49 +[foo, 11, 0] => foo, 10, 0 +[foo, 11, 1] => foo, 10, 0 +[foo, 11, 49] => foo, 10, 48 +[foo, 11, 50] => foo, 10, 49 +[Aged Brie, -1, 0] => Aged Brie, -2, 2 +[Aged Brie, -1, 1] => Aged Brie, -2, 3 +[Aged Brie, -1, 49] => Aged Brie, -2, 50 +[Aged Brie, -1, 50] => Aged Brie, -2, 50 +[Aged Brie, 0, 0] => Aged Brie, -1, 2 +[Aged Brie, 0, 1] => Aged Brie, -1, 3 +[Aged Brie, 0, 49] => Aged Brie, -1, 50 +[Aged Brie, 0, 50] => Aged Brie, -1, 50 +[Aged Brie, 5, 0] => Aged Brie, 4, 1 +[Aged Brie, 5, 1] => Aged Brie, 4, 2 +[Aged Brie, 5, 49] => Aged Brie, 4, 50 +[Aged Brie, 5, 50] => Aged Brie, 4, 50 +[Aged Brie, 6, 0] => Aged Brie, 5, 1 +[Aged Brie, 6, 1] => Aged Brie, 5, 2 +[Aged Brie, 6, 49] => Aged Brie, 5, 50 +[Aged Brie, 6, 50] => Aged Brie, 5, 50 +[Aged Brie, 11, 0] => Aged Brie, 10, 1 +[Aged Brie, 11, 1] => Aged Brie, 10, 2 +[Aged Brie, 11, 49] => Aged Brie, 10, 50 +[Aged Brie, 11, 50] => Aged Brie, 10, 50 +[Backstage passes to a TAFKAL80ETC concert, -1, 0] => Backstage passes to a TAFKAL80ETC concert, -2, 0 +[Backstage passes to a TAFKAL80ETC concert, -1, 1] => Backstage passes to a TAFKAL80ETC concert, -2, 0 +[Backstage passes to a TAFKAL80ETC concert, -1, 49] => Backstage passes to a TAFKAL80ETC concert, -2, 0 +[Backstage passes to a TAFKAL80ETC concert, -1, 50] => Backstage passes to a TAFKAL80ETC concert, -2, 0 +[Backstage passes to a TAFKAL80ETC concert, 0, 0] => Backstage passes to a TAFKAL80ETC concert, -1, 0 +[Backstage passes to a TAFKAL80ETC concert, 0, 1] => Backstage passes to a TAFKAL80ETC concert, -1, 0 +[Backstage passes to a TAFKAL80ETC concert, 0, 49] => Backstage passes to a TAFKAL80ETC concert, -1, 0 +[Backstage passes to a TAFKAL80ETC concert, 0, 50] => Backstage passes to a TAFKAL80ETC concert, -1, 0 +[Backstage passes to a TAFKAL80ETC concert, 5, 0] => Backstage passes to a TAFKAL80ETC concert, 4, 3 +[Backstage passes to a TAFKAL80ETC concert, 5, 1] => Backstage passes to a TAFKAL80ETC concert, 4, 4 +[Backstage passes to a TAFKAL80ETC concert, 5, 49] => Backstage passes to a TAFKAL80ETC concert, 4, 50 +[Backstage passes to a TAFKAL80ETC concert, 5, 50] => Backstage passes to a TAFKAL80ETC concert, 4, 50 +[Backstage passes to a TAFKAL80ETC concert, 6, 0] => Backstage passes to a TAFKAL80ETC concert, 5, 2 +[Backstage passes to a TAFKAL80ETC concert, 6, 1] => Backstage passes to a TAFKAL80ETC concert, 5, 3 +[Backstage passes to a TAFKAL80ETC concert, 6, 49] => Backstage passes to a TAFKAL80ETC concert, 5, 50 +[Backstage passes to a TAFKAL80ETC concert, 6, 50] => Backstage passes to a TAFKAL80ETC concert, 5, 50 +[Backstage passes to a TAFKAL80ETC concert, 11, 0] => Backstage passes to a TAFKAL80ETC concert, 10, 1 +[Backstage passes to a TAFKAL80ETC concert, 11, 1] => Backstage passes to a TAFKAL80ETC concert, 10, 2 +[Backstage passes to a TAFKAL80ETC concert, 11, 49] => Backstage passes to a TAFKAL80ETC concert, 10, 50 +[Backstage passes to a TAFKAL80ETC concert, 11, 50] => Backstage passes to a TAFKAL80ETC concert, 10, 50 +[Sulfuras, Hand of Ragnaros, -1, 0] => Sulfuras, Hand of Ragnaros, -1, 0 +[Sulfuras, Hand of Ragnaros, -1, 1] => Sulfuras, Hand of Ragnaros, -1, 1 +[Sulfuras, Hand of Ragnaros, -1, 49] => Sulfuras, Hand of Ragnaros, -1, 49 +[Sulfuras, Hand of Ragnaros, -1, 50] => Sulfuras, Hand of Ragnaros, -1, 50 +[Sulfuras, Hand of Ragnaros, 0, 0] => Sulfuras, Hand of Ragnaros, 0, 0 +[Sulfuras, Hand of Ragnaros, 0, 1] => Sulfuras, Hand of Ragnaros, 0, 1 +[Sulfuras, Hand of Ragnaros, 0, 49] => Sulfuras, Hand of Ragnaros, 0, 49 +[Sulfuras, Hand of Ragnaros, 0, 50] => Sulfuras, Hand of Ragnaros, 0, 50 +[Sulfuras, Hand of Ragnaros, 5, 0] => Sulfuras, Hand of Ragnaros, 5, 0 +[Sulfuras, Hand of Ragnaros, 5, 1] => Sulfuras, Hand of Ragnaros, 5, 1 +[Sulfuras, Hand of Ragnaros, 5, 49] => Sulfuras, Hand of Ragnaros, 5, 49 +[Sulfuras, Hand of Ragnaros, 5, 50] => Sulfuras, Hand of Ragnaros, 5, 50 +[Sulfuras, Hand of Ragnaros, 6, 0] => Sulfuras, Hand of Ragnaros, 6, 0 +[Sulfuras, Hand of Ragnaros, 6, 1] => Sulfuras, Hand of Ragnaros, 6, 1 +[Sulfuras, Hand of Ragnaros, 6, 49] => Sulfuras, Hand of Ragnaros, 6, 49 +[Sulfuras, Hand of Ragnaros, 6, 50] => Sulfuras, Hand of Ragnaros, 6, 50 +[Sulfuras, Hand of Ragnaros, 11, 0] => Sulfuras, Hand of Ragnaros, 11, 0 +[Sulfuras, Hand of Ragnaros, 11, 1] => Sulfuras, Hand of Ragnaros, 11, 1 +[Sulfuras, Hand of Ragnaros, 11, 49] => Sulfuras, Hand of Ragnaros, 11, 49 +[Sulfuras, Hand of Ragnaros, 11, 50] => Sulfuras, Hand of Ragnaros, 11, 50