Housekeeping

This commit is contained in:
Ralf Comtesse 2025-10-06 08:22:51 +02:00
parent 5ed38a6ae3
commit 639c709c99
6 changed files with 59 additions and 60 deletions

View File

@ -14,5 +14,4 @@ lazy val root = project
"org.junit.jupiter" % "junit-jupiter" % "6.0.0" % Test "org.junit.jupiter" % "junit-jupiter" % "6.0.0" % Test
), ),
testOptions += Tests.Argument(TestFrameworks.JUnit) testOptions += Tests.Argument(TestFrameworks.JUnit)
) )

View File

@ -1,5 +1,5 @@
package com.gildedrose package com.gildedrose
case class Item(val name: String, var sellIn: Int, var quality: Int) { case class Item(name: String, var sellIn: Int, var quality: Int) {
} }

View File

@ -3,16 +3,16 @@ package com.gildedrose
object Main { object Main {
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {
val items = Array[Item]( val items = Array[Item](
new Item("+5 Dexterity Vest", 10, 20), Item("+5 Dexterity Vest", 10, 20),
new Item("Aged Brie", 2, 0), Item("Aged Brie", 2, 0),
new Item("Elixir of the Mongoose", 5, 7), Item("Elixir of the Mongoose", 5, 7),
new Item("Sulfuras, Hand of Ragnaros", 0, 80), Item("Sulfuras, Hand of Ragnaros", 0, 80),
new Item("Sulfuras, Hand of Ragnaros", -1, 80), Item("Sulfuras, Hand of Ragnaros", -1, 80),
new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), Item("Backstage passes to a TAFKAL80ETC concert", 15, 20),
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), Item("Backstage passes to a TAFKAL80ETC concert", 10, 49),
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), Item("Backstage passes to a TAFKAL80ETC concert", 5, 49),
// this conjured item does not work properly yet // this conjured item does not work properly yet
new Item("Conjured Mana Cake", 3, 6) Item("Conjured Mana Cake", 3, 6)
) )
val app = new GildedRose(items) val app = new GildedRose(items)

View File

@ -0,0 +1,38 @@
package com.gildedrose
import org.approvaltests.Approvals
import org.approvaltests.reporters.DiffReporter
import org.approvaltests.reporters.UseReporter
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@UseReporter(Array(classOf[DiffReporter]))
class GildedRoseApprovalTest {
@Test
def foo(): Unit = {
val items: Array[Item] = Array(Item("foo", 0, 0))
val app: GildedRose = new GildedRose(items)
app.updateQuality()
Approvals.verifyAll("Items", items)
}
@Test
def thirtyDays(): Unit = {
val fakeoutput: ByteArrayOutputStream = new ByteArrayOutputStream()
System.setOut(new PrintStream(fakeoutput))
System.setIn(new ByteArrayInputStream("a\n".getBytes()))
val args: Array[String] = Array("30")
TexttestFixture.main(args)
val output: String = fakeoutput.toString()
Approvals.verify(output)
}
}

View File

@ -1,38 +0,0 @@
package com.gildedrose;
import org.approvaltests.Approvals
import org.approvaltests.reporters.DiffReporter
import org.approvaltests.reporters.UseReporter
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.PrintStream
@UseReporter(Array(classOf[DiffReporter]))
class GildedRoseApprovalTestInScala {
@Test
def foo(): Unit = {
val items: Array[Item] = Array(new Item("foo", 0, 0))
val app: GildedRose = new GildedRose(items);
app.updateQuality();
Approvals.verifyAll("Items", items);
}
@Test
def thirtyDays(): Unit = {
val fakeoutput: ByteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(fakeoutput));
System.setIn(new ByteArrayInputStream("a\n".getBytes()));
val args: Array[String] = Array("30")
TexttestFixture.main(args);
val output: String = fakeoutput.toString();
Approvals.verify(output);
}
}

View File

@ -5,7 +5,7 @@ import org.scalatest.matchers.should.Matchers
class GildedRoseTest extends AnyFlatSpec with Matchers { class GildedRoseTest extends AnyFlatSpec with Matchers {
it should "foo" in { it should "foo" in {
val items = Array[Item](new Item("foo", 0, 0)) val items = Array[Item](Item("foo", 0, 0))
val app = new GildedRose(items) val app = new GildedRose(items)
app.updateQuality() app.updateQuality()
app.items(0).name should equal("fixme") app.items(0).name should equal("fixme")