我有一个Service类(MyService),它使用构造函数实例化一个WebserviceClient类(WSService_Service)。
我尝试使用
进行模拟PowerMockito.whenNew(WSService_Service.class).withNoArguments().thenReturn(wSService);
但是它不会工作,它仍然会通过调用WebserviceClient的超级方法的WSService_Service类构造函数。
如何在下面的methodToTest()方法中模拟构造函数?
@Service
public class MyService {
public void methodToTest(){
WSService wsService_Service = new WSService_Service().getWSServicePort();
SomeObjectResponose = wsService_Service.someService(); // I want to verify if this method is called.
}
}
import javax.xml.ws.Service;
@WebServiceClient(name = "WSService", .....//some code ommitted)
public class WSService_Service extends Service{
static {
URL url = null;
try {
url = new URL("http://url.ommited");
} catch (MalformedURLException e) {
//code ommitted
}
WSDL_LOCATION = url;
}
public WSService() {
super(WSDL_LOCATION, SERVICE);
}
public WSService(URL wsdlLocation, WebServiceFeature ... features) {
super(wsdlLocation, SERVICE, features);
}
public WSService getWSServicePort() {
return super.getPort(WSServicePort, WSService.class);
}
//some codes ommited..
}