### Question:
TraceeServletRequestListener implements ServletRequestListener { @Override public void requestInitialized(final ServletRequestEvent sre) { final ServletRequest servletRequest = sre.getServletRequest(); if (servletRequest instanceof HttpServletRequest) { httpRequestInitialized((HttpServletRequest) servletRequest); } } protected  TraceeServletRequestListener(TraceeBackend backend, HttpHeaderTransport transportSerialization);  TraceeServletRequestListener(); @Override void requestDestroyed(final ServletRequestEvent sre); @Override void requestInitialized(final ServletRequestEvent sre);  }### Answer:
@Test public void testGeneratesInvocationId() throws Exception { when(configuration.shouldGenerateInvocationId()).thenReturn(true); final Collection<String> emptyList = Collections.emptyList(); when(httpServletRequest.getHeaders(TraceeConstants.TPIC_HEADER)).thenReturn(enumeration(emptyList)); unit.requestInitialized(wrapToEvent(httpServletRequest)); verify(backend, atLeastOnce()).put(eq(TraceeConstants.INVOCATION_ID_KEY), anyString()); }
@Test public void testDoesNotGeneratesInvocationId() throws Exception { when(configuration.shouldGenerateInvocationId()).thenReturn(false); final Collection<String> emptyList = Collections.emptyList(); when(httpServletRequest.getHeaders(TraceeConstants.TPIC_HEADER)).thenReturn(enumeration(emptyList)); unit.requestInitialized(wrapToEvent(httpServletRequest)); verify(backend, never()).put(eq(TraceeConstants.INVOCATION_ID_KEY), anyString()); }
@Test public void testAcceptIncomingInvocationId() throws Exception { when(configuration.shouldGenerateInvocationId()).thenReturn(false); when(configuration.shouldProcessContext(IncomingRequest)).thenReturn(true); when(configuration.filterDeniedParams(anyMapOf(String.class, String.class), any(TraceeFilterConfiguration.Channel.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return invocation.getArguments()[0]; } }); when(httpServletRequest.getHeaders(TraceeConstants.TPIC_HEADER)).thenReturn(enumeration( singletonList(INVOCATION_ID_KEY + "=123"))); unit.requestInitialized(wrapToEvent(httpServletRequest)); verify(backend, atLeastOnce()).putAll(Mockito.eq(new HashMap<String, String>() {{ put(INVOCATION_ID_KEY, "123"); }})); }
@Test public void testGenerateSessionId() throws Exception { when(configuration.shouldGenerateSessionId()).thenReturn(true); final HttpSession session = Mockito.mock(HttpSession.class); when(httpServletRequest.getSession(any(Boolean.class))).thenReturn(session); when(session.getId()).thenReturn("A_RANDOM_SESSION_ID"); unit.requestInitialized(wrapToEvent(httpServletRequest)); verify(backend, atLeastOnce()).put(eq(SESSION_ID_KEY), anyString()); }