在编写创建soapClient的方法的单元测试时,我无法模拟局部变量

时间:2017-02-06 12:26:09

标签: java unit-testing soap soap-client spock

以下是我的代码......

HashMap<String, String> createSoapClient(JObject jObject, String requestId, String Id){
String url = environmentConfig.getSoapEndPoint();
try {
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
}...

我想模拟soapConnectionFactory和soapConnection对象但是失败了。我希望这个问题是由SOAPConnectionFactory.newInstance()单例方法引起的,但我无法改变它。 这是我尝试过的:

given:
environmentConfig.getSoapEndPoint() >> "https://endpointName"
when:
HashMap<String, String> map = service.createSoapClient(obj, "request-id", "abc")
then:
assert map != null

0 个答案:

没有答案