From 6df1731a10ce1b1fe790b7a6cb23c16da15f1cc5 Mon Sep 17 00:00:00 2001 From: Nicole Lee Date: Wed, 22 Jul 2026 06:48:21 +0000 Subject: [PATCH 1/2] test(spanner): disable Mockito annotation copying for Credentials and ServiceAccountCredentials --- .../cloud/spanner/MutableCredentialsTest.java | 13 +++++++++---- .../cloud/spanner/connection/SpannerPoolTest.java | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java index 654083e0ee69..8e60629b04e9 100644 --- a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java +++ b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; import com.google.auth.CredentialTypeForMetrics; import com.google.auth.RequestMetadataCallback; @@ -45,10 +46,14 @@ @RunWith(JUnit4.class) public class MutableCredentialsTest { - ServiceAccountCredentials initialCredentials = mock(ServiceAccountCredentials.class); - ServiceAccountCredentials initialScopedCredentials = mock(ServiceAccountCredentials.class); - ServiceAccountCredentials updatedCredentials = mock(ServiceAccountCredentials.class); - ServiceAccountCredentials updatedScopedCredentials = mock(ServiceAccountCredentials.class); + ServiceAccountCredentials initialCredentials = + mock(ServiceAccountCredentials.class, withSettings().withoutAnnotations()); + ServiceAccountCredentials initialScopedCredentials = + mock(ServiceAccountCredentials.class, withSettings().withoutAnnotations()); + ServiceAccountCredentials updatedCredentials = + mock(ServiceAccountCredentials.class, withSettings().withoutAnnotations()); + ServiceAccountCredentials updatedScopedCredentials = + mock(ServiceAccountCredentials.class, withSettings().withoutAnnotations()); Set scopes = new HashSet<>(Arrays.asList("scope-a", "scope-b")); Map> initialMetadata = Collections.singletonMap("Authorization", Collections.singletonList("v1")); diff --git a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SpannerPoolTest.java b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SpannerPoolTest.java index 280bce2b0fcc..68951cc57618 100644 --- a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SpannerPoolTest.java +++ b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/SpannerPoolTest.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; import com.google.auth.Credentials; import com.google.cloud.NoCredentials; @@ -477,7 +478,7 @@ public void testSpannerPoolKeyEquality() { .setUri( "cloudspanner://localhost:9010/projects/p1/instances/i/databases/d" + "?minSessions=200;maxSessions=400;numChannels=8;usePlainText=true;userAgent=test-agent") - .setCredentials(mock(Credentials.class)) + .setCredentials(mock(Credentials.class, withSettings().withoutAnnotations())) .build(); // options2 equals the default session pool options, and is therefore equal to ConnectionOptions // without any session pool configuration. From 122da5caadfc13d61fe7d9049b976df3f9fa0a6f Mon Sep 17 00:00:00 2001 From: Nicole Lee Date: Wed, 22 Jul 2026 14:30:49 +0000 Subject: [PATCH 2/2] test(spanner): disable annotation copying of RequestMetadataCallback mock --- .../com/google/cloud/spanner/MutableCredentialsTest.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java index 8e60629b04e9..9f8ee4ceceb7 100644 --- a/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java +++ b/java-spanner/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MutableCredentialsTest.java @@ -75,7 +75,8 @@ public void testCreateMutableCredentials() throws IOException { MutableCredentials credentials = new MutableCredentials(initialCredentials, scopes); URI testUri = URI.create("https://spanner.googleapis.com"); Executor executor = mock(Executor.class); - RequestMetadataCallback callback = mock(RequestMetadataCallback.class); + RequestMetadataCallback callback = + mock(RequestMetadataCallback.class, withSettings().withoutAnnotations()); validateInitialDelegatedCredentialsAreSet(credentials, testUri); @@ -116,7 +117,8 @@ public void testUpdateMutableCredentials() throws IOException { MutableCredentials credentials = new MutableCredentials(initialCredentials, scopes); URI testUri = URI.create("https://example.com"); Executor executor = mock(Executor.class); - RequestMetadataCallback callback = mock(RequestMetadataCallback.class); + RequestMetadataCallback callback = + mock(RequestMetadataCallback.class, withSettings().withoutAnnotations()); validateInitialDelegatedCredentialsAreSet(credentials, testUri);