@@ -656,16 +656,13 @@ void refreshAccessToken_nullApiAudience() throws IOException {
656656 transportFactory .transport .addGdchServiceAccount (
657657 GdchCredentials .getIssuerSubjectValue (PROJECT_ID , SERVICE_IDENTITY_NAME ), tokenString );
658658 transportFactory .transport .setTokenServerUri (TOKEN_SERVER_URI );
659- try {
660- credentials .refreshAccessToken ();
661- fail ("Should not be able to refresh access token without exception." );
662- } catch (NullPointerException ex ) {
663- assertTrue (
664- ex .getMessage ()
665- .contains (
666- "Audience cannot be null or empty for GDCH service account credentials. "
667- + "Specify the audience by calling createWithGdchAudience" ));
668- }
659+ NullPointerException ex =
660+ assertThrows (NullPointerException .class , () -> credentials .refreshAccessToken ());
661+ assertTrue (
662+ ex .getMessage ()
663+ .contains (
664+ "Audience cannot be null or empty for GDCH service account credentials. "
665+ + "Specify the audience by calling createWithGdchAudience" ));
669666 }
670667
671668 @ Test
@@ -999,14 +996,10 @@ void refreshAccessToken_invalidResponse_missingAccessToken() throws IOException
999996 GdchCredentials .getIssuerSubjectValue (PROJECT_ID , SERVICE_IDENTITY_NAME ), null );
1000997 transportFactory .transport .setTokenServerUri (TOKEN_SERVER_URI );
1001998
1002- try {
1003- gdchWithAudience .refreshAccessToken ();
1004- fail ("Should not be able to refresh access token without exception." );
1005- } catch (IOException ex ) {
1006- assertEquals (
1007- "Error parsing token refresh response. Expected value access_token not found." ,
1008- ex .getMessage ());
1009- }
999+ IOException ex = assertThrows (IOException .class , () -> gdchWithAudience .refreshAccessToken ());
1000+ assertEquals (
1001+ "Error parsing token refresh response. Expected value access_token not found." ,
1002+ ex .getMessage ());
10101003 }
10111004
10121005 @ Test
@@ -1048,12 +1041,9 @@ private void refreshAccessToken_invalidResponse(
10481041 transportFactory .transport .addResponseSequence (
10491042 new MockLowLevelHttpResponse ().setContentType (Json .MEDIA_TYPE ).setContent (responseContent ));
10501043
1051- try {
1052- gdchWithAudience .refreshAccessToken ();
1053- fail ("Should not be able to refresh access token with invalid response." );
1054- } catch (IOException ex ) {
1055- assertEquals (expectedErrorMessage , ex .getMessage ());
1056- }
1044+ IOException ex =
1045+ assertThrows (IOException .class , () -> gdchWithAudience .refreshAccessToken ());
1046+ assertEquals (expectedErrorMessage , ex .getMessage ());
10571047 }
10581048
10591049 @ Test
@@ -1074,13 +1064,10 @@ void refreshAccessToken_serverError() throws IOException {
10741064 transportFactory .transport .addResponseSequence (
10751065 new MockLowLevelHttpResponse ().setStatusCode (400 ).setReasonPhrase ("Bad Request" ));
10761066
1077- try {
1078- gdchWithAudience .refreshAccessToken ();
1079- fail ("Should not be able to refresh access token with server error." );
1080- } catch (IOException ex ) {
1081- assertTrue (ex .getMessage ().contains ("Error getting access token for GDCH service account" ));
1082- assertTrue (ex .getMessage ().contains ("400 Bad Request" ));
1083- }
1067+ GoogleAuthException ex =
1068+ assertThrows (GoogleAuthException .class , () -> gdchWithAudience .refreshAccessToken ());
1069+ assertTrue (ex .getMessage ().contains ("Error getting access token for GDCH service account" ));
1070+ assertTrue (ex .getMessage ().contains ("400 Bad Request" ));
10841071 }
10851072
10861073 @ Test
@@ -1100,13 +1087,10 @@ void refreshAccessToken_ioException() throws IOException {
11001087
11011088 transportFactory .transport .addResponseErrorSequence (new IOException ("Connection reset" ));
11021089
1103- try {
1104- gdchWithAudience .refreshAccessToken ();
1105- fail ("Should not be able to refresh access token with IO exception." );
1106- } catch (IOException ex ) {
1107- assertTrue (ex .getMessage ().contains ("Error getting access token for GDCH service account" ));
1108- assertTrue (ex .getMessage ().contains ("Connection reset" ));
1109- }
1090+ GoogleAuthException ex =
1091+ assertThrows (GoogleAuthException .class , () -> gdchWithAudience .refreshAccessToken ());
1092+ assertTrue (ex .getMessage ().contains ("Error getting access token for GDCH service account" ));
1093+ assertTrue (ex .getMessage ().contains ("Connection reset" ));
11101094 }
11111095
11121096 @ Test
0 commit comments