문제

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");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top