protected OAuth20Code addCodeWithChallenge(final Principal principal, final OAuthRegisteredService registeredService,
                                               final String codeChallenge, final String codeChallengeMethod,
                                               final Collection<String> scopes) throws Throwable {
        val authentication = getAuthentication(principal);
        val service = serviceFactory.createService(registeredService.getClientId());

        val tgt = new MockTicketGrantingTicket("casuser");
        ticketRegistry.addTicket(tgt);

        val code = oAuthCodeFactory.create(service, authentication,
            tgt, scopes, codeChallenge, codeChallengeMethod, registeredService.getClientId(), new HashMap<>(),
            OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
        ticketRegistry.addTicket(code);
        return code;
    }
This is {@link AbstractOAuth20Tests}.

@author Misagh Moayyed
@since 5.0.0
support/cas-server-support-oauth/src/test/java/org/apereo/cas/AbstractOAuth20Tests.java