Created
June 13, 2020 14:25
-
-
Save andyczerwonka/206043f615ffb5cd35e7f80cbca2fe54 to your computer and use it in GitHub Desktop.
Revisions
-
andyczerwonka created this gist
Jun 13, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ 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") } }