### Question:
MessageMatcher implements RequestMatcher, ResponseMatcher { protected final void matchInternal(WebServiceMessage input, WebServiceMessage message) { Source controlMessage = preprocessControlMessage(input); if (isSoapControl(controlMessage)) { Source messageSource = getEnvelopeSource(message); compare(controlMessage, messageSource); } else { Source messageSource = message.getPayloadSource(); compare(controlMessage, messageSource); } } MessageMatcher(Source controlMessage); void match(WebServiceMessage request, WebServiceMessage response); void match(URI uri, WebServiceMessage request); final Source getControlMessage();  }### Answer:
@Test public void testSame() { Source source = new StringSource(MESSAGE); MessageMatcher matcher = new MessageMatcher(source); SoapMessage request = createMock(SoapMessage.class); SoapEnvelope envelope = createMock(SoapEnvelope.class); expect(request.getEnvelope()).andReturn(envelope ); expect(envelope.getSource()).andReturn(new StringSource(MESSAGE)); replay(request, envelope); matcher.matchInternal(null, request); verify(request, envelope); }
@Test(expected=AssertionError.class) public void testDifferent() { Source source = new StringSource(MESSAGE); MessageMatcher matcher = new MessageMatcher(source); SoapMessage request = createMock(SoapMessage.class); SoapEnvelope envelope = createMock(SoapEnvelope.class); expect(request.getEnvelope()).andReturn(envelope ); expect(envelope.getSource()).andReturn(new StringSource(MESSAGE2)); replay(request, envelope); matcher.matchInternal(null, request); verify(request, envelope); }
@Test public void testPayload() { Source source = new StringSource(PAYLOAD); MessageMatcher matcher = new MessageMatcher(source); SoapMessage request = createMock(SoapMessage.class); expect(request.getPayloadSource()).andReturn(new StringSource(PAYLOAD)); replay(request); matcher.matchInternal(null, request); verify(request); }
@Test(expected=AssertionError.class) public void testPayloadDifferent() { Source source = new StringSource(PAYLOAD); MessageMatcher matcher = new MessageMatcher(source); SoapMessage request = createMock(SoapMessage.class); expect(request.getPayloadSource()).andReturn(new StringSource(PAYLOAD2)); replay(request); matcher.matchInternal(null, request); verify(request); }