@Test
public void quotaProjectIdHidingCredentials_getRequestMetadata() throws IOException {

  // Credentials with quota project id
  Map<String, List<String>> metaDataWithQuota =
      ImmutableMap.of(
          "k1",
          Collections.singletonList("v1"),
          QUOTA_PROJECT_ID_KEY,
          Collections.singletonList(QUOTA_PROJECT_ID_FROM_CREDENTIALS_VALUE));
  Credentials credentialsWithQuotaProjectId = Mockito.mock(GoogleCredentials.class);
  Mockito.when(credentialsWithQuotaProjectId.getRequestMetadata(null))
      .thenReturn(metaDataWithQuota);
  QuotaProjectIdHidingCredentials quotaProjectIdHidingCredentials =
      new QuotaProjectIdHidingCredentials(credentialsWithQuotaProjectId);
  Map<String, List<String>> metaDataHidingQuota =
      quotaProjectIdHidingCredentials.getRequestMetadata();
  Assert.assertTrue(metaDataWithQuota.containsKey(QUOTA_PROJECT_ID_KEY));
  Assert.assertFalse(metaDataHidingQuota.containsKey(QUOTA_PROJECT_ID_KEY));
  Assert.assertEquals(metaDataWithQuota.size() - 1, metaDataHidingQuota.size());
  // Credentials without quota project id
  Map<String, List<String>> metaDataWithoutQuota =
      ImmutableMap.of("k1", Collections.singletonList("v1"));
  Credentials credentialsWithoutQuotaProjectId = Mockito.mock(GoogleCredentials.class);
  Mockito.when(credentialsWithoutQuotaProjectId.getRequestMetadata(null))
      .thenReturn(metaDataWithoutQuota);
  QuotaProjectIdHidingCredentials quotaProjectIdHidingCredentialsWithout =
      new QuotaProjectIdHidingCredentials(credentialsWithoutQuotaProjectId);
  Map<String, List<String>> metaDataHidingQuotaWithout =
      quotaProjectIdHidingCredentials.getRequestMetadata();
  Assert.assertEquals(
      quotaProjectIdHidingCredentialsWithout.getRequestMetadata(), metaDataWithoutQuota);
}