@Test
  public void testAuthorizationCodeGrant() {

    Authentication userAuthentication =
        new UsernamePasswordAuthenticationToken(
            "marissa", "koala", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));

    parameters.clear();
    parameters.put(OAuth2Utils.CLIENT_ID, "foo");
    parameters.put(OAuth2Utils.SCOPE, "scope");
    OAuth2Request storedOAuth2Request =
        RequestTokenFactory.createOAuth2Request(
            parameters, "foo", null, true, Collections.singleton("scope"), null, null, null);

    String code =
        authorizationCodeServices.createAuthorizationCode(
            new OAuth2Authentication(storedOAuth2Request, userAuthentication));
    parameters.putAll(storedOAuth2Request.getRequestParameters());
    parameters.put("code", code);

    TokenRequest tokenRequest = requestFactory.createTokenRequest(parameters);

    AuthorizationCodeTokenGranter granter =
        new AuthorizationCodeTokenGranter(
            providerTokenServices, authorizationCodeServices, clientDetailsService, requestFactory);
    OAuth2AccessToken token = granter.grant("authorization_code", tokenRequest);
    assertTrue(providerTokenServices.loadAuthentication(token.getValue()).isAuthenticated());
  }
 @Test
 public void testSunnyDay() {
   ResourceOwnerPasswordTokenGranter granter =
       new ResourceOwnerPasswordTokenGranter(
           authenticationManager, providerTokenServices,
           clientDetailsService, requestFactory);
   OAuth2AccessToken token = granter.grant("password", tokenRequest);
   OAuth2Authentication authentication =
       providerTokenServices.loadAuthentication(token.getValue());
   assertTrue(authentication.isAuthenticated());
 }