mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-11 20:02:09 +00:00
before cleanup without java tests
This commit is contained in:
parent
2e0e557c6e
commit
2b32087843
2
scala/.gitignore
vendored
2
scala/.gitignore
vendored
@ -1,4 +1,6 @@
|
|||||||
/bin/
|
/bin/
|
||||||
|
lib
|
||||||
|
project
|
||||||
|
|
||||||
# OSX Finder
|
# OSX Finder
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@ -11,8 +11,7 @@ lazy val root = project
|
|||||||
"com.approvaltests" % "approvaltests" % "25.4.3" % Test,
|
"com.approvaltests" % "approvaltests" % "25.4.3" % Test,
|
||||||
"junit" % "junit" % "4.13.2",
|
"junit" % "junit" % "4.13.2",
|
||||||
"com.github.sbt.junit" % "jupiter-interface" % "0.15.1" % Test,
|
"com.github.sbt.junit" % "jupiter-interface" % "0.15.1" % Test,
|
||||||
// todo: comment about 5.8.0
|
"org.junit.jupiter" % "junit-jupiter" % "6.0.0" % Test
|
||||||
"org.junit.jupiter" % "junit-jupiter" % "5.7.0" % Test
|
|
||||||
),
|
),
|
||||||
testOptions += Tests.Argument(TestFrameworks.JUnit)
|
testOptions += Tests.Argument(TestFrameworks.JUnit)
|
||||||
|
|
||||||
|
|||||||
@ -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(DiffReporter.class)
|
|
||||||
public class GildedRoseApprovalTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void foo() {
|
|
||||||
|
|
||||||
Item[] items = new Item[]{new Item("foo", 0, 0)};
|
|
||||||
GildedRose app = new GildedRose(items);
|
|
||||||
app.updateQuality();
|
|
||||||
|
|
||||||
Approvals.verifyAll("Items", items);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void thirtyDays() {
|
|
||||||
|
|
||||||
ByteArrayOutputStream fakeoutput = new ByteArrayOutputStream();
|
|
||||||
System.setOut(new PrintStream(fakeoutput));
|
|
||||||
System.setIn(new ByteArrayInputStream("a\n".getBytes()));
|
|
||||||
|
|
||||||
String[] args = {"30"};
|
|
||||||
TexttestFixture.main(args);
|
|
||||||
String output = fakeoutput.toString();
|
|
||||||
|
|
||||||
Approvals.verify(output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,33 +1,38 @@
|
|||||||
package com.gildedrose
|
package com.gildedrose;
|
||||||
|
|
||||||
import org.scalatest.flatspec.AnyFlatSpec
|
import org.approvaltests.Approvals
|
||||||
import org.scalatest.matchers.should.Matchers
|
import org.approvaltests.reporters.DiffReporter
|
||||||
|
import org.approvaltests.reporters.UseReporter
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
import java.io.{File, FileOutputStream}
|
import java.io.ByteArrayInputStream
|
||||||
import scala.io.Source
|
import java.io.ByteArrayOutputStream
|
||||||
|
import java.io.PrintStream
|
||||||
|
|
||||||
|
@UseReporter(Array(classOf[DiffReporter]))
|
||||||
|
class GildedRoseApprovalTestInScala {
|
||||||
|
|
||||||
class GildedRoseApprovalTestInScala extends AnyFlatSpec with Matchers {
|
@Test
|
||||||
ignore should "return the result of the golden master" in {
|
def foo(): Unit = {
|
||||||
val fileWithTestResult = new File("approvaltests/gildedrose.testresult.txt")
|
|
||||||
val outputStream = new FileOutputStream(fileWithTestResult)
|
|
||||||
Console.withOut(outputStream) {
|
|
||||||
|
|
||||||
TexttestFixture.main(Array("30"))
|
val items: Array[Item] = Array(new Item("foo", 0, 0))
|
||||||
}
|
val app: GildedRose = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
|
||||||
val approvedFile = "approvaltests/gildedrose.approved.txt"
|
Approvals.verifyAll("Items", items);
|
||||||
val sourceForTestResults = Source.fromFile(fileWithTestResult)
|
|
||||||
val sourceForApprovedFile = Source.fromFile(approvedFile)
|
|
||||||
|
|
||||||
val resultingOutput =
|
|
||||||
try sourceForTestResults.getLines().toVector
|
|
||||||
finally sourceForTestResults.close()
|
|
||||||
val approvedOutput =
|
|
||||||
try sourceForApprovedFile.getLines().toVector
|
|
||||||
finally sourceForTestResults.close()
|
|
||||||
|
|
||||||
resultingOutput should equal(approvedOutput)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@ package com.gildedrose
|
|||||||
object TexttestFixture {
|
object TexttestFixture {
|
||||||
|
|
||||||
def main(args: Array[String]): Unit = {
|
def main(args: Array[String]): Unit = {
|
||||||
println("OMGHAI!")
|
System.out.println("OMGHAI!")
|
||||||
|
|
||||||
val items = Array[Item](
|
val items = Array[Item](
|
||||||
Item("+5 Dexterity Vest", 10, 20),
|
Item("+5 Dexterity Vest", 10, 20),
|
||||||
@ -23,12 +23,12 @@ object TexttestFixture {
|
|||||||
if (args.nonEmpty) days = args(0).toInt + 1
|
if (args.nonEmpty) days = args(0).toInt + 1
|
||||||
|
|
||||||
for (i <- 0 until days) {
|
for (i <- 0 until days) {
|
||||||
println("-------- day " + i + " --------")
|
System.out.println("-------- day " + i + " --------")
|
||||||
println("name, sellIn, quality")
|
System.out.println("name, sellIn, quality")
|
||||||
for (item <- items) {
|
for (item <- items) {
|
||||||
println(s"${item.name}, ${item.sellIn}, ${item.quality}")
|
System.out.println(s"${item.name}, ${item.sellIn}, ${item.quality}")
|
||||||
}
|
}
|
||||||
println()
|
System.out.println()
|
||||||
app.updateQuality()
|
app.updateQuality()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user