31
31
32
32
package com .google .auth .oauth2 ;
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 .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 ;
40
40
41
41
import com .google .common .collect .ImmutableMap ;
42
42
import java .io .IOException ;
47
47
import java .util .Date ;
48
48
import java .util .List ;
49
49
import 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 ;
53
51
54
- @ RunWith (JUnit4 .class )
55
- public class AppEngineCredentialsTest extends BaseSerializationTest {
52
+ class AppEngineCredentialsTest extends BaseSerializationTest {
56
53
57
54
private static final String EXPECTED_ACCESS_TOKEN = "ExpectedAccessToken" ;
58
55
private static final Date EXPECTED_EXPIRATION_DATE =
@@ -66,7 +63,7 @@ public class AppEngineCredentialsTest extends BaseSerializationTest {
66
63
Collections .unmodifiableCollection (Arrays .asList ("scope3" ));
67
64
68
65
@ Test
69
- public void constructor_usesAppIdentityService () throws IOException {
66
+ void constructor_usesAppIdentityService () throws IOException {
70
67
Collection <String > scopes = Collections .singleton ("SomeScope" );
71
68
TestAppEngineCredentials credentials = new TestAppEngineCredentials (scopes );
72
69
List <String > forNameArgs = credentials .getForNameArgs ();
@@ -78,51 +75,50 @@ public void constructor_usesAppIdentityService() throws IOException {
78
75
}
79
76
80
77
@ 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 ));
94
92
}
95
93
96
94
@ Test
97
- public void refreshAccessToken_sameAs () throws IOException {
95
+ void refreshAccessToken_sameAs () throws IOException {
98
96
TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
99
97
AccessToken accessToken = credentials .refreshAccessToken ();
100
98
assertEquals (EXPECTED_ACCESS_TOKEN , accessToken .getTokenValue ());
101
99
assertEquals (EXPECTED_EXPIRATION_DATE , accessToken .getExpirationTime ());
102
100
}
103
101
104
102
@ Test
105
- public void getAccount_sameAs () throws IOException {
103
+ void getAccount_sameAs () throws IOException {
106
104
TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
107
105
assertEquals (EXPECTED_ACCOUNT , credentials .getAccount ());
108
106
}
109
107
110
108
@ Test
111
- public void sign_sameAs () throws IOException {
109
+ void sign_sameAs () throws IOException {
112
110
TestAppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
113
111
assertArrayEquals (EXPECTED_SIGNATURE , credentials .sign ("Bytes to sign" .getBytes ()));
114
112
}
115
113
116
114
@ Test
117
- public void createScoped_clonesWithScopes () throws IOException {
115
+ void createScoped_clonesWithScopes () throws IOException {
118
116
TestAppEngineCredentials credentials = new TestAppEngineCredentials (null );
119
117
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." );
126
122
127
123
GoogleCredentials scopedCredentials = credentials .createScoped (SCOPES );
128
124
assertNotSame (credentials , scopedCredentials );
@@ -133,7 +129,7 @@ public void createScoped_clonesWithScopes() throws IOException {
133
129
}
134
130
135
131
@ Test
136
- public void createScoped_defaultScopes () throws IOException {
132
+ void createScoped_defaultScopes () throws IOException {
137
133
TestAppEngineCredentials credentials = new TestAppEngineCredentials (null );
138
134
assertTrue (credentials .createScopedRequired ());
139
135
@@ -152,7 +148,7 @@ public void createScoped_defaultScopes() throws IOException {
152
148
}
153
149
154
150
@ Test
155
- public void equals_true () throws IOException {
151
+ void equals_true () throws IOException {
156
152
GoogleCredentials credentials = new TestAppEngineCredentials (SCOPES );
157
153
GoogleCredentials otherCredentials = new TestAppEngineCredentials (SCOPES );
158
154
assertTrue (credentials .equals (credentials ));
@@ -161,7 +157,7 @@ public void equals_true() throws IOException {
161
157
}
162
158
163
159
@ Test
164
- public void equals_false_scopes () throws IOException {
160
+ void equals_false_scopes () throws IOException {
165
161
final Collection <String > emptyScopes = Collections .emptyList ();
166
162
Collection <String > scopes = Collections .singleton ("SomeScope" );
167
163
AppEngineCredentials credentials = new TestAppEngineCredentials (emptyScopes );
@@ -171,7 +167,7 @@ public void equals_false_scopes() throws IOException {
171
167
}
172
168
173
169
@ Test
174
- public void toString_containsFields () throws IOException {
170
+ void toString_containsFields () throws IOException {
175
171
String expectedToString =
176
172
String .format (
177
173
"TestAppEngineCredentials{scopes=[%s], scopesRequired=%b}" , "SomeScope" , false );
@@ -181,13 +177,13 @@ public void toString_containsFields() throws IOException {
181
177
}
182
178
183
179
@ Test
184
- public void hashCode_equals () throws IOException {
180
+ void hashCode_equals () throws IOException {
185
181
AppEngineCredentials credentials = new TestAppEngineCredentials (SCOPES );
186
182
assertEquals (credentials .hashCode (), credentials .hashCode ());
187
183
}
188
184
189
185
@ Test
190
- public void serialize () throws IOException , ClassNotFoundException {
186
+ void serialize () throws IOException , ClassNotFoundException {
191
187
Collection <String > scopes = Collections .singleton ("SomeScope" );
192
188
AppEngineCredentials credentials = new TestAppEngineCredentials (scopes );
193
189
GoogleCredentials deserializedCredentials = serializeAndDeserialize (credentials );
0 commit comments