Skip to content

Commit 615362d

Browse files
committed
cleanup
1 parent a72e2ce commit 615362d

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
180180
Credentials credentials = settings.getCredentialsProvider().getCredentials();
181181
if (apiKey != null && credentials != null) {
182182
throw new IllegalArgumentException(
183-
"You can not provide both ApiKey and Credentials for a client.");
183+
"You can not provide both ApiKey and Credentials for a client.");
184184
}
185185
if (apiKey != null) {
186186
// if API key exists it becomes the default credential
@@ -234,7 +234,6 @@ public static ClientContext create(StubSettings settings) throws IOException {
234234

235235
ApiCallContext defaultCallContext =
236236
transportChannel.getEmptyCallContext().withTransportChannel(transportChannel);
237-
238237
if (credentials != null) {
239238
defaultCallContext = defaultCallContext.withCredentials(credentials);
240239
}
@@ -293,7 +292,11 @@ public static ClientContext create(StubSettings settings) throws IOException {
293292
.build();
294293
}
295294

296-
private static Credentials getGdchCredentials(String settingsGdchApiAudience, String endpoint, Credentials credentials) throws IOException {
295+
/**
296+
* Constructs a new {@link Credentials} object based on credentials provided with a GDC-H audience
297+
*/
298+
private static Credentials getGdchCredentials(
299+
String settingsGdchApiAudience, String endpoint, Credentials credentials) throws IOException {
297300
String audienceString;
298301
if (!Strings.isNullOrEmpty(settingsGdchApiAudience)) {
299302
audienceString = settingsGdchApiAudience;
@@ -307,8 +310,7 @@ private static Credentials getGdchCredentials(String settingsGdchApiAudience, St
307310
try {
308311
gdchAudienceUri = URI.create(audienceString);
309312
} catch (IllegalArgumentException ex) { // thrown when passing a malformed uri string
310-
throw new IllegalArgumentException(
311-
"The GDC-H API audience string is not a valid URI", ex);
313+
throw new IllegalArgumentException("The GDC-H API audience string is not a valid URI", ex);
312314
}
313315
credentials = ((GdchCredentials) credentials).createWithGdchAudience(gdchAudienceUri);
314316
return credentials;

gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientSettings.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public final StubSettings getStubSettings() {
6565
return stubSettings;
6666
}
6767

68-
/**
69-
* @deprecated Please use {@link #getBackgroundExecutorProvider()}
70-
*/
68+
/** @deprecated Please use {@link #getBackgroundExecutorProvider()} */
7169
@Deprecated
7270
public final ExecutorProvider getExecutorProvider() {
7371
return stubSettings.getExecutorProvider();
@@ -314,6 +312,8 @@ public B setGdchApiAudience(@Nullable String gdchApiAudience) {
314312
/**
315313
* Sets the API key. The API key will get translated to an [ApiKeyCredentials] and stored in
316314
* [CallContext].
315+
*
316+
* Note: you can not set an API key and credentials object in the same Settings. It will fail when creating the client.
317317
*/
318318
public B setApiKey(String apiKey) {
319319
stubSettings.setApiKey(apiKey);

gax-java/gax/src/main/java/com/google/api/gax/rpc/StubSettings.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ private EndpointContext buildEndpointContext(Builder builder) {
132132
}
133133
}
134134

135-
/**
136-
* @deprecated Please use {@link #getBackgroundExecutorProvider()}.
137-
*/
135+
/** @deprecated Please use {@link #getBackgroundExecutorProvider()}. */
138136
@Deprecated
139137
public final ExecutorProvider getExecutorProvider() {
140138
return deprecatedExecutorProviderSet ? backgroundExecutorProvider : null;
@@ -176,23 +174,17 @@ protected String getServiceName() {
176174
return "";
177175
}
178176

179-
/**
180-
* @return the fully resolved universe domain used by the client
181-
*/
177+
/** @return the fully resolved universe domain used by the client */
182178
public final String getUniverseDomain() {
183179
return endpointContext.resolvedUniverseDomain();
184180
}
185181

186-
/**
187-
* @return the fully resolved endpoint used by the client
188-
*/
182+
/** @return the fully resolved endpoint used by the client */
189183
public String getEndpoint() {
190184
return endpointContext.resolvedEndpoint();
191185
}
192186

193-
/**
194-
* @return the newly created EndpointContext
195-
*/
187+
/** @return the newly created EndpointContext */
196188
@InternalApi
197189
final EndpointContext getEndpointContext() {
198190
return endpointContext;
@@ -605,9 +597,7 @@ public B setApiKey(String apiKey) {
605597
return self();
606598
}
607599

608-
/**
609-
* @deprecated Please use {@link #getBackgroundExecutorProvider()}.
610-
*/
600+
/** @deprecated Please use {@link #getBackgroundExecutorProvider()}. */
611601
@Deprecated
612602
public ExecutorProvider getExecutorProvider() {
613603
return deprecatedExecutorProviderSet ? backgroundExecutorProvider : null;

gax-java/gax/src/test/java/com/google/api/gax/rpc/ClientContextTest.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
import java.util.concurrent.Executor;
6363
import java.util.concurrent.ScheduledExecutorService;
6464
import java.util.concurrent.ScheduledThreadPoolExecutor;
65-
66-
import org.apache.http.impl.client.SystemDefaultCredentialsProvider;
6765
import org.junit.jupiter.api.Test;
6866
import org.mockito.Mockito;
6967

@@ -1080,7 +1078,6 @@ public void testSetApiKey_createsApiCredentials() throws IOException {
10801078
new FakeTransportProvider(
10811079
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
10821080
builder.setTransportChannelProvider(transportProvider);
1083-
10841081
HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
10851082
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of());
10861083
builder.setHeaderProvider(headerProvider);
@@ -1099,22 +1096,21 @@ void testCreateClient_throwsErrorIfApiKeyAndCredentialsAreProvided() throws Exce
10991096
InterceptingExecutor executor = new InterceptingExecutor(1);
11001097
FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
11011098
FakeTransportProvider transportProvider =
1102-
new FakeTransportProvider(
1103-
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
1099+
new FakeTransportProvider(
1100+
transportChannel, executor, true, ImmutableMap.of(), null, DEFAULT_ENDPOINT);
11041101
builder.setTransportChannelProvider(transportProvider);
1105-
11061102
HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
11071103
Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of());
11081104
builder.setHeaderProvider(headerProvider);
11091105
builder.setApiKey(apiKey);
11101106
builder.setCredentialsProvider(Mockito.mock(CredentialsProvider.class));
11111107

11121108
try {
1113-
ClientContext context = ClientContext.create(builder.build());
1109+
ClientContext.create(builder.build());
11141110
fail("No exception raised");
11151111
} catch (IllegalArgumentException e) {
1116-
assert(
1117-
e.getMessage().contains("You can not provide both ApiKey and Credentials for a client."));
1112+
assert (e.getMessage()
1113+
.contains("You can not provide both ApiKey and Credentials for a client."));
11181114
}
11191115
}
11201116
}

0 commit comments

Comments
 (0)