AppIdentityCredential.Builder builder = new AppIdentityCredential.Builder(emptyScopes);
builder.setAppIdentityService(appIdentity);
AppIdentityCredential appCredential = builder.build();
GoogleCredential wrapper = new
AppIdentityCredential.AppEngineCredentialWrapper(appCredential, transport, jsonFactory);
HttpRequest request = transport.createRequestFactory().buildRequest("get", null, null);
assertTrue(wrapper.createScopedRequired());
try {
wrapper.intercept(request);
fail("Should not be able to use credential without scopes.");
} catch (Exception expected) {
}
assertEquals(appIdentity.getGetAccessTokenCallCount(), 1);
GoogleCredential scopedWrapper = wrapper.createScoped(SCOPES);
assertNotSame(wrapper, scopedWrapper);
scopedWrapper.intercept(request);
assertEquals(appIdentity.getGetAccessTokenCallCount(), 2);
HttpHeaders headers = request.getHeaders();
String authHeader = headers.getAuthorization();
assertTrue(authHeader.contains(expectedAccessToken));