### Question:
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);  }### Answer:
@Test public void testGetAuthorizationHeader_oAuth2Refresh() throws Exception { final Credential credential = new Credential(BearerToken.authorizationHeaderAccessMethod()); OAuth2Session adsSession = () -> credential; when(oAuth2AuthorizationHeaderProvider.getOAuth2AuthorizationHeader( (OAuth2Compatible) adsSession)).thenReturn("OAuth2 Header"); when(adsLibConfiguration.isAutoRefreshOAuth2TokenEnabled()).thenReturn(true); assertEquals("OAuth2 Header", authorizationHeaderProvider.getAuthorizationHeader(adsSession, ENDPOINT_URL.toString())); verify(oAuth2Helper).refreshCredential(credential); }
@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); }