### Question:
TraceeClientHandler extends AbstractTraceeHandler { protected final void handleOutgoing(final SOAPMessageContext context) { final SOAPMessage msg = context.getMessage(); if (msg != null && !traceeBackend.isEmpty() && traceeBackend.getConfiguration().shouldProcessContext(IncomingResponse)) { try { final SOAPHeader header = getOrCreateHeader(msg); final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(traceeBackend.copyToMap(), IncomingResponse); transportSerialization.renderSoapHeader(filteredContext, header); msg.saveChanges(); } catch (final SOAPException e) { logger.warn("TraceeClientHandler : Exception occurred during processing of outbound message.", e); } } } TraceeClientHandler();  TraceeClientHandler(TraceeBackend traceeBackend); @Override final boolean handleFault(final SOAPMessageContext context);  }### Answer:
@Test public void addSoapHeaderIfNooneIsOnMessage() throws SOAPException { backend.put("abcd", "12"); when(message.getSOAPHeader()).thenReturn(null); when(message.getSOAPPart()).thenReturn(mock(SOAPPart.class)); final SOAPEnvelope envelope = mock(SOAPEnvelope.class); when(message.getSOAPPart().getEnvelope()).thenReturn(envelope); when(message.getSOAPPart().getEnvelope().addHeader()).thenReturn(mock(SOAPHeader.class, Mockito.RETURNS_DEEP_STUBS)); unit.handleOutgoing(messageContext); verify(envelope).addHeader(); }
@Test public void renderBackendToSoapHeader() throws SOAPException { backend.put("my header", "Wow!"); unit.handleOutgoing(messageContext); final NodeList tpicElements = message.getSOAPHeader().getElementsByTagNameNS(TraceeConstants.SOAP_HEADER_NAMESPACE, TraceeConstants.TPIC_HEADER); assertThat(tpicElements.getLength(), is(1)); final Node tpicEntry = tpicElements.item(0).getChildNodes().item(0); assertThat(tpicEntry.getLocalName(), is("entry")); assertThat(tpicEntry.getAttributes().getNamedItem("key").getNodeValue(), is("my header")); assertThat(tpicEntry.getChildNodes().item(0).getNodeValue(), is("Wow!")); }
@Test public void skipProcessingIfBackendIsEmpty() throws SOAPException { unit.handleOutgoing(messageContext); verify(message, never()).getSOAPHeader(); }