mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +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>
|
<version>${junit.jupiter.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
|
<version>${junit.jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
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;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
|
||||||
@ -10,17 +12,40 @@ class GildedRoseTest {
|
|||||||
@Test
|
@Test
|
||||||
void shouldProcessFooItem() {
|
void shouldProcessFooItem() {
|
||||||
// given
|
// given
|
||||||
final Item[] items = new Item[]{new Item("foo", 0, 0)};
|
GildedRose app = prepareApp(new Item("foo", 0, 0));
|
||||||
GildedRose app = new GildedRose(items);
|
|
||||||
|
|
||||||
// when
|
// when
|
||||||
app.updateQuality();
|
app.updateQuality();
|
||||||
|
|
||||||
// then
|
// then
|
||||||
final Item item = app.items[0];
|
final Item item = app.items[0];
|
||||||
assertThat(item.name).isEqualTo("foo");
|
assertItem(item, "foo", 0, -1);
|
||||||
assertThat(item.quality).isEqualTo(0);
|
|
||||||
assertThat(item.sellIn).isEqualTo(-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