2020import static org .junit .Assert .assertTrue ;
2121
2222import com .google .api .apikeys .v2 .Key ;
23+ import com .google .api .gax .rpc .InvalidArgumentException ;
2324import com .google .cloud .ServiceOptions ;
2425import io .grpc .StatusRuntimeException ;
25- import com .google .api .gax .rpc .InvalidArgumentException ;
2626import java .io .ByteArrayOutputStream ;
2727import java .io .IOException ;
2828import java .io .PrintStream ;
@@ -66,15 +66,12 @@ public void testAuthExplicitNoPath() throws IOException {
6666 @ Test
6767 public void testAuthApiKey () throws IOException , IllegalStateException {
6868 String projectId = ServiceOptions .getDefaultProjectId ();
69- java .util .Random random = new java .util .Random ();
70- String keyDisplayName = "Test API Key " + random .nextInt ();
69+ String keyDisplayName = "Test API Key" ;
7170 String service = "language.googleapis.com" ;
7271 String method = "google.cloud.language.v2.LanguageService.AnalyzeSentiment" ;
7372 Key apiKey = null ;
7473 try {
7574 apiKey = AuthTestUtils .createTestApiKey (projectId , keyDisplayName , service , method );
76- assertNotNull (apiKey );
77- System .out .println ("key string " + apiKey .getKeyString ());
7875 String output = authenticateUsingApiKeyWithRetry (apiKey .getKeyString ());
7976 assertTrue (output .contains ("magnitude:" ));
8077 } finally {
@@ -92,7 +89,7 @@ static String authenticateUsingApiKeyWithRetry(String apiKey) throws IOException
9289 for (int i = 0 ; i < retries ; i ++) {
9390 try {
9491 return ApiKeyAuthExample .authenticateUsingApiKey (apiKey );
95- } catch (StatusRuntimeException | InvalidArgumentException e ) {
92+ } catch (StatusRuntimeException | InvalidArgumentException e ) {
9693 if (e .getMessage ().contains ("API key expired" )) {
9794 System .out .println ("API key not yet active, retrying..." );
9895 try {
0 commit comments