From 41ebe9f98e459b274ecd09c54d7d189f91ce5ce8 Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov Date: Mon, 24 Jun 2019 07:39:29 +0200 Subject: [PATCH] more Backstage passes tests --- .../gildedrose/GildedRoseBackstageTest.java | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/Java/src/test/java/com/gildedrose/GildedRoseBackstageTest.java b/Java/src/test/java/com/gildedrose/GildedRoseBackstageTest.java index ead1d854..1de86ed8 100644 --- a/Java/src/test/java/com/gildedrose/GildedRoseBackstageTest.java +++ b/Java/src/test/java/com/gildedrose/GildedRoseBackstageTest.java @@ -2,11 +2,13 @@ package com.gildedrose; import io.qameta.allure.Feature; import io.qameta.allure.Story; +import lombok.val; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static com.gildedrose.TestHelper.assertItem; import static com.gildedrose.TestHelper.prepareApp; +import static org.apache.commons.lang3.RandomUtils.nextInt; @Story("\"Backstage passes\", like aged brie, increases in Quality as its SellIn value approaches;\n" + @@ -16,12 +18,63 @@ class GildedRoseBackstageTest { private static final String ITEM_NAME = "Backstage passes to a TAFKAL80ETC concert"; + @Feature("Quality increases by 2 when there are 10 days or less") + @ParameterizedTest(name = "sellIn: {arguments}") + @ValueSource(ints = {10, 9, 8, 7, 6}) + void shouldIncreaseQualityBy2WhenThereAre10DaysOrLess(int sellIn) { + // given + val initialQuality = nextInt(10, 40); + GildedRose app = prepareApp(new Item(ITEM_NAME, sellIn, initialQuality)); + + // when + app.updateQuality(); + + // then + final Item item = app.items[0]; + assertItem(item, ITEM_NAME, sellIn - 1, initialQuality + 2); + } + + @Feature("Quality increases by 3 when there are 5 days or less") + @ParameterizedTest(name = "sellIn: {arguments}") + @ValueSource(ints = {5, 4, 3, 2, 1}) + void shouldIncreaseQualityBy32WhenThereAre5DaysOrLess(int sellIn) { + // given + val initialQuality = nextInt(10, 40); + GildedRose app = prepareApp(new Item(ITEM_NAME, sellIn, initialQuality)); + + // when + app.updateQuality(); + + // then + final Item item = app.items[0]; + assertItem(item, ITEM_NAME, sellIn - 1, initialQuality + 3); + } + + @Feature("Quality drops to 0 after the concert") @ParameterizedTest(name = "sellIn: {arguments}") @ValueSource(ints = {0, -1}) void shouldDropQualityToZeroAfterTheConcert(int sellIn) { // given - GildedRose app = prepareApp(new Item(ITEM_NAME, sellIn, 10)); + val initialQuality = nextInt(10, 40); + GildedRose app = prepareApp(new Item(ITEM_NAME, sellIn, initialQuality)); + + // when + app.updateQuality(); + + // then + final Item item = app.items[0]; + assertItem(item, ITEM_NAME, sellIn - 1, 0); + } + + + @Feature("The Quality of an item is never more than 50") + @ParameterizedTest(name = "sellIn: {arguments}") + @ValueSource(ints = {0, -1}) + void shouldNotIncreaseQualityAbove50(int sellIn) { + // given + val initialQuality = nextInt(10, 40); + GildedRose app = prepareApp(new Item(ITEM_NAME, sellIn, initialQuality)); // when app.updateQuality();