package io.citrine.orion.core.domain import io.citrine.testing.BaseUnitTest import scala.collection.mutable.ListBuffer class BusinessRuleTest extends BaseUnitTest { trait StatusInfo { def write(msg: String) def msgs(): Seq[String] } class StatusInfoWriter extends StatusInfo { private val buffer = ListBuffer[String]() override def write(msg: String): Unit = buffer += msg override def msgs(): List[String] = buffer.toList } implicit val statusInfo = new StatusInfoWriter case class Row(contents: String) def rule(desc: String)(predicate: => Boolean)(implicit statusInfo: StatusInfo): Boolean = { val ex = predicate val prefix = if (ex) "Passed:" else "Failed:" statusInfo.write(s"$prefix $desc") ex } test("allow less than 100 rows") { val rows = List(Row("1")) rule("Limit rows to 100") { rows.length < 100 } shouldBe true statusInfo.msgs contains ("Passed: Limit rows to 100") } test("fail when rows > 100") { val rows = for (i <- 0 to 101) yield Row(s"$i") rule("Limit rows to 100") { rows.length < 100 } shouldBe false statusInfo.msgs contains ("Failed: Limit rows to 100") } }