mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Implemented quality update for "Conjured" item with Cucumber tests
This commit is contained in:
parent
5f8918b3f0
commit
3792d69022
@ -12,6 +12,8 @@ dependencies {
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
|
||||
testImplementation 'com.approvaltests:approvaltests:9.3.0'
|
||||
testCompile group: 'org.assertj', name: 'assertj-core', version: '3.17.2'
|
||||
compile group: 'io.cucumber', name: 'cucumber-java', version: '6.7.0'
|
||||
testCompile group: 'io.cucumber', name: 'cucumber-junit', version: '6.7.0'
|
||||
}
|
||||
|
||||
group = 'com.gildedrose'
|
||||
@ -19,5 +21,8 @@ version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
test {
|
||||
testLogging {
|
||||
events "passed", "skipped", "failed", "standardOut", "standardError"
|
||||
}
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package com.gildedrose;
|
||||
|
||||
public class ConjuredQualityUpdater implements ItemQualityUpdater {
|
||||
|
||||
private final Item item;
|
||||
private final int normalDailyQualityDegradation = 2;
|
||||
|
||||
public ConjuredQualityUpdater(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateQuality() {
|
||||
decreaseQuality(normalDailyQualityDegradation);
|
||||
|
||||
item.sellIn = item.sellIn - 1;
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
decreaseQuality(normalDailyQualityDegradation);
|
||||
}
|
||||
}
|
||||
|
||||
void decreaseQuality(int decrementValue) {
|
||||
item.quality = item.quality - decrementValue;
|
||||
if (item.quality < 0) {
|
||||
item.quality = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,7 @@ import static com.gildedrose.ItemQualityUpdateStrategyFactory.itemQualityUpdater
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
class GildedRose {
|
||||
public class GildedRose {
|
||||
|
||||
Item[] items;
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ public class ItemQualityUpdateStrategyFactory {
|
||||
case "Sulfuras, Hand of Ragnaros": return new SulfrasQualityUpdater(item);
|
||||
case "Aged Brie": return new AgedBrieQualityUpdater(item);
|
||||
case "Backstage passes to a TAFKAL80ETC concert": return new BackstageBrieQualityUpdater(item);
|
||||
case "Conjured": return new ConjuredQualityUpdater(item);
|
||||
default: return new DefaultQualityUpdater(item);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ class ItemQualityUpdateStrategyFactoryTest {
|
||||
testFactoryFor("Aged Brie", AgedBrieQualityUpdater.class);
|
||||
testFactoryFor("Backstage passes to a TAFKAL80ETC concert", BackstageBrieQualityUpdater.class);
|
||||
testFactoryFor("xyz", DefaultQualityUpdater.class);
|
||||
testFactoryFor("Conjured", ConjuredQualityUpdater.class);
|
||||
}
|
||||
|
||||
void testFactoryFor(String name, Class<? extends ItemQualityUpdater> clazz) {
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import io.cucumber.java.en.Given;
|
||||
import io.cucumber.java.en.Then;
|
||||
import io.cucumber.java.en.When;
|
||||
import org.assertj.core.util.Arrays;
|
||||
|
||||
public class QualityUpdaterStepdefs {
|
||||
|
||||
private GildedRose gildedRose;
|
||||
private Item item;
|
||||
|
||||
@Given("^name is \"([^\"]*)\", quality is \"([^\"]*)\" and sellIn is \"([^\"]*)\"$")
|
||||
public void nameIsQualityIsAndSellInIs(String name, String quality, String sellIn) {
|
||||
item = new Item(name, Integer.parseInt(sellIn), Integer.parseInt(quality));
|
||||
gildedRose = new GildedRose(Arrays.array(item));
|
||||
}
|
||||
|
||||
@When("I calculateQuality")
|
||||
public void iCalculateQuality() {
|
||||
gildedRose.updateQuality();
|
||||
}
|
||||
|
||||
@Then("I should have new quality {string} and new sellIn {string}")
|
||||
public void iShouldHaveNewQualityAndNewSellIn(String newQuality, String newSellIn) {
|
||||
assertThat(item.quality).isEqualTo(Integer.parseInt(newQuality));
|
||||
assertThat(item.sellIn).isEqualTo(Integer.parseInt(newSellIn));
|
||||
}
|
||||
}
|
||||
13
Java/src/test/java/com/gildedrose/RunCucumberTest.java
Normal file
13
Java/src/test/java/com/gildedrose/RunCucumberTest.java
Normal file
@ -0,0 +1,13 @@
|
||||
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"}
|
||||
)
|
||||
public class RunCucumberTest {
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
Feature: Conjured items quality update
|
||||
|
||||
Scenario Outline: Conjured items quality degrades by two each day
|
||||
Given name is "<name>", quality is "<quality>" and sellIn is "<sellIn>"
|
||||
When I calculateQuality
|
||||
Then I should have new quality "<newQuality>" and new sellIn "<newSellIn>"
|
||||
|
||||
Examples:
|
||||
| name | quality | sellIn | newQuality | newSellIn |
|
||||
| Conjured | 8 | 10 | 6 | 9 |
|
||||
| Conjured | 3 | 2 | 1 | 1 |
|
||||
| Conjured | 1 | 1 | 0 | 0 |
|
||||
| Conjured | 6 | 0 | 2 | -1 |
|
||||
| Conjured | 4 | 0 | 0 | -1 |
|
||||
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
|
||||
Loading…
Reference in New Issue
Block a user