views:

29

answers:

1

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?

A: 

Have you tried:

WebResource wr = mock(WebResource.class);
when(wr.accept(anyObject())).thenReturn(wr);
when(wr.get(anyString()).thenReturn("some text");
amorfis
@amorfis Yes, the same story, the same compiler message...
Vincenzo
Maybe try anyObject() instead of anyVararg(). Just edited the answer.
amorfis