mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
Conjured items rule
This commit is contained in:
parent
59558ab822
commit
af9b68cb5e
@ -2,6 +2,7 @@ package com.gildedrose;
|
|||||||
|
|
||||||
import com.gildedrose.rules.AgedBrieQualityRule;
|
import com.gildedrose.rules.AgedBrieQualityRule;
|
||||||
import com.gildedrose.rules.BackstagePassQualityRule;
|
import com.gildedrose.rules.BackstagePassQualityRule;
|
||||||
|
import com.gildedrose.rules.ConjuredQualityRule;
|
||||||
import com.gildedrose.rules.DefaultQualityRule;
|
import com.gildedrose.rules.DefaultQualityRule;
|
||||||
import com.gildedrose.rules.QualityRule;
|
import com.gildedrose.rules.QualityRule;
|
||||||
import com.gildedrose.rules.Result;
|
import com.gildedrose.rules.Result;
|
||||||
@ -18,6 +19,7 @@ class GildedRose {
|
|||||||
new SulfurasQualityRule(),
|
new SulfurasQualityRule(),
|
||||||
new AgedBrieQualityRule(),
|
new AgedBrieQualityRule(),
|
||||||
new BackstagePassQualityRule(),
|
new BackstagePassQualityRule(),
|
||||||
|
new ConjuredQualityRule(),
|
||||||
new DefaultQualityRule()
|
new DefaultQualityRule()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.gildedrose.rules;
|
||||||
|
|
||||||
|
import static java.lang.Integer.max;
|
||||||
|
|
||||||
|
public class ConjuredQualityRule implements QualityRule {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldApply(String itemName) {
|
||||||
|
return itemName != null && itemName.startsWith("Conjured ");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result calculateQuality(int oldQuality, int newSellIn) {
|
||||||
|
return new Result(max(oldQuality - 2, 0), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,35 +1,17 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import lombok.val;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
import static com.gildedrose.TestHelper.assertItem;
|
import static com.gildedrose.TestHelper.assertItem;
|
||||||
import static com.gildedrose.TestHelper.prepareApp;
|
import static com.gildedrose.TestHelper.prepareApp;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
import static org.apache.commons.lang3.RandomUtils.nextInt;
|
|
||||||
|
|
||||||
|
|
||||||
class GildedRoseConjuredTest {
|
class GildedRoseConjuredTest {
|
||||||
|
|
||||||
private static final String NAME = "Conjured Mana Cake";
|
private static final String ITEM_NAME = "Conjured Mana Cake";
|
||||||
|
|
||||||
@Feature("The Quality of an item is never more than 50")
|
|
||||||
@ParameterizedTest(name = "Initial quality: {arguments}")
|
|
||||||
@ValueSource(ints = {49, 50})
|
|
||||||
void shouldNotIncreaseQualityAbove50(int initialQuality) {
|
|
||||||
// given
|
|
||||||
val initialSellIn = nextInt(3, 50);
|
|
||||||
GildedRose app = prepareApp(new Item(NAME, initialSellIn, initialQuality));
|
|
||||||
|
|
||||||
// when
|
|
||||||
app.updateQuality();
|
|
||||||
|
|
||||||
// then
|
|
||||||
final Item item = app.items[0];
|
|
||||||
assertItem(item, "Aged Brie", initialSellIn - 1, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Feature("\"Conjured\" items degrade in Quality twice as fast as normal items")
|
@Feature("\"Conjured\" items degrade in Quality twice as fast as normal items")
|
||||||
@Feature("The Quality of an item is never negative")
|
@Feature("The Quality of an item is never negative")
|
||||||
@ -37,7 +19,7 @@ class GildedRoseConjuredTest {
|
|||||||
@ValueSource(ints = {0, 1, 2, 3, 49, 50})
|
@ValueSource(ints = {0, 1, 2, 3, 49, 50})
|
||||||
void shouldDegradeInQualityTwiceFast(int initialQuality) {
|
void shouldDegradeInQualityTwiceFast(int initialQuality) {
|
||||||
// given
|
// given
|
||||||
GildedRose app = prepareApp(new Item("Aged Brie", 1, initialQuality));
|
GildedRose app = prepareApp(new Item(ITEM_NAME, 1, initialQuality));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
@ -45,6 +27,6 @@ class GildedRoseConjuredTest {
|
|||||||
// then
|
// then
|
||||||
final Item item = app.items[0];
|
final Item item = app.items[0];
|
||||||
final int expectedQuality = max(initialQuality - 2, 0);
|
final int expectedQuality = max(initialQuality - 2, 0);
|
||||||
assertItem(item, "Aged Brie", 0, expectedQuality);
|
assertItem(item, ITEM_NAME, 0, expectedQuality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user