### Question:
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();  }### Answer:
@Test public void testGetWhenDisabled() { final GoogleCredentialsAccessTokenSupplier supplier = new GoogleCredentialsAccessTokenSupplier(false, null, null); assertThat(supplier.get(), equalTo(Optional.<AccessToken>absent())); }
@Test public void testGetWithStaticToken() { final AccessToken token = new AccessToken("token", null); final GoogleCredentialsAccessTokenSupplier supplier = new GoogleCredentialsAccessTokenSupplier(true, token, null); assertThat(supplier.get(), equalTo(Optional.of(token))); }
@Test public void testGetWithCredentials() throws IOException { final GoogleCredentials credentials = mock(GoogleCredentials.class); final GoogleCredentialsAccessTokenSupplier supplier = new GoogleCredentialsAccessTokenSupplier( true, null, null, credentials); supplier.get(); verify(credentials).refreshIfExpired(); }