protected OAuth20AccessToken addAccessToken(final Principal principal,
                                                final OAuthRegisteredService registeredService,
                                                final String codeId) throws Throwable {
        val authentication = getAuthentication(principal);
        val service = serviceFactory.createService(registeredService.getServiceId());
        val accessToken = defaultAccessTokenFactory.create(service, authentication,
            new MockTicketGrantingTicket("casuser"),
            new ArrayList<>(), codeId, registeredService.getClientId(), new HashMap<>(),
            OAuth20ResponseTypes.CODE, OAuth20GrantTypes.AUTHORIZATION_CODE);
        this.ticketRegistry.addTicket(accessToken);
        return accessToken;
    }
This is {@link AbstractOAuth20Tests}.

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