Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Expectation recorded on superclass method gets overwritten #209
Expectation recorded on superclass method on subclass object is overwritten if same expectation is recorded on different subclass object.
Best shown on following unit test (testng 6.9.6, jmockit 1.19) which I would expect to pass.
It's not a bug, even if in a case like this the mocking behavior is not what one would expect; well, unless you are familiar with the exact semantics of @Mocked.
Expectations recorded/verified on a @Mocked instance, by default, do not care about the actual instance used during replay (the one the code under test used); they will match regardless, considering only which method was called and any arguments and argument matchers.
If the instance on which the expectation was recorded needs to match the instances at replay time, then the test should use @Injectable rather than @Mocked. Alternatively, the test can use the "onInstance(mocked instance)" constraint to force instance matching.