I recently upgraded from jMock 2.5.1 to 2.6.0, and it seems that some of its dependencies have changed, causing some of my previously passing tests to fail.
One of my tests has the following expectation that used for the common setup of several tests:
oneOf(service).event(with(any(Long.class)));
In my test suite, event
gets called with both null
and valid Long
values. This used to be perfectly acceptable in jMock 2.5.1, but after the upgrade, I get the following exception:
java.lang.AssertionError: unexpected invocation: service.event(null)
expectations:
expected once, never invoked: service.event(an instance of java.lang.Long)
what happened before this:
locator.locateService()
service.getService()
at org.jmock.api.ExpectationError.unexpected(ExpectationError.java:23)
at org.jmock.internal.InvocationDispatcher.dispatch(InvocationDispatcher.java:85)
at org.jmock.Mockery.dispatch(Mockery.java:231)
at org.jmock.Mockery.access$100(Mockery.java:29)
at org.jmock.Mockery$MockObject.invoke(Mockery.java:271)
at org.jmock.internal.InvocationDiverter.invoke(InvocationDiverter.java:27)
at org.jmock.internal.FakeObjectMethods.invoke(FakeObjectMethods.java:38)
at org.jmock.lib.concurrent.Synchroniser.synchroniseInvocation(Synchroniser.java:82)
at org.jmock.lib.concurrent.Synchroniser.access$000(Synchroniser.java:23)
at org.jmock.lib.concurrent.Synchroniser$1.invoke(Synchroniser.java:74)
at org.jmock.lib.JavaReflectionImposteriser$1.invoke(JavaReflectionImposteriser.java:33)
at com.sun.proxy.$Proxy27.system(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
I suspect this might be due to the new version of Hamcrest that jMock 2.6.0 uses, but I'm unsure. Is there a more suitable matcher I can use to specify both null and non-null values for this method?
(Long) with(anything())
though. – Tatiana