给出代码
@Test
public void testXClass(){
XClass xclass = new XClass();
UriBuilder uriBuilder = EasyMock.createMock(UriBuilder.class);
EasyMock.expect(uriBuilder.fromUri(EasyMock.anyObject(String.class))).andReturn(dummyUriBuilder()).anyTimes();
//EasyMock.replay(uriBuilder);
EasyMock.expect(xclass.xMethod(EasyMock.anyObject(String.class))).andReturn("Done").anyTimes();
String x = xclass.xMethod(EasyMock.anyObject(String.class));
}
private UriBuilder dummyUriBuilder() {
UriBuilder uriBuilder = UriBuilder.fromUri("https://dev.x-service.com");
uriBuilder.path("/x1/");
return uriBuilder;
}
class XClass {
public String xMethod(String x) {
...
UriBuilder uriBuilder = UriBuilder.fromUri("https://dev.x-service.com");
uriBuilder.path("/x1/");
...
}
}
我在行
上收到错误UriBuilder uriBuilder = UriBuilder.fromUri("https://dev.x-service.com");
堆栈跟踪:
java.lang.IllegalArgumentException at
org.apache.cxf.jaxrs.impl.UriBuilderImpl.uri(UriBuilderImpl.java:888) at
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
如何模拟此UriBuilder
内容?我认为我在设置EasyMock时做错了。