mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
The Quality of an item is never negative
This commit is contained in:
parent
534dd114e3
commit
a55c6ba494
@ -28,6 +28,12 @@
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
@ -10,17 +12,40 @@ class GildedRoseTest {
|
||||
@Test
|
||||
void shouldProcessFooItem() {
|
||||
// given
|
||||
final Item[] items = new Item[]{new Item("foo", 0, 0)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
GildedRose app = prepareApp(new Item("foo", 0, 0));
|
||||
|
||||
// when
|
||||
app.updateQuality();
|
||||
|
||||
// then
|
||||
final Item item = app.items[0];
|
||||
assertThat(item.name).isEqualTo("foo");
|
||||
assertThat(item.quality).isEqualTo(0);
|
||||
assertThat(item.sellIn).isEqualTo(-1);
|
||||
assertItem(item, "foo", 0, -1);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name="Initial quality: {arguments}")
|
||||
@ValueSource(ints={0,1})
|
||||
void shouldTheQualityNeverBeNegative(int initialQuality) {
|
||||
// given
|
||||
GildedRose app = prepareApp(new Item("foo", 0, initialQuality));
|
||||
|
||||
// when
|
||||
app.updateQuality();
|
||||
|
||||
// then
|
||||
final Item item = app.items[0];
|
||||
assertItem(item, "foo", 0, -1);
|
||||
}
|
||||
|
||||
private void assertItem(Item item, String expectedName, int expectedQuality, int expectedSellIn) {
|
||||
assertThat(item).as("item").isNotNull();
|
||||
assertThat(item.name).as("name").isEqualTo(expectedName);
|
||||
assertThat(item.quality).as("quality").isEqualTo(expectedQuality);
|
||||
assertThat(item.sellIn).as("sellIn").isEqualTo(expectedSellIn);
|
||||
}
|
||||
|
||||
private static GildedRose prepareApp(Item... items) {
|
||||
return new GildedRose(items);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user