public static OAuth20AccessToken getAccessToken(final TicketGrantingTicket ticketGrantingTicket,
                                                       final String id,
                                                       final String serviceId, final String clientId) {
        val service = RegisteredServiceTestUtils.getService(serviceId);
        service.getAttributes().put(OAuth20Constants.CLIENT_ID, List.of(clientId));
        val accessToken = mock(OAuth20AccessToken.class);
        val ticketId = OAuth20AccessToken.PREFIX + "-%s".formatted(id);
        when(accessToken.getId()).thenReturn(ticketId);
        when(accessToken.getTicketGrantingTicket()).thenReturn(ticketGrantingTicket);
        when(accessToken.getAuthentication()).thenReturn(ticketGrantingTicket.getAuthentication());
        when(accessToken.getService()).thenReturn(service);
        when(accessToken.getClientId()).thenReturn(clientId);
        when(accessToken.getExpirationPolicy()).thenReturn(NeverExpiresExpirationPolicy.INSTANCE);
        when(accessToken.getCreationTime()).thenReturn(ZonedDateTime.now(Clock.systemUTC()));
        when(accessToken.toString()).thenReturn(ticketId);
        when(accessToken.getGrantType()).thenReturn(OAuth20GrantTypes.AUTHORIZATION_CODE);
        return accessToken;
    }
Gets access token.

@param ticketGrantingTicket the ticket granting ticket
@param id                   the id
@param serviceId            the service id
@param clientId             the client id
@return the access token
support/cas-server-support-oauth/src/test/java/org/apereo/cas/OAuth20TestUtils.java