31
31
32
32
package com .google .auth .appengine ;
33
33
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 ;
41
41
42
42
import com .google .auth .Credentials ;
43
43
import com .google .auth .oauth2 .AccessToken ;
51
51
import java .util .Date ;
52
52
import java .util .List ;
53
53
import 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 ;
57
55
58
56
/** Unit tests for AppEngineCredentials */
59
- @ RunWith (JUnit4 .class )
60
- public class AppEngineCredentialsTest extends BaseSerializationTest {
57
+ class AppEngineCredentialsTest extends BaseSerializationTest {
61
58
62
59
private static Collection <String > SCOPES =
63
60
Collections .unmodifiableCollection (Arrays .asList ("scope1" , "scope2" ));
64
61
private static final URI CALL_URI = URI .create ("http://googleapis.com/testapi/v1/foo" );
65
62
private static final String EXPECTED_ACCOUNT = "serviceAccount" ;
66
63
67
64
@ Test
68
- public void constructor_usesAppIdentityService () throws IOException {
65
+ void constructor_usesAppIdentityService () throws IOException {
69
66
String expectedAccessToken = "ExpectedAccessToken" ;
70
67
71
68
MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -83,7 +80,7 @@ public void constructor_usesAppIdentityService() throws IOException {
83
80
}
84
81
85
82
@ Test
86
- public void refreshAccessToken_sameAs () throws IOException {
83
+ void refreshAccessToken_sameAs () throws IOException {
87
84
String expectedAccessToken = "ExpectedAccessToken" ;
88
85
89
86
MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -100,7 +97,7 @@ public void refreshAccessToken_sameAs() throws IOException {
100
97
}
101
98
102
99
@ Test
103
- public void getAccount_sameAs () throws IOException {
100
+ void getAccount_sameAs () {
104
101
MockAppIdentityService appIdentity = new MockAppIdentityService ();
105
102
appIdentity .setServiceAccountName (EXPECTED_ACCOUNT );
106
103
AppEngineCredentials credentials =
@@ -112,7 +109,7 @@ public void getAccount_sameAs() throws IOException {
112
109
}
113
110
114
111
@ Test
115
- public void sign_sameAs () throws IOException {
112
+ void sign_sameAs () {
116
113
byte [] expectedSignature = {0xD , 0xE , 0xA , 0xD };
117
114
MockAppIdentityService appIdentity = new MockAppIdentityService ();
118
115
appIdentity .setSignature (expectedSignature );
@@ -125,7 +122,7 @@ public void sign_sameAs() throws IOException {
125
122
}
126
123
127
124
@ Test
128
- public void createScoped_clonesWithScopes () throws IOException {
125
+ void createScoped_clonesWithScopes () throws IOException {
129
126
String expectedAccessToken = "ExpectedAccessToken" ;
130
127
Collection <String > emptyScopes = Collections .emptyList ();
131
128
@@ -138,11 +135,10 @@ public void createScoped_clonesWithScopes() throws IOException {
138
135
.setAppIdentityService (appIdentity )
139
136
.build ();
140
137
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." );
146
142
assertEquals (0 , appIdentity .getGetAccessTokenCallCount ());
147
143
148
144
GoogleCredentials scopedCredentials = credentials .createScoped (SCOPES );
@@ -155,7 +151,7 @@ public void createScoped_clonesWithScopes() throws IOException {
155
151
}
156
152
157
153
@ Test
158
- public void equals_true () throws IOException {
154
+ void equals_true () {
159
155
Collection <String > emptyScopes = Collections .emptyList ();
160
156
MockAppIdentityService appIdentity = new MockAppIdentityService ();
161
157
@@ -175,7 +171,7 @@ public void equals_true() throws IOException {
175
171
}
176
172
177
173
@ Test
178
- public void equals_false_scopes () throws IOException {
174
+ void equals_false_scopes () {
179
175
Collection <String > emptyScopes = Collections .emptyList ();
180
176
Collection <String > scopes = Collections .singleton ("SomeScope" );
181
177
MockAppIdentityService appIdentity = new MockAppIdentityService ();
@@ -195,7 +191,7 @@ public void equals_false_scopes() throws IOException {
195
191
}
196
192
197
193
@ Test
198
- public void toString_containsFields () throws IOException {
194
+ void toString_containsFields () {
199
195
String expectedToString =
200
196
String .format (
201
197
"AppEngineCredentials{scopes=[%s], scopesRequired=%b, appIdentityServiceClassName=%s}" ,
@@ -213,7 +209,7 @@ public void toString_containsFields() throws IOException {
213
209
}
214
210
215
211
@ Test
216
- public void hashCode_equals () throws IOException {
212
+ void hashCode_equals () {
217
213
Collection <String > emptyScopes = Collections .emptyList ();
218
214
MockAppIdentityService appIdentity = new MockAppIdentityService ();
219
215
AppEngineCredentials credentials =
@@ -230,7 +226,7 @@ public void hashCode_equals() throws IOException {
230
226
}
231
227
232
228
@ Test
233
- public void serialize () throws IOException , ClassNotFoundException {
229
+ void serialize () throws IOException , ClassNotFoundException {
234
230
Collection <String > scopes = Collections .singleton ("SomeScope" );
235
231
MockAppIdentityService appIdentity = new MockAppIdentityService ();
236
232
AppEngineCredentials credentials =
@@ -249,14 +245,7 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
249
245
assertNotNull (token );
250
246
String expectedValue = "Bearer " + token ;
251
247
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" );
261
250
}
262
251
}
0 commit comments