org.autotdd.engine.JunitUniverse.scala Maven / Gradle / Ivy
package org.autotdd.engine
import java.io.File
trait JunitUniverse[R] extends EngineUniverse[R] {
trait JUnitManipulator {
def nuke;
def append(s: String);
}
class JunitFileManipulator(val file: File) extends JUnitManipulator {
def nuke =
file.delete()
def append(s: String) =
Files.appendToFile(file)((pw) => pw.append(s))
}
class JUnitTestManipulator() extends JUnitManipulator {
var results: List[String] = null
def nuke =
if (results == null)
results = List()
else
throw new IllegalStateException;
def append(s: String) = results = s :: results
}
class JunitScenarioReporter(manipulator: JUnitManipulator, displayProcessor: LoggerDisplayProcessor) extends ScenarioVisitor {
def start = manipulator.nuke
def visitUseCase(ui: Int, u: UseCase) {
val text = Usecase { ui }: { u.description }
.mkString;
manipulator.append(text)
}
def visitUseCaseEnd(u: UseCase) {
}
def visitScenario(useCaseindex: Int, u: UseCase, scenarioIndex: Int, s: Scenario) {
val paramsString = s.params.mkString("
,")
val text =
{ scenarioIndex }{ s.description.collect { case d => ": " + d } getOrElse ("") }
Parameters { s.params.mkString(",") }
Expected { s.expected.getOrElse("") }
{
if (s.because.isDefined)
Because { s.becauseString } { s.because.get.comment }
}
{
if (s.code.isDefined)
Code { s.code.get.description } { s.code.get.comment }
}
{
if (s.assertions.size > 0)
Assertions { s.assertions.mkString(",") }
}
;
val t = text.mkString
manipulator.append(t)
}
def end={}
def ifPrint: (String, Node) => String = ???
def elsePrint: (String, Node) => String = ???
def endPrint: (String, Node) => String = ???
}
}