3131
3232package com .google .auth .oauth2 ;
3333
34- import static org .junit .Assert .assertArrayEquals ;
35- import static org .junit .Assert .assertEquals ;
36- import static org .junit .Assert .assertFalse ;
37- import static org .junit .Assert .assertNotSame ;
38- import static org .junit .Assert . assertTrue ;
39- import static org .junit .Assert . fail ;
34+ import static org .junit .jupiter . api . Assertions .assertArrayEquals ;
35+ import static org .junit .jupiter . api . Assertions .assertEquals ;
36+ import static org .junit .jupiter . api . Assertions .assertFalse ;
37+ import static org .junit .jupiter . api . Assertions .assertNotSame ;
38+ import static org .junit .jupiter . api . Assertions . assertThrows ;
39+ import static org .junit .jupiter . api . Assertions . assertTrue ;
4040
4141import com .google .common .collect .ImmutableMap ;
4242import java .io .IOException ;
4747import java .util .Date ;
4848import java .util .List ;
4949import java .util .Map ;
50- import org .junit .Test ;
51- import org .junit .runner .RunWith ;
52- import org .junit .runners .JUnit4 ;
50+ import org .junit .jupiter .api .Test ;
5351
54- @ RunWith (JUnit4 .class )
55- public class AppEngineCredentialsTest extends BaseSerializationTest {
52+ class AppEngineCredentialsTest extends BaseSerializationTest {
5653
5754 private static final String EXPECTED_ACCESS_TOKEN = "ExpectedAccessToken" ;
5855 private static final Date EXPECTED_EXPIRATION_DATE =
@@ -66,7 +63,7 @@ public class AppEngineCredentialsTest extends BaseSerializationTest {
6663 Collections .unmodifiableCollection (Arrays .asList ("scope3" ));
6764
6865 @ Test
69- public void constructor_usesAppIdentityService () throws IOException {
66+ void constructor_usesAppIdentityService () throws IOException {
7067 Collection <String > scopes = Collections .singleton ("SomeScope" );
7168 TestAppEngineCredentials credentials = new TestAppEngineCredentials (scopes );
7269 List <String > forNameArgs = credentials .getForNameArgs ();
@@ -78,51 +75,50 @@ public void constructor_usesAppIdentityService() throws IOException {
7875 }
7976
8077 @ Test
81- public void constructor_noAppEngineRuntime_throwsHelpfulLoadError () throws IOException {
82- try {
83- new TestAppEngineCredentialsNoSdk ();
84- fail ("Credential expected to fail to load if credential class not present." );
85- } catch (IOException e ) {
86- String message = e .getMessage ();
87- assertTrue (message .contains ("Check that the App Engine SDK is deployed." ));
88- assertTrue (e .getCause () instanceof ClassNotFoundException );
89- assertTrue (
90- e .getCause ()
91- .getMessage ()
92- .contains (AppEngineCredentials .APP_IDENTITY_SERVICE_FACTORY_CLASS ));
93- }
78+ void constructor_noAppEngineRuntime_throwsHelpfulLoadError () {
79+ IOException exception =
80+ assertThrows (
81+ IOException .class ,
82+ TestAppEngineCredentialsNoSdk ::new ,
83+ "Credential expected to fail to load if credential class not present." );
84+ String message = exception .getMessage ();
85+ assertTrue (message .contains ("Check that the App Engine SDK is deployed." ));
86+ assertTrue (exception .getCause () instanceof ClassNotFoundException );
87+ assertTrue (
88+ exception
89+ .getCause ()
90+ .getMessage ()
91+ .contains (AppEngineCredentials .APP_IDENTITY_SERVICE_FACTORY_CLASS ));
9492 }
9593
9694 @ Test
97- public void refreshAccessToken_sameAs () throws IOException {
95+ void refreshAccessToken_sameAs () throws IOException {
9896 TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
9997 AccessToken accessToken = credentials .refreshAccessToken ();
10098 assertEquals (EXPECTED_ACCESS_TOKEN , accessToken .getTokenValue ());
10199 assertEquals (EXPECTED_EXPIRATION_DATE , accessToken .getExpirationTime ());
102100 }
103101
104102 @ Test
105- public void getAccount_sameAs () throws IOException {
103+ void getAccount_sameAs () throws IOException {
106104 TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
107105 assertEquals (EXPECTED_ACCOUNT , credentials .getAccount ());
108106 }
109107
110108 @ Test
111- public void sign_sameAs () throws IOException {
109+ void sign_sameAs () throws IOException {
112110 TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
113111 assertArrayEquals (EXPECTED_SIGNATURE , credentials .sign ("Bytes to sign" .getBytes ()));
114112 }
115113
116114 @ Test
117- public void createScoped_clonesWithScopes () throws IOException {
115+ void createScoped_clonesWithScopes () throws IOException {
118116 TestAppEngineCredentials credentials = new TestAppEngineCredentials (null );
119117 assertTrue (credentials .createScopedRequired ());
120- try {
121- credentials .refreshAccessToken ();
122- fail ("Should not be able to use credential without scopes." );
123- } catch (Exception expected ) {
124- // Expected
125- }
118+ assertThrows (
119+ Exception .class ,
120+ credentials ::refreshAccessToken ,
121+ "Should not be able to use credential without scopes." );
126122
127123 GoogleCredentials scopedCredentials = credentials .createScoped (SCOPES );
128124 assertNotSame (credentials , scopedCredentials );
@@ -133,7 +129,7 @@ public void createScoped_clonesWithScopes() throws IOException {
133129 }
134130
135131 @ Test
136- public void createScoped_defaultScopes () throws IOException {
132+ void createScoped_defaultScopes () throws IOException {
137133 TestAppEngineCredentials credentials = new TestAppEngineCredentials (null );
138134 assertTrue (credentials .createScopedRequired ());
139135
@@ -152,7 +148,7 @@ public void createScoped_defaultScopes() throws IOException {
152148 }
153149
154150 @ Test
155- public void equals_true () throws IOException {
151+ void equals_true () throws IOException {
156152 GoogleCredentials credentials = new TestAppEngineCredentials (SCOPES );
157153 GoogleCredentials otherCredentials = new TestAppEngineCredentials (SCOPES );
158154 assertTrue (credentials .equals (credentials ));
@@ -161,7 +157,7 @@ public void equals_true() throws IOException {
161157 }
162158
163159 @ Test
164- public void equals_false_scopes () throws IOException {
160+ void equals_false_scopes () throws IOException {
165161 final Collection <String > emptyScopes = Collections .emptyList ();
166162 Collection <String > scopes = Collections .singleton ("SomeScope" );
167163 AppEngineCredentials credentials = new TestAppEngineCredentials (emptyScopes );
@@ -171,7 +167,7 @@ public void equals_false_scopes() throws IOException {
171167 }
172168
173169 @ Test
174- public void toString_containsFields () throws IOException {
170+ void toString_containsFields () throws IOException {
175171 String expectedToString =
176172 String .format (
177173 "TestAppEngineCredentials{scopes=[%s], scopesRequired=%b}" , "SomeScope" , false );
@@ -181,13 +177,13 @@ public void toString_containsFields() throws IOException {
181177 }
182178
183179 @ Test
184- public void hashCode_equals () throws IOException {
180+ void hashCode_equals () throws IOException {
185181 AppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
186182 assertEquals (credentials .hashCode (), credentials .hashCode ());
187183 }
188184
189185 @ Test
190- public void serialize () throws IOException , ClassNotFoundException {
186+ void serialize () throws IOException , ClassNotFoundException {
191187 Collection <String > scopes = Collections .singleton ("SomeScope" );
192188 AppEngineCredentials credentials = new TestAppEngineCredentials (scopes );
193189 GoogleCredentials deserializedCredentials = serializeAndDeserialize (credentials );
0 commit comments