diff --git a/Java-Cucumber/src/main/java/com/gildedrose/TexttestFixture.java b/Java-Cucumber/src/main/java/com/gildedrose/TexttestFixture.java index d059c88f..1e1aa928 100644 --- a/Java-Cucumber/src/main/java/com/gildedrose/TexttestFixture.java +++ b/Java-Cucumber/src/main/java/com/gildedrose/TexttestFixture.java @@ -18,7 +18,7 @@ public class TexttestFixture { GildedRose app = new GildedRose(items); - int days = 2; + int days = 30; if (args.length > 0) { days = Integer.parseInt(args[0]) + 1; } diff --git a/Java-Cucumber/src/test/java/com/gildedrose/StepDefinitions.java b/Java-Cucumber/src/test/java/com/gildedrose/StepDefinitions.java index 2d79ec51..ce28ab5c 100644 --- a/Java-Cucumber/src/test/java/com/gildedrose/StepDefinitions.java +++ b/Java-Cucumber/src/test/java/com/gildedrose/StepDefinitions.java @@ -6,24 +6,44 @@ import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + public class StepDefinitions { private Item[] items = new Item[1]; private GildedRose app; + private int[] qualityValues; + private int[] sellInValues; - @Given("The item as {string}") - public void initial_sellin_is_and_quality_is(String name) { - items[0] = new Item(name, 0, 0); + @Given("For article {string} with initial quality {int} and sellIn {int}") + public void initial_sellin_is_and_quality_is(String name, int quality, int sellIn) { + items = new Item[] { new Item(name, sellIn, quality) }; app = new GildedRose(items); + } - @When("I update the quality") - public void i_update_the_quality() { - app.updateQuality(); + @When("The quality is updated the next {int} days") + public void i_update_the_quality(int days) { + qualityValues = new int[days]; + sellInValues = new int[days]; + for (int i = 0; i < days; i++) { + app.updateQuality(); + qualityValues[i] = items[0].quality; + sellInValues[i] = items[0].sellIn; + } } - @Then("I should get item as {string}") - public void i_should_get_sellin_as_and_quality_as(String expected) { - assertEquals(expected, app.items[0].name); + @Then("I should get the following quality values each day:") + public void i_should_get_sellin_as_and_quality_as(io.cucumber.datatable.DataTable dataTable) { + List> rows = dataTable.asMaps(String.class, String.class); + for (int i = 0; i < rows.size(); i++) { + Map row = rows.get(i); + int expectedQuality = Integer.parseInt(row.get("quality")); + int expectedSellIn = Integer.parseInt(row.get("sellIn")); + assertEquals(expectedQuality, qualityValues[i]); + assertEquals(expectedSellIn, sellInValues[i]); + } } } diff --git a/Java-Cucumber/src/test/resources/com/gildedrose/GildedRose.feature b/Java-Cucumber/src/test/resources/com/gildedrose/GildedRose.feature index 30e5415d..4463a32b 100644 --- a/Java-Cucumber/src/test/resources/com/gildedrose/GildedRose.feature +++ b/Java-Cucumber/src/test/resources/com/gildedrose/GildedRose.feature @@ -1,7 +1,19 @@ Feature: Gilded Rose quality I want to know if the quality is updated properly - Scenario: Checking foo - Given The item as "foo" - When I update the quality - Then I should get item as "foo" + Scenario: Check quality degradation for normal article + Given For article "foo" with initial quality 10 and sellIn 5 + When The quality is updated the next 10 days + Then I should get the following quality values each day: + | day | quality | sellIn | + | 1 | 9 | 4 | + | 2 | 8 | 3 | + | 3 | 7 | 2 | + | 4 | 6 | 1 | + | 5 | 5 | 0 | + | 6 | 3 | -1 | + | 7 | 1 | -2 | + | 8 | 0 | -3 | + | 9 | 0 | -4 | + | 10 | 0 | -5 | + diff --git a/Java/build.gradle b/Java/build.gradle index 616cec6a..edc0fdf6 100644 --- a/Java/build.gradle +++ b/Java/build.gradle @@ -7,21 +7,44 @@ 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' + + implementation 'org.codehaus.groovy:groovy:3.0.8' + testImplementation 'io.cucumber:cucumber-java:7.21.1' + testImplementation 'io.cucumber:cucumber-junit:7.21.1' + testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3' + testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3' + testImplementation 'org.junit.vintage:junit-vintage-engine:5.9.3' } group = 'com.gildedrose' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '1.8' +sourceCompatibility = '21' test { useJUnitPlatform() } +configurations { + cucumberRuntime { + extendsFrom testImplementation + } +} task texttest(type: JavaExec) { main = "com.gildedrose.TexttestFixture" classpath = sourceSets.test.runtimeClasspath args "30" } +task cucumber() { + dependsOn assemble, testClasses + doLast { + javaexec { + main = "io.cucumber.core.cli.Main" + classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output + args = [ + '--plugin', 'pretty', + '--plugin', 'html:target/cucumber-report.html', + '--glue', 'com.gildedrose', + 'src/test/resources'] + } + } +} diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.java b/Java/src/test/java/com/gildedrose/GildedRoseTest.java deleted file mode 100644 index 8ae29eec..00000000 --- a/Java/src/test/java/com/gildedrose/GildedRoseTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gildedrose; - -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); - } - -} diff --git a/Java/src/test/java/com/gildedrose/RunCucumberTest.java b/Java/src/test/java/com/gildedrose/RunCucumberTest.java new file mode 100644 index 00000000..a13510b0 --- /dev/null +++ b/Java/src/test/java/com/gildedrose/RunCucumberTest.java @@ -0,0 +1,12 @@ +package com.gildedrose; + +import io.cucumber.junit.Cucumber; +import io.cucumber.junit.CucumberOptions; +import org.junit.runner.RunWith; + +@RunWith(Cucumber.class) +@CucumberOptions(plugin = {"pretty", "html:target/cucumber-report.html"}, + features = {"src/test/resources"}) +public class RunCucumberTest { +} + diff --git a/Java/src/test/java/com/gildedrose/StepDefinitions.java b/Java/src/test/java/com/gildedrose/StepDefinitions.java new file mode 100644 index 00000000..ce28ab5c --- /dev/null +++ b/Java/src/test/java/com/gildedrose/StepDefinitions.java @@ -0,0 +1,49 @@ +package com.gildedrose; + +import static org.junit.Assert.*; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +public class StepDefinitions { + private Item[] items = new Item[1]; + private GildedRose app; + private int[] qualityValues; + private int[] sellInValues; + + @Given("For article {string} with initial quality {int} and sellIn {int}") + public void initial_sellin_is_and_quality_is(String name, int quality, int sellIn) { + items = new Item[] { new Item(name, sellIn, quality) }; + app = new GildedRose(items); + + } + + @When("The quality is updated the next {int} days") + public void i_update_the_quality(int days) { + qualityValues = new int[days]; + sellInValues = new int[days]; + for (int i = 0; i < days; i++) { + app.updateQuality(); + qualityValues[i] = items[0].quality; + sellInValues[i] = items[0].sellIn; + } + } + + @Then("I should get the following quality values each day:") + public void i_should_get_sellin_as_and_quality_as(io.cucumber.datatable.DataTable dataTable) { + List> rows = dataTable.asMaps(String.class, String.class); + for (int i = 0; i < rows.size(); i++) { + Map row = rows.get(i); + int expectedQuality = Integer.parseInt(row.get("quality")); + int expectedSellIn = Integer.parseInt(row.get("sellIn")); + assertEquals(expectedQuality, qualityValues[i]); + assertEquals(expectedSellIn, sellInValues[i]); + } + } +} + diff --git a/Java/src/test/resources/com/gildedrose/GildedRose.feature b/Java/src/test/resources/com/gildedrose/GildedRose.feature new file mode 100644 index 00000000..4463a32b --- /dev/null +++ b/Java/src/test/resources/com/gildedrose/GildedRose.feature @@ -0,0 +1,19 @@ +Feature: Gilded Rose quality + I want to know if the quality is updated properly + + Scenario: Check quality degradation for normal article + Given For article "foo" with initial quality 10 and sellIn 5 + When The quality is updated the next 10 days + Then I should get the following quality values each day: + | day | quality | sellIn | + | 1 | 9 | 4 | + | 2 | 8 | 3 | + | 3 | 7 | 2 | + | 4 | 6 | 1 | + | 5 | 5 | 0 | + | 6 | 3 | -1 | + | 7 | 1 | -2 | + | 8 | 0 | -3 | + | 9 | 0 | -4 | + | 10 | 0 | -5 | + diff --git a/Java/src/test/resources/cucumber.properties b/Java/src/test/resources/cucumber.properties new file mode 100644 index 00000000..b48dd63b --- /dev/null +++ b/Java/src/test/resources/cucumber.properties @@ -0,0 +1 @@ +cucumber.publish.quiet=true diff --git a/texttests/config.gr b/texttests/config.gr index b7166cd0..6b5e724a 100755 --- a/texttests/config.gr +++ b/texttests/config.gr @@ -18,8 +18,8 @@ diff_program:meld #executable:${TEXTTEST_HOME}/zig/zig-out/bin/zig # Settings for the Java version using Gradle wrapped in a python script -#executable:${TEXTTEST_HOME}/Java/texttest_rig.py -#interpreter:python +executable:${TEXTTEST_HOME}/Java/texttest_rig.py +interpreter:python # Settings for the Java version using the classpath #executable:com.gildedrose.TexttestFixture @@ -31,8 +31,8 @@ diff_program:meld #interpreter:python # Settings for the Ruby version -executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb -interpreter:ruby +#executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb +#interpreter:ruby # Settings for the C# Core version #executable:${TEXTTEST_HOME}/csharpcore/GildedRoseTests/bin/Debug/net8.0/GildedRoseTests