I found some simple examples, but nothing works.
a model:
class Product() {
var price: Int = 0
var stock: Int = 0
def addPrice(price: Int): Int = {
this.price = price
this.price
}
def addStock(qty: Int): Int = {
this.stock += qty
this.stock
}
}
and my test class
classProductSpec extends AnyFlatSpec with MockFactory with OneInstancePerTest {
val m = mock[Product]
// suites (test examples)
inAnyOrder {
(m.addPrice _).expects(40).returns(40).once
inSequence {
(m.addStock _).expects(20).returns(20).once
(m.addStock _).expects(10).returns(30).once
}
}
// tests
it should "set price" in {
assert(m.addPrice(40) == 40)
}
it should "add new qty. Step 1" in {
assert(m.addStock(20) == 20)
}
it should "add new qty. Step 2" in {
assert(m.addStock(10) == 30)
}
}
Every time, the error is:
Expected:
inAnyOrder {
inAnyOrder {
<mock-1> Product.addPrice(40) once (never called - UNSATISFIED)
...
}
}
If I run only one suite and one assert, it works:
(m.addPrice _).expects(40).returns(40).once
// tests
it should "set price" in {
assert(m.addPrice(40) == 40)
}