mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
moded to Java folder
This commit is contained in:
parent
f68dbcfdcf
commit
6871882977
@ -18,7 +18,7 @@ public class TexttestFixture {
|
|||||||
|
|
||||||
GildedRose app = new GildedRose(items);
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
int days = 2;
|
int days = 30;
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
days = Integer.parseInt(args[0]) + 1;
|
days = Integer.parseInt(args[0]) + 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,24 +6,44 @@ import io.cucumber.java.en.Given;
|
|||||||
import io.cucumber.java.en.Then;
|
import io.cucumber.java.en.Then;
|
||||||
import io.cucumber.java.en.When;
|
import io.cucumber.java.en.When;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class StepDefinitions {
|
public class StepDefinitions {
|
||||||
private Item[] items = new Item[1];
|
private Item[] items = new Item[1];
|
||||||
private GildedRose app;
|
private GildedRose app;
|
||||||
|
private int[] qualityValues;
|
||||||
|
private int[] sellInValues;
|
||||||
|
|
||||||
@Given("The item as {string}")
|
@Given("For article {string} with initial quality {int} and sellIn {int}")
|
||||||
public void initial_sellin_is_and_quality_is(String name) {
|
public void initial_sellin_is_and_quality_is(String name, int quality, int sellIn) {
|
||||||
items[0] = new Item(name, 0, 0);
|
items = new Item[] { new Item(name, sellIn, quality) };
|
||||||
app = new GildedRose(items);
|
app = new GildedRose(items);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@When("I update the quality")
|
@When("The quality is updated the next {int} days")
|
||||||
public void i_update_the_quality() {
|
public void i_update_the_quality(int days) {
|
||||||
app.updateQuality();
|
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}")
|
@Then("I should get the following quality values each day:")
|
||||||
public void i_should_get_sellin_as_and_quality_as(String expected) {
|
public void i_should_get_sellin_as_and_quality_as(io.cucumber.datatable.DataTable dataTable) {
|
||||||
assertEquals(expected, app.items[0].name);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,19 @@
|
|||||||
Feature: Gilded Rose quality
|
Feature: Gilded Rose quality
|
||||||
I want to know if the quality is updated properly
|
I want to know if the quality is updated properly
|
||||||
|
|
||||||
Scenario: Checking foo
|
Scenario: Check quality degradation for normal article
|
||||||
Given The item as "foo"
|
Given For article "foo" with initial quality 10 and sellIn 5
|
||||||
When I update the quality
|
When The quality is updated the next 10 days
|
||||||
Then I should get item as "foo"
|
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 |
|
||||||
|
|
||||||
|
|||||||
@ -7,21 +7,44 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.6.2'
|
implementation 'org.codehaus.groovy:groovy:3.0.8'
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
|
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'
|
group = 'com.gildedrose'
|
||||||
version = '0.0.1-SNAPSHOT'
|
version = '0.0.1-SNAPSHOT'
|
||||||
sourceCompatibility = '1.8'
|
sourceCompatibility = '21'
|
||||||
|
|
||||||
test {
|
test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
}
|
}
|
||||||
|
configurations {
|
||||||
|
cucumberRuntime {
|
||||||
|
extendsFrom testImplementation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task texttest(type: JavaExec) {
|
task texttest(type: JavaExec) {
|
||||||
main = "com.gildedrose.TexttestFixture"
|
main = "com.gildedrose.TexttestFixture"
|
||||||
classpath = sourceSets.test.runtimeClasspath
|
classpath = sourceSets.test.runtimeClasspath
|
||||||
args "30"
|
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']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
12
Java/src/test/java/com/gildedrose/RunCucumberTest.java
Normal file
12
Java/src/test/java/com/gildedrose/RunCucumberTest.java
Normal 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 {
|
||||||
|
}
|
||||||
|
|
||||||
49
Java/src/test/java/com/gildedrose/StepDefinitions.java
Normal file
49
Java/src/test/java/com/gildedrose/StepDefinitions.java
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
19
Java/src/test/resources/com/gildedrose/GildedRose.feature
Normal file
19
Java/src/test/resources/com/gildedrose/GildedRose.feature
Normal 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 |
|
||||||
|
|
||||||
1
Java/src/test/resources/cucumber.properties
Normal file
1
Java/src/test/resources/cucumber.properties
Normal file
@ -0,0 +1 @@
|
|||||||
|
cucumber.publish.quiet=true
|
||||||
@ -18,8 +18,8 @@ diff_program:meld
|
|||||||
#executable:${TEXTTEST_HOME}/zig/zig-out/bin/zig
|
#executable:${TEXTTEST_HOME}/zig/zig-out/bin/zig
|
||||||
|
|
||||||
# Settings for the Java version using Gradle wrapped in a python script
|
# Settings for the Java version using Gradle wrapped in a python script
|
||||||
#executable:${TEXTTEST_HOME}/Java/texttest_rig.py
|
executable:${TEXTTEST_HOME}/Java/texttest_rig.py
|
||||||
#interpreter:python
|
interpreter:python
|
||||||
|
|
||||||
# Settings for the Java version using the classpath
|
# Settings for the Java version using the classpath
|
||||||
#executable:com.gildedrose.TexttestFixture
|
#executable:com.gildedrose.TexttestFixture
|
||||||
@ -31,8 +31,8 @@ diff_program:meld
|
|||||||
#interpreter:python
|
#interpreter:python
|
||||||
|
|
||||||
# Settings for the Ruby version
|
# Settings for the Ruby version
|
||||||
executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb
|
#executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb
|
||||||
interpreter:ruby
|
#interpreter:ruby
|
||||||
|
|
||||||
# Settings for the C# Core version
|
# Settings for the C# Core version
|
||||||
#executable:${TEXTTEST_HOME}/csharpcore/GildedRoseTests/bin/Debug/net8.0/GildedRoseTests
|
#executable:${TEXTTEST_HOME}/csharpcore/GildedRoseTests/bin/Debug/net8.0/GildedRoseTests
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user