ScalaMock
ScalaMock copied to clipboard
Update to ScalaMock 5.1.0 breaks argument matching
If you want to discuss a new feature, please ignore/clear this form.
ScalaMock Version (e.g. 3.5.0)
5.1
Scala Version (e.g. 2.12)
2.12
Runtime (JVM or JS)
JVM
Please describe the expected behavior of the issue
I have a lot of tests where expects
or when
is called with a stubbed POJO (Hibernate entity class written in Java). All those methods work as expected in the version 4.1.
Please provide a description of what actually happens
After upgrading from 4.1 to 5.1, all tests which have either when
or expects
with stubbed POJO arguments, are failing with 'unsatisfied expectation' error (as if the method arguments didn't match). I suspected this has something to do with equality tests, but in failing tests debugger never stops in overridden equals
method on POJOs.
In theory I can fix that using where
predicate, but this will require to rewrite ~ 100 tests - which I would like to avoid.
Reproducible Test Case
This following code will work in 4.1 and fail in 5.1 with "unsatisfied expectation - never called" error on the call to bindAccount
.
Note that SystemUser
is a Java (not Scala) class (a Hibernate entity).
"bind device API" should "bind user device" in {
val payload = new PBindDevice
payload.token = "token"
val user = stub[SystemUser]
(user.getId _).when().returns(1L)
(authService.getCurrentUser _).expects().returns(user)
(firebaseService.bindAccount _).expects(user, payload.token).returns()
(databaseSession.commit _).expects().returns()
fixture.bindUserDevice(payload)
}