OAuthorization implements Authorization { public void refresh() throws Exception{ State.notNull(oauthApi, "AccessToken refresh impossible, you must specify the oauth_session_handle and refresh access token url, see CRestBuilder."); this.accessOAuthToken = oauthApi.refreshAccessToken(this.accessOAuthToken); } 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 shouldRefreshInnerAccessTokenUsingOAuthApiResult() throws Exception { OAuthToken refreshedToken = mock(OAuthToken.class); when(mockOAuthApi.refreshAccessToken(any(OAuthToken.class))).thenReturn(refreshedToken); toTest.refresh(); verify(mockOAuthApi).refreshAccessToken(mockToken); toTest.refresh(); verify(mockOAuthApi).refreshAccessToken(refreshedToken); }
@Test(expected = IllegalStateException.class) public void shouldThrowAnIllegalStateExceptionWhenTryingToRefreshTokenIfNoOAuthApiHasBeenPassed() throws Exception { OAuthorization toTest = new OAuthorization(mockToken, mockOAuthenticator); toTest.refresh(); }