From d187e00d1f88de0a0147027ee5f72bc06a1418bf Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Fri, 5 Oct 2018 21:23:30 +0200 Subject: [PATCH] Extract fixture and make it immutable --- .../kotlin/com/gildedrose/GildedRoseTest.kt | 17 +++++++---------- .../acceptance/ThirtyDaysAcceptanceTests.kt | 13 ++----------- .../kotlin/com/gildedrose/core/TestUtils.kt | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 21 deletions(-) create mode 100644 src/test/kotlin/com/gildedrose/core/TestUtils.kt diff --git a/src/test/kotlin/com/gildedrose/GildedRoseTest.kt b/src/test/kotlin/com/gildedrose/GildedRoseTest.kt index 8ec4967e..79b199bd 100644 --- a/src/test/kotlin/com/gildedrose/GildedRoseTest.kt +++ b/src/test/kotlin/com/gildedrose/GildedRoseTest.kt @@ -1,21 +1,18 @@ package com.gildedrose +import com.gildedrose.core.TestUtils import org.assertj.core.api.Java6Assertions.assertThat import org.junit.Test import java.util.* class GildedRoseTest { - private val store = arrayOf( - Item("+5 Dexterity Vest", 10, 20), // - Item("Aged Brie", 2, 0), // - Item("Elixir of the Mongoose", 5, 7), // - Item("Sulfuras, Hand of Ragnaros", 0, 80), // - Item("Sulfuras, Hand of Ragnaros", -1, 80), - Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - Item("Backstage passes to a TAFKAL80ETC concert", 5, 49) - ) + private lateinit var store: Array + + @Before + fun setUp() { + store = TestUtils.fixture + } @Test fun givenUnknownItem_afterRandomNumberOfDays_shouldDecreaseSellInByNumberOfDays() { diff --git a/src/test/kotlin/com/gildedrose/acceptance/ThirtyDaysAcceptanceTests.kt b/src/test/kotlin/com/gildedrose/acceptance/ThirtyDaysAcceptanceTests.kt index b9fab047..7ee84c49 100644 --- a/src/test/kotlin/com/gildedrose/acceptance/ThirtyDaysAcceptanceTests.kt +++ b/src/test/kotlin/com/gildedrose/acceptance/ThirtyDaysAcceptanceTests.kt @@ -3,6 +3,7 @@ package com.gildedrose.acceptance import com.gildedrose.GildedRose import com.gildedrose.Item import com.gildedrose.core.TestToFileHandler +import com.gildedrose.core.TestUtils import org.junit.Assert.assertEquals import org.junit.Test @@ -12,17 +13,7 @@ class ThirtyDaysAcceptanceTests { @Test fun withInitialTextFixture_whenRunForThirtyDays_itShouldHaveSameOutputAsLegacyCode() { - val initialTextFixture = arrayOf( - Item("+5 Dexterity Vest", 10, 20), // - Item("Aged Brie", 2, 0), // - Item("Elixir of the Mongoose", 5, 7), // - Item("Sulfuras, Hand of Ragnaros", 0, 80), // - Item("Sulfuras, Hand of Ragnaros", -1, 80), - Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), - // this conjured item does not work properly yet - Item("Conjured Mana Cake", 3, 6)) + val initialTextFixture = TestUtils.fixture val output = runWithItemsForDays(initialTextFixture, 30) diff --git a/src/test/kotlin/com/gildedrose/core/TestUtils.kt b/src/test/kotlin/com/gildedrose/core/TestUtils.kt new file mode 100644 index 00000000..2d967222 --- /dev/null +++ b/src/test/kotlin/com/gildedrose/core/TestUtils.kt @@ -0,0 +1,18 @@ +package com.gildedrose.core + +import com.gildedrose.Item + +object TestUtils { + + val fixture + get() = arrayOf( + Item("+5 Dexterity Vest", 10, 20), + Item("Aged Brie", 2, 0), + Item("Elixir of the Mongoose", 5, 7), + Item("Sulfuras, Hand of Ragnaros", 0, 80), + Item("Sulfuras, Hand of Ragnaros", -1, 80), + Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), + Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + Item("Conjured Mana Cake", 3, 6)) +} \ No newline at end of file