### Question:
OutboundProviderSync extends SynchronousProvider implements OutboundSecurityProvider { @Override protected OutboundSecurityResponse syncOutbound(ProviderRequest providerRequest, SecurityEnvironment outboundEnv, EndpointConfig outboundEndpointConfig) { return providerRequest.securityContext() .user() .map(Subject::principal) .map(Principal::getName) .map(name -> OutboundSecurityResponse .withHeaders(Map.of("X-AUTH-USER", List.of(name)))) .orElse(OutboundSecurityResponse.abstain()); }    }### Answer:
@Test public void testAbstain() { SecurityContext context = mock(SecurityContext.class); when(context.user()).thenReturn(Optional.empty()); when(context.service()).thenReturn(Optional.empty()); SecurityEnvironment se = SecurityEnvironment.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.securityContext()).thenReturn(context); when(request.env()).thenReturn(se); OutboundProviderSync ops = new OutboundProviderSync(); OutboundSecurityResponse response = ops.syncOutbound(request, SecurityEnvironment.create(), EndpointConfig.create()); assertThat(response.status(), is(SecurityResponse.SecurityStatus.ABSTAIN)); }
@Test public void testSuccess() { String username = "aUser"; Subject subject = Subject.create(Principal.create(username)); SecurityContext context = mock(SecurityContext.class); when(context.user()).thenReturn(Optional.of(subject)); when(context.service()).thenReturn(Optional.empty()); SecurityEnvironment se = SecurityEnvironment.create(); ProviderRequest request = mock(ProviderRequest.class); when(request.securityContext()).thenReturn(context); when(request.env()).thenReturn(se); OutboundProviderSync ops = new OutboundProviderSync(); OutboundSecurityResponse response = ops.syncOutbound(request, SecurityEnvironment.create(), EndpointConfig.create()); assertThat(response.status(), is(SecurityResponse.SecurityStatus.SUCCESS)); assertThat(response.requestHeaders().get("X-AUTH-USER"), is(List.of(username))); }