Maybe I'm expecting too much, but I can't seem to verify correctly on
Mockito spies.
I have this:
val newVehicle = spy(Vehicle.create)
println("*** new
v"+Integer.toHexString(System.identityHashCode(newVehicle)))
I then call the test methods and afterwards verify:
there was no(newVehicle).end
there was one(newVehicle).save
This results in:
java.lang.Exception: The mock was not called as expected:
Missing method call for verify(mock) here:
-> at org.specs2.mock.MockitoMocker$class.verify(MockitoMocker.scala:31)
Example of correct verification:
verify(mock).doSomething()
Also, this error might show up because you verify either of:
final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
I've overidden the save method on Vehicle:
override def save = {
println("*** Saving v"+Integer.toHexString(System.identityHashCode(this)))
super.save
}
And I can see the method is in fact called:
*** new v 32935741
*** Saving v 32935741
Any hints?
/Jeppe
Updating both specs2 & Mockito to SNAPSHOT/RC1 didn't help. It seems
to be a Mockito problem verifying calls on methods defined in traits:
trait Foo {
def func = "ooh"
}
class Bar extends Foo {
def g = "aah"
}
val b = org.mockito.Mockito.spy(new Bar)
org.mockito.Mockito.verify(b, org.mockito.Mockito.times(0)).g
org.mockito.Mockito.verify(b, org.mockito.Mockito.times(0)).func
The first verify works, the second fails.
This is rather bad. Any good workarounds? Do you know of any work
being done in this area or should I bring this to the mockito folks?
/Jeppe
I've added this http://code.google.com/p/mockito/issues/detail?id=287
But it seems Scala is not high on the priority list. I'm not that
familiar with the bytecode of Scala, so might be a while :-(
/Jeppe