@Test
    void verifyStartRegistration() throws Throwable {
        val server = mock(WebAuthnServer.class);
        val controller = new WebAuthnController(server);

        val publicKeyCredential = PublicKeyCredentialCreationOptions.builder()
            .rp(new RelyingPartyIdentity.RelyingPartyIdentityBuilder.MandatoryStages()
                .id(RandomUtils.randomAlphabetic(8))
                .name(RandomUtils.randomAlphabetic(8))
                .build())
            .user(new UserIdentity.UserIdentityBuilder.MandatoryStages()
                .name(RandomUtils.randomAlphabetic(8))
                .displayName(RandomUtils.randomAlphabetic(8))
                .id(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)))
                .build())
            .challenge(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)))
            .pubKeyCredParams(List.of())
            .build();
        val registrationRequest = new RegistrationRequest("casuser", Optional.empty(),
            ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8)),
            publicKeyCredential,
            Optional.of(ByteArray.fromBase64Url(RandomUtils.randomAlphabetic(8))));
        when(server.startRegistration(anyString(), any(), any(), any(ResidentKeyRequirement.class), any()))
            .thenReturn(Either.right(registrationRequest));

        val request = new MockHttpServletRequest();
        val response = new MockHttpServletResponse();

        val authenticatedPrincipal = new TestingAuthenticationToken("casuser", List.of());
        var result = controller.startRegistration("displayName",
            "nickName", false, "sessionToken",
            authenticatedPrincipal, request, response);
        assertEquals(HttpStatus.OK, result.getStatusCode());

        when(server.startRegistration(anyString(), any(), any(), any(ResidentKeyRequirement.class), any())).thenReturn(Either.left("failed"));
        result = controller.startRegistration("displayName", "nickName", false,
            "sessionToken", authenticatedPrincipal, request, response);
        assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
    }
This is {@link WebAuthnControllerTests}.

@author Misagh Moayyed
@since 6.3.0
support/cas-server-support-webauthn-core/src/test/java/org/apereo/cas/webauthn/WebAuthnControllerTests.java