### Question:
X509AuthenticationProvider implements AuthenticationProvider { @Override public Authentication authenticate(Authentication authentication) { if (authentication instanceof X509AuthenticationToken) { if (!isClientCertEnabled) { return null; } String username = getUserid(authentication); if (username == null) { return null; } String jwtToken = tokenCreationService.createJwtTokenWithoutCredentials(username); Authentication tokenAuthentication = new TokenAuthentication(username, jwtToken); tokenAuthentication.setAuthenticated(true); return tokenAuthentication; } else { throw new AuthenticationTokenException("Wrong authentication token. " + authentication.getClass()); } }  @Override Authentication authenticate(Authentication authentication); @Override boolean supports(Class<?> authentication);  }### Answer:
@Test void givenX509AuthIsDisabled_whenRequested_thenNullIsReturned() { x509AuthenticationProvider.isClientCertEnabled = false; assertNull(x509AuthenticationProvider.authenticate(new X509AuthenticationToken(x509Certificate))); }
@Test void givenCertificateIsntMappedToUser_whenAuthenticationIsRequired_thenNullIsReturned() { when(x509AuthenticationMapper.mapCertificateToMainframeUserId(x509Certificate[0])).thenReturn(null); Authentication result = x509AuthenticationProvider.authenticate(new X509AuthenticationToken(x509Certificate)); assertThat(result, is(nullValue())); }
@Test void givenZosmfIsPresent_whenValidCertificateAndPassTicketGenerate_returnZosmfJwtToken() { String validUsername = "validUsername"; when(x509AuthenticationMapper.mapCertificateToMainframeUserId(x509Certificate[0])).thenReturn(validUsername); when(tokenCreationService.createJwtTokenWithoutCredentials(validUsername)).thenReturn("validJwtToken"); Authentication result = x509AuthenticationProvider.authenticate(new X509AuthenticationToken(x509Certificate)); assertThat(result.isAuthenticated(), is(true)); }