MockTokenServerTransport transport = new MockTokenServerTransport();
transport.addServiceAccount(serviceAccountEmail, accessToken);
// Write out user file
GenericJson serviceAccountContents = new GenericJson();
serviceAccountContents.setFactory(JSON_FACTORY);
serviceAccountContents.put("client_id", serviceAccountId);
serviceAccountContents.put("client_email", serviceAccountEmail);
serviceAccountContents.put("private_key", SA_KEY_TEXT);
serviceAccountContents.put("private_key_id", SA_KEY_ID);
serviceAccountContents.put("type", GoogleCredential.SERVICE_ACCOUNT_FILE_TYPE);
String json = serviceAccountContents.toPrettyString();
InputStream serviceAccountStream = new ByteArrayInputStream(json.getBytes());
GoogleCredential defaultCredential = GoogleCredential
.fromStream(serviceAccountStream, transport, JSON_FACTORY);
assertNotNull(defaultCredential);