@Test
public void testBuilderFromSettings_QuotaProjectId() {

  CredentialsProvider credentialsProvider_no_quota = Mockito.mock(CredentialsProvider.class);
  HeaderProvider headerProvider_no_quota = Mockito.mock(HeaderProvider.class);
  HeaderProvider internalHeaderProvider_no_quota = Mockito.mock(HeaderProvider.class);
  HeaderProvider headerProvider_with_quota =
      new HeaderProvider() {
        @Override
        public Map<String, String> getHeaders() {
          return Collections.singletonMap(
              QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE);
        }
      };
  HeaderProvider internalHeaderProvider_with_quota =
      new HeaderProvider() {
        @Override
        public Map<String, String> getHeaders() {
          return Collections.singletonMap(
              QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE);
        }
      };
  CredentialsProvider credentialsProvider_with_quota =
      new CredentialsProvider() {
        @Override
        public Credentials getCredentials() throws IOException {
          return credentialsWithQuotaProject;
        }
      };
  // Case for setting quota_project_id from builder only
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaOnly = new FakeClientSettings.Builder();
  builder_setQuotaOnly.setCredentialsProvider(credentialsProvider_no_quota);
  builder_setQuotaOnly.setHeaderProvider(headerProvider_no_quota);
  builder_setQuotaOnly.setInternalHeaderProvider(internalHeaderProvider_no_quota);
  builder_setQuotaOnly.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS);
  // Case for setting quota_project_id from HeaderProvider Only
  // expect value is from HeaderProvider
  FakeClientSettings.Builder builder_setQuotaFromHeadersOnly = new FakeClientSettings.Builder();
  builder_setQuotaFromHeadersOnly.setHeaderProvider(headerProvider_with_quota);
  // Case for setting quota_project_id from HeaderProvider and set from builders
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaFromHeadersAndBuilders =
      new FakeClientSettings.Builder();
  builder_setQuotaFromHeadersOnly.setHeaderProvider(headerProvider_with_quota);
  builder_setQuotaFromHeadersAndBuilders.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS);
  // Case for setting quota_project_id from InternalHeaderProvider and set from builders
  // expect value is from InternalHeaderProvider
  FakeClientSettings.Builder builder_setQuotaFromInternalHeadersOnly =
      new FakeClientSettings.Builder();
  builder_setQuotaFromInternalHeadersOnly.setInternalHeaderProvider(
      internalHeaderProvider_with_quota);
  // Case for setting quota_project_id from InternalHeaderProvider and set from builders
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaFromInternalHeadersAndBuilders =
      new FakeClientSettings.Builder();
  builder_setQuotaFromInternalHeadersAndBuilders.setInternalHeaderProvider(
      internalHeaderProvider_with_quota);
  builder_setQuotaFromInternalHeadersAndBuilders.setQuotaProjectId(
      QUOTA_PROJECT_ID_FROM_BUILDERS);
  // Case for setting quota_project_id from CredentialProvider Only
  // expect value is from CredentialProvider
  FakeClientSettings.Builder builder_setQuotaFromCredentialsProvider =
      new FakeClientSettings.Builder();
  builder_setQuotaFromCredentialsProvider.setCredentialsProvider(credentialsProvider_with_quota);
  // Case for setting quota_project_id from CredentialProvider and Builders
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaFromCredentialsProviderAndBuilder =
      new FakeClientSettings.Builder();
  builder_setQuotaFromCredentialsProviderAndBuilder.setCredentialsProvider(
      credentialsProvider_with_quota);
  builder_setQuotaFromCredentialsProviderAndBuilder.setQuotaProjectId(
      QUOTA_PROJECT_ID_FROM_BUILDERS);
  // Case for setting quota_project_id from All three sources
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaFromAllSources = new FakeClientSettings.Builder();
  builder_setQuotaFromAllSources.setHeaderProvider(headerProvider_with_quota);
  builder_setQuotaFromAllSources.setInternalHeaderProvider(headerProvider_with_quota);
  builder_setQuotaFromAllSources.setCredentialsProvider(credentialsProvider_with_quota);
  builder_setQuotaFromAllSources.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS);
  // Case for setting quota_project_id from All three sources but set from builders first
  // expect value is from builders
  FakeClientSettings.Builder builder_setQuotaFromAllSourcesOrder =
      new FakeClientSettings.Builder();
  builder_setQuotaFromAllSourcesOrder.setQuotaProjectId(QUOTA_PROJECT_ID_FROM_BUILDERS);
  builder_setQuotaFromAllSourcesOrder.setHeaderProvider(headerProvider_with_quota);
  builder_setQuotaFromAllSourcesOrder.setInternalHeaderProvider(headerProvider_with_quota);
  builder_setQuotaFromAllSourcesOrder.setCredentialsProvider(credentialsProvider_with_quota);
  Truth.assertThat(builder_setQuotaOnly.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
  Truth.assertThat(builder_setQuotaFromHeadersOnly.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_HEADER_VALUE);
  Truth.assertThat(builder_setQuotaFromHeadersAndBuilders.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
  Truth.assertThat((builder_setQuotaFromInternalHeadersOnly).getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE);
  Truth.assertThat(builder_setQuotaFromInternalHeadersAndBuilders.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
  Truth.assertThat(builder_setQuotaFromCredentialsProviderAndBuilder.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
  Truth.assertThat(builder_setQuotaFromAllSources.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
  Truth.assertThat(builder_setQuotaFromAllSourcesOrder.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_BUILDERS);
}