HybridProvider extends AbstractProvider { @Override public AccessToken getAccessToken(String googleIdentity, List<String> scopes) { if (googleIdentity.endsWith(".iam.gserviceaccount.com")) { return serviceAccountProvider.getAccessToken(googleIdentity, scopes); } else { return userProvider.getAccessToken(googleIdentity, scopes); } } HybridProvider(); @Override AccessToken getAccessToken(String googleIdentity, List<String> scopes);  }
@Test public void testUser() { HybridProvider provider = new HybridProvider(); AccessToken accessToken = provider.getAccessToken("alice@example.com", SCOPES); assertEquals( "FakeAccessToken/GoogleIdentity=alice@example.com;Scopes=" + String.join(",", SCOPES), accessToken.getValue()); }
@Test public void testServiceAccount() { HybridProvider provider = new HybridProvider(); AccessToken accessToken = provider.getAccessToken("alice-shadow@" + projectId + ".iam.gserviceaccount.com", SCOPES); assertTrue(accessToken.getValue().startsWith("y")); assertEquals(2, CharMatcher.is('.').countIn(accessToken.getValue())); assertTrue(accessToken.getExpiresAt() > 0); }