### Question:
AuthenticationSchemeFactory { public AuthenticationCommand getAuthenticationCommand(Authentication authentication) { final AbstractAuthenticationScheme scheme; if ((authentication == null) || (authentication.getScheme() == null)) { scheme = defaultScheme; } else { scheme = getSchema(authentication.getScheme()); } final HttpServletRequest request = RequestContext.getCurrentContext().getRequest(); final QueryResponse jwtQr = authenticationService.getJwtTokenFromRequest(request) .map(x -> authenticationService.parseJwtToken(x)) .orElse(null); return scheme.createCommand(authentication, () -> jwtQr); } AuthenticationSchemeFactory(@Autowired AuthenticationService authenticationService, @Autowired List<AbstractAuthenticationScheme> schemes); AbstractAuthenticationScheme getSchema(AuthenticationScheme scheme); AuthenticationCommand getAuthenticationCommand(Authentication authentication);  }### Answer:
@Test void testGetAuthenticationCommand() { final AbstractAuthenticationScheme byPass = spy(createScheme(AuthenticationScheme.BYPASS, true)); final AbstractAuthenticationScheme passTicket = spy(createScheme(AuthenticationScheme.HTTP_BASIC_PASSTICKET, false)); AuthenticationService as = mock(AuthenticationService.class); AuthenticationSchemeFactory asf = new AuthenticationSchemeFactory(as, Arrays.asList(byPass, passTicket)); Authentication authentication = new Authentication(AuthenticationScheme.BYPASS, "applid1"); HttpServletRequest request = mock(HttpServletRequest.class); RequestContext requestContext = new RequestContext(); requestContext.setRequest(request); QueryResponse qr = new QueryResponse("domain", "userId", new Date(), new Date(), QueryResponse.Source.ZOWE); when(as.getJwtTokenFromRequest(request)).thenReturn(Optional.of("jwtToken123")); when(as.getJwtTokenFromRequest(null)).thenReturn(Optional.empty()); when(as.parseJwtToken("jwtToken123")).thenReturn(qr); verify(byPass, times(0)).createCommand(eq(authentication), argThat(x -> x.get() == null)); verify(passTicket, times(0)).createCommand(eq(authentication), argThat(x -> x.get() == null)); asf.getAuthenticationCommand(authentication); verify(byPass, times(1)).createCommand(eq(authentication), argThat(x -> x.get() == null)); verify(passTicket, times(0)).createCommand(eq(authentication), argThat(x -> x.get() == null)); authentication.setScheme(AuthenticationScheme.HTTP_BASIC_PASSTICKET); asf.getAuthenticationCommand(authentication); verify(byPass, times(1)).createCommand(eq(authentication), argThat(x -> x.get() == null)); verify(passTicket, times(1)).createCommand(eq(authentication), argThat(x -> x.get() == null)); authentication.setScheme(null); asf.getAuthenticationCommand(authentication); verify(byPass, times(2)).createCommand(eq(authentication), argThat(x -> x.get() == null)); verify(passTicket, times(1)).createCommand(eq(authentication), argThat(x -> x.get() == null)); asf.getAuthenticationCommand(null); verify(byPass, times(2)).createCommand(eq(authentication), argThat(x -> x.get() == null)); verify(byPass, times(1)).createCommand(eq(null), argThat(x -> x.get() == null)); verify(passTicket, times(1)).createCommand(eq(authentication), argThat(x -> x.get() == null)); RequestContext.testSetCurrentContext(requestContext); verify(byPass, times(0)).createCommand(eq(authentication), argThat(x -> Objects.equals(qr, x.get()))); verify(passTicket, times(0)).createCommand(eq(authentication), argThat(x -> Objects.equals(qr, x.get()))); authentication.setScheme(AuthenticationScheme.HTTP_BASIC_PASSTICKET); asf.getAuthenticationCommand(authentication); verify(byPass, times(0)).createCommand(eq(authentication), argThat(x -> Objects.equals(qr, x.get()))); verify(passTicket, times(1)).createCommand(eq(authentication), argThat(x -> Objects.equals(qr, x.get()))); }