diff --git a/scala/build.sbt b/scala/build.sbt index c7ab2489..f922a7cd 100644 --- a/scala/build.sbt +++ b/scala/build.sbt @@ -7,12 +7,11 @@ lazy val root = project version := "1.0", scalaVersion := scala3Version, libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % "3.2.19" % Test, - "com.approvaltests" % "approvaltests" % "25.4.3" % Test, - "junit" % "junit" % "4.13.2", + "org.scalatest" %% "scalatest" % "3.2.19" % Test, + "com.approvaltests" % "approvaltests" % "25.4.3" % Test, + "junit" % "junit" % "4.13.2", "com.github.sbt.junit" % "jupiter-interface" % "0.15.1" % Test, - "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) ) diff --git a/scala/src/main/scala/com/gildedrose/Item.scala b/scala/src/main/scala/com/gildedrose/Item.scala index f30ab6e2..ed4a21f3 100644 --- a/scala/src/main/scala/com/gildedrose/Item.scala +++ b/scala/src/main/scala/com/gildedrose/Item.scala @@ -1,5 +1,5 @@ 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) { } \ No newline at end of file diff --git a/scala/src/main/scala/com/gildedrose/Main.scala b/scala/src/main/scala/com/gildedrose/Main.scala index fbd1cd9b..bd943be9 100644 --- a/scala/src/main/scala/com/gildedrose/Main.scala +++ b/scala/src/main/scala/com/gildedrose/Main.scala @@ -3,16 +3,16 @@ package com.gildedrose object Main { def main(args: Array[String]): Unit = { val items = Array[Item]( - new Item("+5 Dexterity Vest", 10, 20), - new Item("Aged Brie", 2, 0), - new Item("Elixir of the Mongoose", 5, 7), - new Item("Sulfuras, Hand of Ragnaros", 0, 80), - new Item("Sulfuras, Hand of Ragnaros", -1, 80), - new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + 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 - new Item("Conjured Mana Cake", 3, 6) + Item("Conjured Mana Cake", 3, 6) ) val app = new GildedRose(items) diff --git a/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTest.scala b/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTest.scala new file mode 100644 index 00000000..775b0957 --- /dev/null +++ b/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTest.scala @@ -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) + } +} diff --git a/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTestInScala.scala b/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTestInScala.scala deleted file mode 100644 index 117d1656..00000000 --- a/scala/src/test/scala/com/gildedrose/GildedRoseApprovalTestInScala.scala +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/scala/src/test/scala/com/gildedrose/GildedRoseTest.scala b/scala/src/test/scala/com/gildedrose/GildedRoseTest.scala index 6d8c1732..a4a3d902 100644 --- a/scala/src/test/scala/com/gildedrose/GildedRoseTest.scala +++ b/scala/src/test/scala/com/gildedrose/GildedRoseTest.scala @@ -4,10 +4,10 @@ import org.scalatest.flatspec.AnyFlatSpec import org.scalatest.matchers.should.Matchers class GildedRoseTest extends AnyFlatSpec with Matchers { - it should "foo" in { - val items = Array[Item](new Item("foo", 0, 0)) - val app = new GildedRose(items) - app.updateQuality() - app.items(0).name should equal ("fixme") - } + it should "foo" in { + val items = Array[Item](Item("foo", 0, 0)) + val app = new GildedRose(items) + app.updateQuality() + app.items(0).name should equal("fixme") + } }