OAuthorization implements Authorization { public AuthorizationToken authorize(MethodType methodType, String url, EncodedPair... parameters) throws Exception{ List<EncodedPair> oauthParams = oauth.oauth(this.accessOAuthToken, methodType, url, parameters); return new AuthorizationToken("OAuth", join(oauthParams, ',', '=', false, true)); } OAuthorization(OAuthToken accessOAuthToken, OAuthenticator oauth);  OAuthorization(OAuthToken accessOAuthToken, OAuthenticator oauth, OAuthApi oauthApi); AuthorizationToken authorize(MethodType methodType, String url, EncodedPair... parameters); void refresh();  }
@Test public void shouldGetAnAuthorizationTokenBasedOnOAuthenticatorResult() throws Exception { List<EncodedPair> pairs = asList( toPreEncodedPair("a","a%20val"), toPreEncodedPair("b","b%20val") ); when(mockOAuthenticator.oauth(any(OAuthToken.class), any(MethodType.class), anyString(), any(EncodedPair[].class))).thenReturn(pairs); MethodType argMethodType = GET; String argUrl = "url"; EncodedPair argPair = toPreEncodedPair("c","c%20val"); AuthorizationToken actual = toTest.authorize(argMethodType, argUrl, argPair); assertNotNull(actual); assertEquals("OAuth", actual.getName()); assertEquals("a=\"a%20val\",b=\"b%20val\"", actual.getValue()); verify(mockOAuthenticator).oauth(mockToken, argMethodType, argUrl, argPair); }