@Test public void testGetAuthorizationHeader_oAuth2NoRefresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(false); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper, times(0)).refreshCredential(credential); }
public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } }
AuthorizationHeaderProvider { public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } } }
AuthorizationHeaderProvider { public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } } @Inject  AuthorizationHeaderProvider(
      OAuth2AuthorizationHeaderProvider oAuth2AuthorizationHeaderProvider,
      AdsLibConfiguration adsLibConfiguration,
      OAuth2Helper oAuth2Helper); }
AuthorizationHeaderProvider { public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } } @Inject  AuthorizationHeaderProvider(
      OAuth2AuthorizationHeaderProvider oAuth2AuthorizationHeaderProvider,
      AdsLibConfiguration adsLibConfiguration,
      OAuth2Helper oAuth2Helper); String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl); }
AuthorizationHeaderProvider { public String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl) throws AuthenticationException { if (adsSession instanceof OAuth2Compatible && ((OAuth2Compatible) adsSession).getOAuth2Credential() != null) { return getOAuth2Header((OAuth2Compatible) adsSession); } else { throw new IllegalArgumentException( "Session does not have any valid authentication mechanisms"); } } @Inject  AuthorizationHeaderProvider(
      OAuth2AuthorizationHeaderProvider oAuth2AuthorizationHeaderProvider,
      AdsLibConfiguration adsLibConfiguration,
      OAuth2Helper oAuth2Helper); String getAuthorizationHeader(AdsSession adsSession, @Nullable String endpointUrl);  }