@Test
        void verifyExchangeTokens() throws Throwable {
            val registeredService = getRegisteredService(UUID.randomUUID().toString(), "secret",
                Set.of(OAuth20GrantTypes.TOKEN_EXCHANGE));
            servicesManager.save(registeredService);

            val accessToken = getAccessToken(registeredService.getServiceId(), registeredService.getClientId());
            ticketRegistry.addTicket(accessToken);

            val mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
            mockRequest.setParameter(OAuth20Constants.REQUESTED_TOKEN_TYPE, OAuth20TokenExchangeTypes.ACCESS_TOKEN.getType());
            mockRequest.setParameter(OAuth20Constants.SUBJECT_TOKEN, accessToken.getId());

            val mv = generateAccessTokenResponseAndGetModelAndView(registeredService,
                RegisteredServiceTestUtils.getAuthentication("casuser"),
                OAuth20GrantTypes.TOKEN_EXCHANGE, mockRequest);
            assertNotNull(mv);
            val id = mv.getModel().get(OAuth20Constants.ACCESS_TOKEN).toString();
            val at = ticketRegistry.getTicket(id, OAuth20AccessToken.class);
            assertNotNull(at);
            val attributes = at.getAuthentication().getPrincipal().getAttributes();
            assertTrue(attributes.containsKey("givenName"));
            assertTrue(attributes.containsKey("uid"));
            assertTrue(attributes.containsKey("username"));
            assertTrue(mv.getModel().containsKey(OAuth20Constants.EXPIRES_IN));
            assertTrue(mv.getModel().containsKey(OAuth20Constants.TOKEN_TYPE));
            assertTrue(mv.getModel().containsKey(OAuth20Constants.ISSUED_TOKEN_TYPE));
        }
This is {@link OAuth20DefaultTokenGeneratorTests}.

@author Misagh Moayyed
@since 6.1.0
support/cas-server-support-oauth/src/test/java/org/apereo/cas/support/oauth/web/response/accesstoken/OAuth20DefaultTokenGeneratorTests.java