title: Unit test for spring ws-client - check if marshalSendAndReceive is being invoked
body: <p>my goal is writing a unit test for my <code>WebServiceClientImpl</code> class and I want to add a test that checks if <code>marshalSendAndReceive</code> is being invoked. I use <code>Mockito</code> and <code>powermockito</code> framework. I need to use <code>powermockito</code> because <code>WebServiceGatewaySupport.getWebServiceTemplate</code> is a final method, which <code>mockito</code> cant do. </p>
  
  <p>This is the class that I want to test.</p>
  
  <pre><code>public class WebServiceClientImpl extends WebServiceGatewaySupport implements
  WebServiceClient {
  
  @Override
  public &lt;T&gt; T execute(final Object requestPayload,
                     final Class&lt;T&gt; responseType,
                     final String soapActionCallBack) {
  return (T) getWebServiceTemplate()
               .marshalSendAndReceive(requestPayload, new 
                                      SoapActionCallback(soapActionCallBack));
  }
  </code></pre>
  
  <p>This is my unit test so far.</p>
  
  <pre><code>RunWith( PowerMockRunner.class )
  @PowerMockRunnerDelegate( HierarchicalContextRunner.class )
  @PrepareForTest( WebServiceClientImpl.class )
  public class WebServiceClientImplTest {
  
  private WebServiceClientImpl webServiceClientImpl = PowerMockito.mock(WebServiceClientImpl.class);
  
  @Mock
  private WebServiceTemplate webServiceTemplate;
  
  @Before
  public void before() {
    MockitoAnnotations.initMocks( this );
  }
  
  public class Execute {
    Object response = "response";
    Object request = "request";
    SoapActionCallback soapActionCallBack = new SoapActionCallback("soap");
  
    @Before
    public void before() {
  
    when( webServiceClientImpl.getWebServiceTemplate() ).thenReturn( webServiceTemplate );
    when( webServiceTemplate.marshalSendAndReceive ( request, soapActionCallBack) ).thenReturn(response);
    response = webServiceClientImpl.execute( request, Object.class, "soapActionCallBack" );
    System.out.println ("RESPONSE " + response );
  }
  
  
  @Test
  public void marshalSendAndReceiveInvoked() {
    verify( webServiceTemplate ).marshalSendAndReceive( request, soapActionCallBack );
  }
  
  @Test
  public void webServiceClientReturnValue() {
    assertEquals( "response", response );
  }}}
  </code></pre>
  
  <p>However the response is still null, even though I have put this in the unit test. </p>
  
  <p><code>when( webServiceTemplate.marshalSendAndReceive ( request, soapActionCallBack) ).thenReturn(response)</code></p>
  
  <p>Can anyone helps with the unit test? Any help will be appreciated - Thank you!</p>