I have a Service class(MyService) that instantiates a WebserviceClient class(WSService_Service) using constructor.
I tried mocking it using
PowerMockito.whenNew(WSService_Service.class).withNoArguments().thenReturn(wSService);
But it wont work, It would still go through the WSService_Service class constructor which calls a super method of a WebserviceClient.
How do I mock the constructor in methodToTest() method below?
@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..
}