### Question:
ContainerSecurityRequestFilter implements ContainerRequestFilter { @Override public void filter(final ContainerRequestContext requestContext) throws IOException { final MultivaluedMap<String, String> headers = requestContext.getHeaders(); final String userId = getValueForHeaderAndScheme(headers, HttpHeaders.AUTHORIZATION, CLICK_PLATFORM_SCHEME); final String teamId = getValueForHeaderAndScheme(headers, CLICK_PLATFORM_TEAM_ID_HEADER, CLICK_PLATFORM_SCHEME); final String agentUserId = getValueForHeaderAndScheme(headers, CLICK_PLATFORM_AGENT_AUTHORIZATION_HEADER, CLICK_PLATFORM_SCHEME); final String appId = getValueForHeader(headers, CLICK_PLATFORM_APP_ID_HEADER); SecurityContextHolder.set(new DefaultSecurityContext(userId, teamId, agentUserId, appId)); }  @Override void filter(final ContainerRequestContext requestContext);  }### Answer:
@Test public void shouldSetSecurityContextProperties_withHeaders() throws Exception { mockStatic(SecurityContextHolder.class); final String userId = randomId(); final String teamId = randomId(); final String agentUserId = randomId(); final String appId = randomId(); headers.add(HttpHeaders.AUTHORIZATION, CLICK_PLATFORM_SCHEME + " " + userId); headers.add(CLICK_PLATFORM_TEAM_ID_HEADER, CLICK_PLATFORM_SCHEME + " " + teamId); headers.add(CLICK_PLATFORM_AGENT_AUTHORIZATION_HEADER, CLICK_PLATFORM_SCHEME + " " + agentUserId); headers.add(CLICK_PLATFORM_APP_ID_HEADER, appId); final ContainerSecurityRequestFilter containerSecurityRequestFilter = new ContainerSecurityRequestFilter(); containerSecurityRequestFilter.filter(mockContainerRequestContext); final ArgumentCaptor<DefaultSecurityContext> securityContextCaptor = ArgumentCaptor .forClass(DefaultSecurityContext.class); verifyStatic(SecurityContextHolder.class); SecurityContextHolder.set(securityContextCaptor.capture()); assertEquals(Optional.of(userId), securityContextCaptor.getValue().userId()); assertEquals(Optional.of(teamId), securityContextCaptor.getValue().teamId()); assertEquals(Optional.of(agentUserId), securityContextCaptor.getValue().agentUserId()); assertEquals(Optional.of(appId), securityContextCaptor.getValue().appId()); }
@Test public void shouldSetSecurityContextProperties_withJustAppIdHeaders() throws Exception { mockStatic(SecurityContextHolder.class); final String appId = randomId(); headers.add(CLICK_PLATFORM_APP_ID_HEADER, appId); final ContainerSecurityRequestFilter containerSecurityRequestFilter = new ContainerSecurityRequestFilter(); containerSecurityRequestFilter.filter(mockContainerRequestContext); final ArgumentCaptor<DefaultSecurityContext> securityContextCaptor = ArgumentCaptor .forClass(DefaultSecurityContext.class); verifyStatic(SecurityContextHolder.class); SecurityContextHolder.set(securityContextCaptor.capture()); assertEquals(Optional.empty(), securityContextCaptor.getValue().userId()); assertEquals(Optional.empty(), securityContextCaptor.getValue().teamId()); assertEquals(Optional.empty(), securityContextCaptor.getValue().agentUserId()); assertEquals(Optional.of(appId), securityContextCaptor.getValue().appId()); }
@Test public void shouldSetEmptySecurityContextProperties_withNoHeaders() throws Exception { mockStatic(SecurityContextHolder.class); final ContainerSecurityRequestFilter containerSecurityRequestFilter = new ContainerSecurityRequestFilter(); containerSecurityRequestFilter.filter(mockContainerRequestContext); final ArgumentCaptor<DefaultSecurityContext> securityContextCaptor = ArgumentCaptor .forClass(DefaultSecurityContext.class); verifyStatic(SecurityContextHolder.class); SecurityContextHolder.set(securityContextCaptor.capture()); assertEquals(Optional.empty(), securityContextCaptor.getValue().userId()); assertEquals(Optional.empty(), securityContextCaptor.getValue().teamId()); assertEquals(Optional.empty(), securityContextCaptor.getValue().agentUserId()); assertEquals(Optional.empty(), securityContextCaptor.getValue().appId()); }