moded to Java folder

This commit is contained in:
jns9j04 2025-03-26 11:14:08 +01:00
parent f68dbcfdcf
commit 6871882977
10 changed files with 158 additions and 39 deletions

View File

@ -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;
}

View File

@ -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<Map<String, String>> rows = dataTable.asMaps(String.class, String.class);
for (int i = 0; i < rows.size(); i++) {
Map<String, String> 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]);
}
}
}

View File

@ -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 |

View File

@ -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']
}
}
}

View File

@ -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);
}
}

View File

@ -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 {
}

View File

@ -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<Map<String, String>> rows = dataTable.asMaps(String.class, String.class);
for (int i = 0; i < rows.size(); i++) {
Map<String, String> 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]);
}
}
}

View File

@ -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 |

View File

@ -0,0 +1 @@
cucumber.publish.quiet=true

View File

@ -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