I have the class A with private methods a and b and public method c.
Methods a and b are covered by tests.
The public method c is used with a parameter, so it can call a or b with if stmt
I want test method c with behavior-based test (test a called for some parameter and b called for other). I can't figure out how achieve this with ScalaTest and ScalaMock
Part of the class code
protected final def generate(leftBranch: List[L], leftPoint: L, rightBranch: List[L], rightPoint: L): C = {
val lEmpty = leftBranch.isEmpty
val rEmpty = rightBranch.isEmpty
if (lEmpty && rEmpty) {
val cc = leafOrdering.compare(leftPoint, rightPoint)
if (cc < 0) {
nextOrExpand(leftPoint){ p =>
if (leafOrdering.compare(p, rightPoint) < 0) {
usePoint(p)
} else
expand(leftPoint)
}
}
else if (cc == 0)
throw SamePointException()
else
throw LowerRestrictionException()
}
else if (lEmpty) {
val cc = leafOrdering.compare(leftPoint, rightBranch.head)
if (cc < 0)
nextOrExpand(leftPoint){ p =>
if (leafOrdering.compare(p, rightBranch.head) <= 0) {
usePoint(p)
} else {
expand(leftPoint)
}
}
else if (cc == 0)
minimalRestricted(List(leftPoint), startBranchWith, rightBranch.tail, rightPoint)
else
throw LowerRestrictionException()
}
else if (rEmpty)
if (leafOrdering.compare(leftBranch.head, rightPoint) < 0)
next(leftBranch, leftPoint)
else
throw LowerRestrictionException()
else {
if (leafOrdering.compare(leftBranch.head, rightBranch.head) < 0)
next(leftBranch, leftPoint)
else {
throw LowerRestrictionException()
}
}
}
Methods nextOrExpand, usePoint, expand, minimalRestricted, next are private and tested. The generate method is a public method that needs to be tested.
If I'm not wrong, with
behavior-based testyou want to write your test like the example showed hereIf that's what you want, you would be able to see that you can
mix different traitsto write your tests using different styles. Also based on which one you pick, the output of the test will be different.scalatest also provide a rich DSL that will let you write your test close to a natural language. You can use matchers that offer different methods such as
have,be,contains, etc