I'm trying to mock Jersey WebResource with Mockito, and can't do it
-
28-09-2019 - |
문제
This is my code (Jersey 1.4 + Mockito 1.8.5):
import org.junit.Test;
import static org.junit.Assert.*;
import com.sun.jersey.api.client.WebResource;
import static org.mockito.Mockito.*;
public FooTest {
@Test public shouldMakeAHttpCall() {
WebResource wr = mock(WebResource.class);
doReturn(wr).when(wr).accept(anyVararg());
doReturn("some text").when(wr).get(String.class);
}
}
Compiler says:
cannot find symbol: method accept(java.lang.Object)
location: class com.sun.jersey.api.client.WebResource
There is something wrong with anyVargarg()
, but what exactly?
해결책
This is the solution:
doReturn(wr).when(wr).accept((MediaType) anyVararg());
다른 팁
Have you tried:
WebResource wr = mock(WebResource.class);
when(wr.accept(anyObject())).thenReturn(wr);
when(wr.get(anyString()).thenReturn("some text");
제휴하지 않습니다 StackOverflow