I am trying to write some unit tests for some code that uses Jersey to hit a RESTful web service, and am using Mockito to mock out some things. Here's my code:
@Test
void test() {
given:
// WebResource is a Jersey/JAX-RS construct.
WebResource mockResource = Mockito.mock(WebResource)
// Address.groovy is a POJO from my project.
Address mockAddress = Mockito.mock(Address)
// THE NEXT LINE IS WHAT IS THROWING THE EXCEPTION:
Mockito.when(mockResource.get(Mockito.any())).thenReturn(mockAddress)
when:
<omitted for brevity>
then:
<omitted for brevity>
}
As you can see, I'm trying to coerce Jersey to return my mockAddress
instance whenever the WebResource
attempts to do an HTTP GET.
When this runs I get:
groovy.lang.GroovyRuntimeException: Ambiguous method overloading for method com.sun.jersey.api.client.WebResource$$EnhancerByMockitoWithCGLIB$$1c2e51fa#get.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
[class com.sun.jersey.api.client.GenericType]
[class java.lang.Class]
at groovy.lang.MetaClassImpl.chooseMostSpecificParams(MetaClassImpl.java:3031)
at groovy.lang.MetaClassImpl.chooseMethodInternal(MetaClassImpl.java:2983)
at groovy.lang.MetaClassImpl.chooseMethod(MetaClassImpl.java:2926)
at groovy.lang.MetaClassImpl.getMethodWithCachingInternal(MetaClassImpl.java:1203)
at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3130)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:129)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:163)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.me.myapp.MyUnitTest.test(MyUnitTest.groovy:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
<large stack trace omitted for brevity>
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Where MyUnitTest.groovy:19
is the line:
Mockito.when(mockResource.get(Mockito.any())).thenReturn(mockAddress)
Any ideas as to what is going on?