title: Java - Mocking soap call with SOAPMessage request
body: <p>I am trying to mock a soap call which is returning null as response.</p>
  
  <p>I have a java class where I am making a call to fedex web services to get the parsed address validated. Till here everything is fine, but when it comes to unit testing the issue arises. 
  In test I am trying to mock the soap call by passing the same request parameters that is getting passed in actual java class but the mock is returning the response as null because of the request what I am passing is not same as what the soap call is expecting in java class.</p>
  
  <p>Java class code (abc.java)-</p>
  
  <pre><code>SOAPMessage payload = getAddressRequestPayload();
  SOAPMessage responseMessage = soapConnection.call(payload, settings.addressUrl());
  </code></pre>
  
  <p>Test code (junit4)-</p>
  
  <pre><code>SOAPMessage testResponse = getMockResponse();
  SOAPMessage testPayload =  abc.getAddressRequestPayload();
  
  when(mockSoapConnection.call(testPayload, settings.addressUrl())).thenReturn(testResponse);
  </code></pre>
  
  <p>Also I have tried getting the string xml request payload from java class and appending the new timestamp using fakeclock in test class to match both payloads but it seems to be different.
  One way is give generic soapmessage class in when call like -</p>
  
  <pre><code>when(mockSoapConnection.call(any(SOAPMessage.class), anyString())).thenReturn(testResponse)
  </code></pre>
  
  <p>Then the test is passing, but that is not the correct way of checking a specific call.So how do I get to know the differnce between the payloads or is there any other way to mock the soap call??</p>
  
  <p>Any help is appreciated.</p>
  
  <p>Saurabh</p>