From 4b5f2aed45fd7ae2b0d1b6ebfe0388e7daf95de8 Mon Sep 17 00:00:00 2001 From: Timur Sadykov Date: Fri, 5 Jan 2024 05:29:05 -0800 Subject: [PATCH] fix: toBuilder test fix --- .../auth/oauth2/ComputeEngineCredentials.java | 6 ++++++ .../com/google/auth/oauth2/GoogleCredentials.java | 4 +++- .../auth/oauth2/ComputeEngineCredentialsTest.java | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java index fd7260534..2e0c321d1 100644 --- a/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java @@ -657,6 +657,12 @@ public Builder setUniverseDomain(String universeDomain) { return this; } + @CanIgnoreReturnValue + public Builder setQuotaProjectId(String quotaProjectId) { + super.quotaProjectId = quotaProjectId; + return this; + } + public HttpTransportFactory getHttpTransportFactory() { return transportFactory; } diff --git a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java index a49cf9b2f..54d708103 100644 --- a/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java +++ b/oauth2_http/java/com/google/auth/oauth2/GoogleCredentials.java @@ -481,7 +481,9 @@ protected Builder() {} protected Builder(GoogleCredentials credentials) { super(credentials); this.quotaProjectId = credentials.quotaProjectId; - this.universeDomain = credentials.universeDomain; + if (credentials.isExplicitUniverseDomain) { + this.universeDomain = credentials.universeDomain; + } } protected Builder(GoogleCredentials.Builder builder) { diff --git a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java index 80268bb1e..dc307d518 100644 --- a/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java +++ b/oauth2_http/javatests/com/google/auth/oauth2/ComputeEngineCredentialsTest.java @@ -60,6 +60,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Date; import java.util.List; import java.util.Map; import java.util.Queue; @@ -361,6 +362,19 @@ public void hashCode_equals() throws IOException { assertEquals(credentials.hashCode(), otherCredentials.hashCode()); } + @Test + public void toBuilder() { + ComputeEngineCredentials credentials = + ComputeEngineCredentials.newBuilder() + .setHttpTransportFactory(new MockMetadataServerTransportFactory()) + .setQuotaProjectId("quota-project") + .build(); + + ComputeEngineCredentials secondCredentials = credentials.toBuilder().build(); + + assertEquals(credentials, secondCredentials); + } + @Test public void serialize() throws IOException, ClassNotFoundException { MockMetadataServerTransportFactory serverTransportFactory =