### Question:
InterceptingMessageReceiver implements WebServiceMessageReceiver { public void receive(MessageContext messageContext) throws Exception { interceptingTemplate.interceptRequest(messageContext, wrappedMessageReceiver); } InterceptingMessageReceiver(WebServiceMessageReceiver wrappedMessageReceiver,ClientInterceptor[] interceptors); void receive(MessageContext messageContext);  }### Answer:
@Test public void testInterceptOne() throws Exception { MessageContext messageContext = new DefaultMessageContext(getMessageFactory()); IMocksControl control = createControl(); WebServiceMessageReceiver wrappedMessageReceiver = new WebServiceMessageReceiver(){ public void receive(MessageContext messageContext) throws Exception { messageContext.setResponse(getMessageFactory().createWebServiceMessage()); } }; ClientInterceptor interceptor1 = control.createMock(ClientInterceptor.class); ClientInterceptor[] interceptors = new ClientInterceptor[]{interceptor1}; expect(interceptor1.handleRequest(messageContext)).andReturn(true); expect(interceptor1.handleResponse(messageContext)).andReturn(true); wrappedMessageReceiver.receive(messageContext); control.replay(); InterceptingMessageReceiver receiver = new InterceptingMessageReceiver(wrappedMessageReceiver, interceptors); receiver.receive(messageContext); control.verify(); }
@Test public void testInterceptOneFault() throws Exception { MessageContext messageContext = new DefaultMessageContext(getMessageFactory()); IMocksControl control = createControl(); WebServiceMessageReceiver wrappedMessageReceiver = new WebServiceMessageReceiver(){ public void receive(MessageContext messageContext) throws Exception { SaajSoapMessage message = getMessageFactory().createWebServiceMessage(); message.getSoapBody().addServerOrReceiverFault("TestFault", Locale.ENGLISH); messageContext.setResponse(message); } }; ClientInterceptor interceptor1 = control.createMock(ClientInterceptor.class); ClientInterceptor[] interceptors = new ClientInterceptor[]{interceptor1}; expect(interceptor1.handleRequest(messageContext)).andReturn(true); expect(interceptor1.handleFault(messageContext)).andReturn(true); wrappedMessageReceiver.receive(messageContext); control.replay(); InterceptingMessageReceiver receiver = new InterceptingMessageReceiver(wrappedMessageReceiver, interceptors); receiver.receive(messageContext); control.verify(); }
@Test public void testInterceptTwo() throws Exception { MessageContext messageContext = new DefaultMessageContext(getMessageFactory()); IMocksControl control = createControl(); WebServiceMessageReceiver wrappedMessageReceiver = new WebServiceMessageReceiver(){ public void receive(MessageContext messageContext) throws Exception { messageContext.setResponse(getMessageFactory().createWebServiceMessage()); } }; ClientInterceptor interceptor1 = control.createMock(ClientInterceptor.class); ClientInterceptor interceptor2 = control.createMock(ClientInterceptor.class); ClientInterceptor[] interceptors = new ClientInterceptor[]{interceptor1, interceptor2}; expect(interceptor1.handleRequest(messageContext)).andReturn(true); expect(interceptor1.handleResponse(messageContext)).andReturn(true); expect(interceptor2.handleRequest(messageContext)).andReturn(true); expect(interceptor2.handleResponse(messageContext)).andReturn(true); wrappedMessageReceiver.receive(messageContext); control.replay(); InterceptingMessageReceiver receiver = new InterceptingMessageReceiver(wrappedMessageReceiver, interceptors); receiver.receive(messageContext); control.verify(); }
@Test public void testInterceptTwoInterrupt() throws Exception { MessageContext messageContext = new DefaultMessageContext(getMessageFactory()); IMocksControl control = createControl(); WebServiceMessageReceiver wrappedMessageReceiver = new WebServiceMessageReceiver(){ public void receive(MessageContext messageContext) throws Exception { messageContext.setResponse(getMessageFactory().createWebServiceMessage()); } }; ClientInterceptor interceptor1 = control.createMock(ClientInterceptor.class); ClientInterceptor interceptor2 = control.createMock(ClientInterceptor.class); ClientInterceptor[] interceptors = new ClientInterceptor[]{interceptor1, interceptor2}; expect(interceptor1.handleRequest(messageContext)).andReturn(false); expect(interceptor1.handleResponse(messageContext)).andReturn(true); wrappedMessageReceiver.receive(messageContext); control.replay(); InterceptingMessageReceiver receiver = new InterceptingMessageReceiver(wrappedMessageReceiver, interceptors); receiver.receive(messageContext); control.verify(); }