Hi,
Story
I have a mock for a class with method having parameters with default values. My code calling it with only the mandatory params. In my test I want to verify that the mocked object has been called correctly.
Issue
In the test the statement "there was one(a).foo(12)" always passes without respect to the parameter value, that is the actual code in the code could be a.foo(100) but this line passes.
Question
How should such code be tested using specs2? The workaround I used is to test all the parameters, that is: there was one(a).foo(be_===(12), any[Int])
Example
class A {
def foo(x: Int, y: Int = 10) = x * y
}
class B(a: A) {
def bar(x: Int) = a.foo(x)
}
class MyTest extends SpecificationWithJUnit with Mockito {
trait ctx extends Scope {
val a = mock[A]
val aut = new B(a)
}
"passes (works wrong!)" in new ctx {
b.bar(11)
got {
one(a).foo(12)
}
}
"fails (works correct)" in new ctx {
b.bar(11)
got {
one(a).foo(be_===(12),any[Int])
}
}
}
Thanks,
Alex