@Test
public void testBuilderFromClientContext_QuotaProjectId() {

  ApiCallContext callContext = FakeCallContext.createDefault();
  ClientContext clientContextQuotaOnly =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
          .build();
  FakeClientSettings.Builder builderQuotaOnly =
      new FakeClientSettings.Builder(clientContextQuotaOnly);
  ClientContext clientContextCredentialOnly =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setCredentials(credentialsWithQuotaProject)
          .build();
  FakeClientSettings.Builder builderCredentialOnly =
      new FakeClientSettings.Builder(clientContextCredentialOnly);
  ClientContext clientContextCredentialAndQuota =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setCredentials(credentialsWithQuotaProject)
          .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
          .build();
  FakeClientSettings.Builder builderCredentialAndQuota =
      new FakeClientSettings.Builder(clientContextCredentialAndQuota);
  ClientContext clientContextHeadersOnly =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setHeaders(ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE))
          .build();
  FakeClientSettings.Builder builderHeadersOnly =
      new FakeClientSettings.Builder(clientContextHeadersOnly);
  ClientContext clientContextHeadersAndQuota =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
          .setHeaders(ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_HEADER_VALUE))
          .build();
  FakeClientSettings.Builder builderHeadersAndQuota =
      new FakeClientSettings.Builder(clientContextHeadersAndQuota);
  ClientContext clientContextInternalHeadersOnly =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setInternalHeaders(
              ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE))
          .build();
  FakeClientSettings.Builder builderInternalHeadersOnly =
      new FakeClientSettings.Builder(clientContextInternalHeadersOnly);
  ClientContext clientContextInternalHeadersAndQuota =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setInternalHeaders(
              ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE))
          .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
          .build();
  FakeClientSettings.Builder builderInternalHeadersAndQuota =
      new FakeClientSettings.Builder(clientContextInternalHeadersAndQuota);
  ClientContext clientContextQuotaFromAllSources =
      ClientContext.newBuilder()
          .setTransportChannel(Mockito.mock(TransportChannel.class))
          .setDefaultCallContext(callContext)
          .setHeaders(
              ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE))
          .setCredentials(credentialsWithQuotaProject)
          .setQuotaProjectId(QUOTA_PROJECT_ID_FROM_CONTEXT)
          .setInternalHeaders(
              ImmutableMap.of(QUOTA_PROJECT_ID_KEY, QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE))
          .build();
  FakeClientSettings.Builder builderQuotaFromAllSources =
      new FakeClientSettings.Builder(clientContextQuotaFromAllSources);
  Truth.assertThat(builderQuotaOnly.getQuotaProjectId()).isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
  Truth.assertThat(builderCredentialOnly.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_CREDENTIALS_VALUE);
  Truth.assertThat(builderCredentialAndQuota.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
  Truth.assertThat(builderHeadersOnly.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_HEADER_VALUE);
  Truth.assertThat(builderHeadersAndQuota.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
  Truth.assertThat(builderInternalHeadersOnly.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_INTERNAL_HEADER_VALUE);
  Truth.assertThat(builderInternalHeadersAndQuota.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
  Truth.assertThat(builderQuotaFromAllSources.getQuotaProjectId())
      .isEqualTo(QUOTA_PROJECT_ID_FROM_CONTEXT);
}