mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
Replace texttest fixture with own acceptance test
This commit is contained in:
parent
538bbce81c
commit
7f08d805bb
@ -1,36 +0,0 @@
|
||||
package com.gildedrose
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
println("OMGHAI!")
|
||||
|
||||
val items = 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 app = GildedRose(items)
|
||||
|
||||
var days = 2
|
||||
if (args.size > 0) {
|
||||
days = Integer.parseInt(args[0]) + 1
|
||||
}
|
||||
|
||||
for (i in 0..days - 1) {
|
||||
println("-------- day $i --------")
|
||||
println("name, sellIn, quality")
|
||||
for (item in items) {
|
||||
println(item)
|
||||
}
|
||||
println()
|
||||
app.updateQuality()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.gildedrose.acceptance
|
||||
|
||||
import com.gildedrose.GildedRose
|
||||
import com.gildedrose.Item
|
||||
import com.gildedrose.core.TestToFileHandler
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ThirtyDaysAcceptanceTests {
|
||||
|
||||
private val testToFileHandler = TestToFileHandler("ThirtyDays")
|
||||
|
||||
@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 output = runWithItemsForDays(initialTextFixture, 30)
|
||||
|
||||
assertEquals(output, testToFileHandler.read())
|
||||
}
|
||||
|
||||
private fun runWithItemsForDays(items: Array<Item>, days: Int): String {
|
||||
var output = ""
|
||||
|
||||
val app = GildedRose(items)
|
||||
|
||||
for (i in 0 until days) {
|
||||
output += "\nDAY $i\n"
|
||||
|
||||
items.forEach {
|
||||
val newLine = if (it == items.last()) "" else "\n"
|
||||
output += "$it$newLine"
|
||||
}
|
||||
|
||||
app.updateQuality()
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
}
|
||||
13
src/test/kotlin/com/gildedrose/core/TestToFileHandler.kt
Normal file
13
src/test/kotlin/com/gildedrose/core/TestToFileHandler.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package com.gildedrose.core
|
||||
|
||||
import java.io.File
|
||||
|
||||
class TestToFileHandler(
|
||||
fileName: String) {
|
||||
|
||||
val filePath = "texttest/$fileName.txt"
|
||||
|
||||
fun write(text: String) = File(filePath).bufferedWriter().use { it.write(text) }
|
||||
|
||||
fun read() = File(filePath).bufferedReader().readLines().joinToString(separator = "\n")
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user