@Test
public void authenticate_test() {

    //Given
    byte[] credentialId = new byte[32];
    GrantedAuthority grantedAuthority = new SimpleGrantedAuthority("ROLE_ADMIN");
    UserDetails webAuthnPrincipal = new TestUserDetailsImpl("dummy", Collections.singletonList(grantedAuthority));
    WebAuthnAuthenticator webAuthnAuthenticator = mock(WebAuthnAuthenticator.class, RETURNS_DEEP_STUBS);
    when(webAuthnAuthenticator.getUserPrincipal()).thenReturn(webAuthnPrincipal);
    when(webAuthnAuthenticator.getAttestedCredentialData().getCredentialId()).thenReturn(credentialId);
    //When
    WebAuthnAuthenticationRequest request = mock(WebAuthnAuthenticationRequest.class);
    WebAuthnAuthenticationParameters parameters = mock(WebAuthnAuthenticationParameters.class);
    when(request.getCredentialId()).thenReturn(credentialId);
    when(authenticatorService.loadAuthenticatorByCredentialId(credentialId)).thenReturn(webAuthnAuthenticator);
    Authentication token = new WebAuthnAssertionAuthenticationToken(request, parameters, null);
    Authentication authenticatedToken = authenticationProvider.authenticate(token);
    ArgumentCaptor<AuthenticationRequest> requestCaptor = ArgumentCaptor.forClass(AuthenticationRequest.class);
    ArgumentCaptor<AuthenticationParameters> parameterCaptor = ArgumentCaptor.forClass(AuthenticationParameters.class);
    verify(webAuthnManager).validate(requestCaptor.capture(), parameterCaptor.capture());
    assertThat(authenticatedToken.getPrincipal()).isEqualTo(webAuthnPrincipal);
    assertThat(authenticatedToken.getCredentials()).isEqualTo(request);
    assertThat(authenticatedToken.getAuthorities().toArray()).containsExactly(grantedAuthority);
}