@Test public void testGetWhenDisabled() { final GoogleCredentialsAccessTokenSupplier supplier = new GoogleCredentialsAccessTokenSupplier(false, null, null); assertThat(supplier.get(), equalTo(Optional.<AccessToken>absent())); }
@Override public Optional<AccessToken> get() { Optional<AccessToken> tokenOpt = Optional.absent(); if (enabled) { if (staticToken != null) { tokenOpt = Optional.of(staticToken); } else { try { synchronized (lock) { if (credentials == null) { credentials = getCredentialsWithScopes(tokenScopes); } credentials.refreshIfExpired(); } tokenOpt = Optional.of(credentials.getAccessToken()); } catch (IOException | RuntimeException e) { LOG.debug("Exception (possibly benign) while loading Google Credentials", e); return Optional.absent(); } } } return tokenOpt; }
GoogleCredentialsAccessTokenSupplier implements Supplier<Optional<AccessToken>> { @Override public Optional<AccessToken> get() { Optional<AccessToken> tokenOpt = Optional.absent(); if (enabled) { if (staticToken != null) { tokenOpt = Optional.of(staticToken); } else { try { synchronized (lock) { if (credentials == null) { credentials = getCredentialsWithScopes(tokenScopes); } credentials.refreshIfExpired(); } tokenOpt = Optional.of(credentials.getAccessToken()); } catch (IOException | RuntimeException e) { LOG.debug("Exception (possibly benign) while loading Google Credentials", e); return Optional.absent(); } } } return tokenOpt; } }
GoogleCredentialsAccessTokenSupplier implements Supplier<Optional<AccessToken>> { @Override public Optional<AccessToken> get() { Optional<AccessToken> tokenOpt = Optional.absent(); if (enabled) { if (staticToken != null) { tokenOpt = Optional.of(staticToken); } else { try { synchronized (lock) { if (credentials == null) { credentials = getCredentialsWithScopes(tokenScopes); } credentials.refreshIfExpired(); } tokenOpt = Optional.of(credentials.getAccessToken()); } catch (IOException | RuntimeException e) { LOG.debug("Exception (possibly benign) while loading Google Credentials", e); return Optional.absent(); } } } return tokenOpt; } GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes); @VisibleForTesting  GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes,
                                       final GoogleCredentials credentials); }
GoogleCredentialsAccessTokenSupplier implements Supplier<Optional<AccessToken>> { @Override public Optional<AccessToken> get() { Optional<AccessToken> tokenOpt = Optional.absent(); if (enabled) { if (staticToken != null) { tokenOpt = Optional.of(staticToken); } else { try { synchronized (lock) { if (credentials == null) { credentials = getCredentialsWithScopes(tokenScopes); } credentials.refreshIfExpired(); } tokenOpt = Optional.of(credentials.getAccessToken()); } catch (IOException | RuntimeException e) { LOG.debug("Exception (possibly benign) while loading Google Credentials", e); return Optional.absent(); } } } return tokenOpt; } GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes); @VisibleForTesting  GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes,
                                       final GoogleCredentials credentials); @Override Optional<AccessToken> get(); }
GoogleCredentialsAccessTokenSupplier implements Supplier<Optional<AccessToken>> { @Override public Optional<AccessToken> get() { Optional<AccessToken> tokenOpt = Optional.absent(); if (enabled) { if (staticToken != null) { tokenOpt = Optional.of(staticToken); } else { try { synchronized (lock) { if (credentials == null) { credentials = getCredentialsWithScopes(tokenScopes); } credentials.refreshIfExpired(); } tokenOpt = Optional.of(credentials.getAccessToken()); } catch (IOException | RuntimeException e) { LOG.debug("Exception (possibly benign) while loading Google Credentials", e); return Optional.absent(); } } } return tokenOpt; } GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes); @VisibleForTesting  GoogleCredentialsAccessTokenSupplier(final boolean enabled,
                                       final AccessToken staticToken,
                                       final List<String> tokenScopes,
                                       final GoogleCredentials credentials); @Override Optional<AccessToken> get();  }