### Question:
TraceeServerHandler extends AbstractTraceeHandler { protected final void handleOutgoing(SOAPMessageContext context) { final SOAPMessage msg = context.getMessage(); try { if (msg != null && !traceeBackend.isEmpty() && traceeBackend.getConfiguration().shouldProcessContext(OutgoingResponse)) { final SOAPHeader header = getOrCreateHeader(msg); final Map<String, String> filteredContext = traceeBackend.getConfiguration().filterDeniedParams(traceeBackend.copyToMap(), OutgoingResponse); transportSerialization.renderSoapHeader(filteredContext, header); msg.saveChanges(); context.setMessage(msg); } } catch (final SOAPException e) { logger.error("TraceeServerHandler : Exception occurred during processing of outbound message."); logger.debug("Detailed: TraceeServerHandler : Exception occurred during processing of outbound message: {}", e.getMessage(), e); } finally { traceeBackend.clear(); } } TraceeServerHandler();  TraceeServerHandler(TraceeBackend traceeBackend, SoapHeaderTransport soapHeaderTransport); @Override boolean handleFault(SOAPMessageContext context);  }### Answer:
@Test public void testHandleOutgoing() throws SOAPException, JAXBException { backend.put("John", "Boy"); final SOAPHeader soapHeader = message.getSOAPHeader(); unit.handleOutgoing(messageContext); verify(soapHeaderTransport).renderSoapHeader(anyMapOf(String.class, String.class), eq(soapHeader)); }
@Test public void handleOutgoingIfBackendIsNotEmpty() throws SOAPException, JAXBException { backend.put("John", "Boy"); final SOAPHeader header = message.getSOAPHeader(); unit.handleOutgoing(messageContext); verify(soapHeaderTransport).renderSoapHeader(anyMapOf(String.class, String.class), eq(header)); }
@Test public void doNotHAndleOutgoingIfBackendIsEmpty() throws SOAPException, JAXBException { final SOAPHeader header = message.getSOAPHeader(); unit.handleOutgoing(messageContext); verify(soapHeaderTransport, never()).renderSoapHeader(anyMapOf(String.class, String.class), eq(header)); }
@Test public void catchExceptionIfOutgoingTpicHeaderIsNotRenderable() throws SOAPException { when(message.getSOAPHeader()).thenThrow(new SOAPException()); unit.handleOutgoing(messageContext); assertThat(backend.isEmpty(), is(true)); }
@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); unit.handleOutgoing(messageContext); verify(envelope).addHeader(); }
@Test public void testHandleOutgoingHasCalledClearInTheEnd() throws SOAPException { unit.handleOutgoing(messageContext); verify(backend).clear(); }