Use JMock . JMock allows you to check behavior, not state changes. To do this, you need to encapsulate the SOAPCOnnectionFactory.newInstance () method in another object:
public class MySOAPConnectionFactory { public SOAPConnectionFactory getConnection() { return SOAPConnectionFactory.newInstance(); }
Use the object of the new class in your code.
conn = mySOAPConnectionFactory.getConnection(); conn.call( message, endpoint );
Then in your test, replace the Mock object for Factory, which will return the Mock connection. Set expectations in Mock Connection, waiting for the call you are looking for.
final SOAPConnectionFactory mockConnection = mockery.mock(SOAPConnectionFactory.class); final SOAPConnection mockSoapConnection = mockery.mock(SOAPConnection.class); foo.setMySOAPConnectionFactory( mockConnectionFactory ); try { mockery.checking( new Expectations() { { atLeast( 1 ).of( mockConnectionFactory ).getConnection(); will( returnValue( mockSoapConnection ) ); atLeast( 1 ).of( mockConnection ).call(SOME_MESSAGE, ENDPOINT); } } );
source share