3131
3232package com .google .auth .appengine ;
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 .assertNotNull ;
38- import static org .junit .Assert .assertNotSame ;
39- import static org .junit .Assert . assertTrue ;
40- 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 .assertNotNull ;
38+ import static org .junit .jupiter . api . Assertions .assertNotSame ;
39+ import static org .junit .jupiter . api . Assertions . assertThrows ;
40+ import static org .junit .jupiter . api . Assertions . assertTrue ;
4141
4242import com .google .auth .Credentials ;
4343import com .google .auth .oauth2 .AccessToken ;
5151import java .util .Date ;
5252import java .util .List ;
5353import java .util .Map ;
54- import org .junit .Test ;
55- import org .junit .runner .RunWith ;
56- import org .junit .runners .JUnit4 ;
54+ import org .junit .jupiter .api .Test ;
5755
5856/** Unit tests for AppEngineCredentials */
59- @ RunWith (JUnit4 .class )
60- public class AppEngineCredentialsTest extends BaseSerializationTest {
57+ class AppEngineCredentialsTest extends BaseSerializationTest {
6158
6259 private static Collection <String > SCOPES =
6360 Collections .unmodifiableCollection (Arrays .asList ("scope1" , "scope2" ));
6461 private static final URI CALL_URI = URI .create ("http://googleapis.com/testapi/v1/foo" );
6562 private static final String EXPECTED_ACCOUNT = "serviceAccount" ;
6663
6764 @ Test
68- public void constructor_usesAppIdentityService () throws IOException {
65+ void constructor_usesAppIdentityService () throws IOException {
6966 String expectedAccessToken = "ExpectedAccessToken" ;
7067
7168 MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -83,7 +80,7 @@ public void constructor_usesAppIdentityService() throws IOException {
8380 }
8481
8582 @ Test
86- public void refreshAccessToken_sameAs () throws IOException {
83+ void refreshAccessToken_sameAs () throws IOException {
8784 String expectedAccessToken = "ExpectedAccessToken" ;
8885
8986 MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -100,7 +97,7 @@ public void refreshAccessToken_sameAs() throws IOException {
10097 }
10198
10299 @ Test
103- public void getAccount_sameAs () throws IOException {
100+ void getAccount_sameAs () {
104101 MockAppIdentityService appIdentity = new MockAppIdentityService ();
105102 appIdentity .setServiceAccountName (EXPECTED_ACCOUNT );
106103 AppEngineCredentials credentials =
@@ -112,7 +109,7 @@ public void getAccount_sameAs() throws IOException {
112109 }
113110
114111 @ Test
115- public void sign_sameAs () throws IOException {
112+ void sign_sameAs () {
116113 byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
117114 MockAppIdentityService appIdentity = new MockAppIdentityService ();
118115 appIdentity .setSignature (expectedSignature );
@@ -125,7 +122,7 @@ public void sign_sameAs() throws IOException {
125122 }
126123
127124 @ Test
128- public void createScoped_clonesWithScopes () throws IOException {
125+ void createScoped_clonesWithScopes () throws IOException {
129126 String expectedAccessToken = "ExpectedAccessToken" ;
130127 Collection <String > emptyScopes = Collections .emptyList ();
131128
@@ -138,11 +135,10 @@ public void createScoped_clonesWithScopes() throws IOException {
138135 .setAppIdentityService (appIdentity )
139136 .build ();
140137 assertTrue (credentials .createScopedRequired ());
141- try {
142- credentials .getRequestMetadata (CALL_URI );
143- fail ("Should not be able to use credential without scopes." );
144- } catch (Exception expected ) {
145- }
138+ assertThrows (
139+ Exception .class ,
140+ () -> credentials .getRequestMetadata (CALL_URI ),
141+ "Should not be able to use credential without scopes." );
146142 assertEquals (0 , appIdentity .getGetAccessTokenCallCount ());
147143
148144 GoogleCredentials scopedCredentials = credentials .createScoped (SCOPES );
@@ -155,7 +151,7 @@ public void createScoped_clonesWithScopes() throws IOException {
155151 }
156152
157153 @ Test
158- public void equals_true () throws IOException {
154+ void equals_true () {
159155 Collection <String > emptyScopes = Collections .emptyList ();
160156 MockAppIdentityService appIdentity = new MockAppIdentityService ();
161157
@@ -175,7 +171,7 @@ public void equals_true() throws IOException {
175171 }
176172
177173 @ Test
178- public void equals_false_scopes () throws IOException {
174+ void equals_false_scopes () {
179175 Collection <String > emptyScopes = Collections .emptyList ();
180176 Collection <String > scopes = Collections .singleton ("SomeScope" );
181177 MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -195,7 +191,7 @@ public void equals_false_scopes() throws IOException {
195191 }
196192
197193 @ Test
198- public void toString_containsFields () throws IOException {
194+ void toString_containsFields () {
199195 String expectedToString =
200196 String .format (
201197 "AppEngineCredentials{scopes=[%s], scopesRequired=%b, appIdentityServiceClassName=%s}" ,
@@ -213,7 +209,7 @@ public void toString_containsFields() throws IOException {
213209 }
214210
215211 @ Test
216- public void hashCode_equals () throws IOException {
212+ void hashCode_equals () {
217213 Collection <String > emptyScopes = Collections .emptyList ();
218214 MockAppIdentityService appIdentity = new MockAppIdentityService ();
219215 AppEngineCredentials credentials =
@@ -230,7 +226,7 @@ public void hashCode_equals() throws IOException {
230226 }
231227
232228 @ Test
233- public void serialize () throws IOException , ClassNotFoundException {
229+ void serialize () throws IOException , ClassNotFoundException {
234230 Collection <String > scopes = Collections .singleton ("SomeScope" );
235231 MockAppIdentityService appIdentity = new MockAppIdentityService ();
236232 AppEngineCredentials credentials =
@@ -249,14 +245,7 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
249245 assertNotNull (token );
250246 String expectedValue = "Bearer " + token ;
251247 List <String > authorizations = metadata .get ("Authorization" );
252- assertNotNull ("Authorization headers not found" , authorizations );
253- boolean found = false ;
254- for (String authorization : authorizations ) {
255- if (expectedValue .equals (authorization )) {
256- found = true ;
257- break ;
258- }
259- }
260- assertTrue ("Bearer token not found" , found );
248+ assertNotNull (authorizations , "Authorization headers not found" );
249+ assertTrue (authorizations .contains (expectedValue ), "Bearer token not found" );
261250 }
262251}
0 commit comments