@Test(expected = InvalidGrantException.class)
 public void testUnauthenticated() {
   validUser = new UsernamePasswordAuthenticationToken("foo", "bar");
   ResourceOwnerPasswordTokenGranter granter =
       new ResourceOwnerPasswordTokenGranter(
           authenticationManager, providerTokenServices,
           clientDetailsService, requestFactory);
   granter.grant("password", tokenRequest);
 }
 @Test(expected = InvalidClientException.class)
 public void testGrantTypeNotSupported() {
   ResourceOwnerPasswordTokenGranter granter =
       new ResourceOwnerPasswordTokenGranter(
           authenticationManager, providerTokenServices,
           clientDetailsService, requestFactory);
   client.setAuthorizedGrantTypes(Collections.singleton("client_credentials"));
   granter.grant("password", tokenRequest);
 }
 @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());
 }
 @Test(expected = InvalidGrantException.class)
 public void testAccountLocked() {
   ResourceOwnerPasswordTokenGranter granter =
       new ResourceOwnerPasswordTokenGranter(
           new AuthenticationManager() {
             public Authentication authenticate(Authentication authentication)
                 throws AuthenticationException {
               throw new LockedException("test");
             }
           },
           providerTokenServices,
           clientDetailsService,
           requestFactory);
   granter.grant("password", tokenRequest);
 }