繁体   English   中英

我正在尝试使用Mockito模拟Jersey WebResource,但无法做到

[英]I'm trying to mock Jersey WebResource with Mockito, and can't do it

这是我的代码( 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);
  }
}

编译说:

cannot find symbol: method accept(java.lang.Object)
location: class com.sun.jersey.api.client.WebResource

anyVargarg() ,但是究竟是什么呢?

这是解决方案:

doReturn(wr).when(wr).accept((MediaType) anyVararg());

你有没有尝试过:

WebResource wr = mock(WebResource.class);
when(wr.accept(anyObject())).thenReturn(wr);
when(wr.get(anyString()).thenReturn("some text");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM