Skip to content

Commit 53355a7

Browse files
authored
refactor: Revert JUnit5 to JUnit4 (#969)
* refactor: Revert JUnit5 to JUnit4 Refactored tests added since 928dd04 to use JUnit4 instead of JUnit5. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - sixth iteration (#756) (#769)" This reverts commit 928dd04. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - fifth iteration (#756) (#767)" This reverts commit 59dfb35. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - fourth iteration (#756) (#766)" This reverts commit d7edc45. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - third iteration (#756) (#764)" This reverts commit e9dfaf9. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - second iteration (#756) (#763)" This reverts commit d045247. Revert "chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - first iteration (#756) (#762)" This reverts commit 4e6576f. Revert "refactor: migration tests in credentials module from JUnit4 to JUnit5 (#756) (#761)" This reverts commit a64d35c. Revert "refactor: migration tests in appengine module from JUnit4 to JUnit5 (#756) (#760)" This reverts commit cccaa44.
1 parent 1f4c9c7 commit 53355a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2261
-2072
lines changed

appengine/javatests/com/google/auth/appengine/AppEngineCredentialsTest.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131

3232
package com.google.auth.appengine;
3333

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;
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;
4141

4242
import com.google.auth.Credentials;
4343
import com.google.auth.oauth2.AccessToken;
@@ -51,18 +51,21 @@
5151
import java.util.Date;
5252
import java.util.List;
5353
import java.util.Map;
54-
import org.junit.jupiter.api.Test;
54+
import org.junit.Test;
55+
import org.junit.runner.RunWith;
56+
import org.junit.runners.JUnit4;
5557

5658
/** Unit tests for AppEngineCredentials */
57-
class AppEngineCredentialsTest extends BaseSerializationTest {
59+
@RunWith(JUnit4.class)
60+
public class AppEngineCredentialsTest extends BaseSerializationTest {
5861

5962
private static Collection<String> SCOPES =
6063
Collections.unmodifiableCollection(Arrays.asList("scope1", "scope2"));
6164
private static final URI CALL_URI = URI.create("http://googleapis.com/testapi/v1/foo");
6265
private static final String EXPECTED_ACCOUNT = "serviceAccount";
6366

6467
@Test
65-
void constructor_usesAppIdentityService() throws IOException {
68+
public void constructor_usesAppIdentityService() throws IOException {
6669
String expectedAccessToken = "ExpectedAccessToken";
6770

6871
MockAppIdentityService appIdentity = new MockAppIdentityService();
@@ -80,7 +83,7 @@ void constructor_usesAppIdentityService() throws IOException {
8083
}
8184

8285
@Test
83-
void refreshAccessToken_sameAs() throws IOException {
86+
public void refreshAccessToken_sameAs() throws IOException {
8487
String expectedAccessToken = "ExpectedAccessToken";
8588

8689
MockAppIdentityService appIdentity = new MockAppIdentityService();
@@ -97,7 +100,7 @@ void refreshAccessToken_sameAs() throws IOException {
97100
}
98101

99102
@Test
100-
void getAccount_sameAs() {
103+
public void getAccount_sameAs() throws IOException {
101104
MockAppIdentityService appIdentity = new MockAppIdentityService();
102105
appIdentity.setServiceAccountName(EXPECTED_ACCOUNT);
103106
AppEngineCredentials credentials =
@@ -109,7 +112,7 @@ void getAccount_sameAs() {
109112
}
110113

111114
@Test
112-
void sign_sameAs() {
115+
public void sign_sameAs() throws IOException {
113116
byte[] expectedSignature = {0xD, 0xE, 0xA, 0xD};
114117
MockAppIdentityService appIdentity = new MockAppIdentityService();
115118
appIdentity.setSignature(expectedSignature);
@@ -122,7 +125,7 @@ void sign_sameAs() {
122125
}
123126

124127
@Test
125-
void createScoped_clonesWithScopes() throws IOException {
128+
public void createScoped_clonesWithScopes() throws IOException {
126129
String expectedAccessToken = "ExpectedAccessToken";
127130
Collection<String> emptyScopes = Collections.emptyList();
128131

@@ -135,10 +138,11 @@ void createScoped_clonesWithScopes() throws IOException {
135138
.setAppIdentityService(appIdentity)
136139
.build();
137140
assertTrue(credentials.createScopedRequired());
138-
assertThrows(
139-
Exception.class,
140-
() -> credentials.getRequestMetadata(CALL_URI),
141-
"Should not be able to use credential without scopes.");
141+
try {
142+
credentials.getRequestMetadata(CALL_URI);
143+
fail("Should not be able to use credential without scopes.");
144+
} catch (Exception expected) {
145+
}
142146
assertEquals(0, appIdentity.getGetAccessTokenCallCount());
143147

144148
GoogleCredentials scopedCredentials = credentials.createScoped(SCOPES);
@@ -151,7 +155,7 @@ void createScoped_clonesWithScopes() throws IOException {
151155
}
152156

153157
@Test
154-
void equals_true() {
158+
public void equals_true() throws IOException {
155159
Collection<String> emptyScopes = Collections.emptyList();
156160
MockAppIdentityService appIdentity = new MockAppIdentityService();
157161

@@ -171,7 +175,7 @@ void equals_true() {
171175
}
172176

173177
@Test
174-
void equals_false_scopes() {
178+
public void equals_false_scopes() throws IOException {
175179
Collection<String> emptyScopes = Collections.emptyList();
176180
Collection<String> scopes = Collections.singleton("SomeScope");
177181
MockAppIdentityService appIdentity = new MockAppIdentityService();
@@ -191,7 +195,7 @@ void equals_false_scopes() {
191195
}
192196

193197
@Test
194-
void toString_containsFields() {
198+
public void toString_containsFields() throws IOException {
195199
String expectedToString =
196200
String.format(
197201
"AppEngineCredentials{scopes=[%s], scopesRequired=%b, appIdentityServiceClassName=%s}",
@@ -209,7 +213,7 @@ void toString_containsFields() {
209213
}
210214

211215
@Test
212-
void hashCode_equals() {
216+
public void hashCode_equals() throws IOException {
213217
Collection<String> emptyScopes = Collections.emptyList();
214218
MockAppIdentityService appIdentity = new MockAppIdentityService();
215219
AppEngineCredentials credentials =
@@ -226,7 +230,7 @@ void hashCode_equals() {
226230
}
227231

228232
@Test
229-
void serialize() throws IOException, ClassNotFoundException {
233+
public void serialize() throws IOException, ClassNotFoundException {
230234
Collection<String> scopes = Collections.singleton("SomeScope");
231235
MockAppIdentityService appIdentity = new MockAppIdentityService();
232236
AppEngineCredentials credentials =
@@ -245,7 +249,7 @@ private static void assertContainsBearerToken(Map<String, List<String>> metadata
245249
assertNotNull(token);
246250
String expectedValue = "Bearer " + token;
247251
List<String> authorizations = metadata.get("Authorization");
248-
assertNotNull(authorizations, "Authorization headers not found");
249-
assertTrue(authorizations.contains(expectedValue), "Bearer token not found");
252+
assertNotNull("Authorization headers not found", authorizations);
253+
assertTrue("Bearer token not found", authorizations.contains(expectedValue));
250254
}
251255
}

appengine/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
<artifactId>guava</artifactId>
6969
</dependency>
7070
<dependency>
71-
<groupId>org.junit.jupiter</groupId>
72-
<artifactId>junit-jupiter-api</artifactId>
71+
<groupId>junit</groupId>
72+
<artifactId>junit</artifactId>
7373
<scope>test</scope>
7474
</dependency>
7575
<dependency>

credentials/javatests/com/google/auth/SigningExceptionTest.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,45 @@
3131

3232
package com.google.auth;
3333

34-
import static org.junit.jupiter.api.Assertions.assertEquals;
35-
import static org.junit.jupiter.api.Assertions.assertFalse;
36-
import static org.junit.jupiter.api.Assertions.assertSame;
37-
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertFalse;
36+
import static org.junit.Assert.assertSame;
37+
import static org.junit.Assert.assertTrue;
3838

3939
import com.google.auth.ServiceAccountSigner.SigningException;
40-
import org.junit.jupiter.api.Test;
40+
import java.io.IOException;
41+
import org.junit.Test;
4142

42-
class SigningExceptionTest {
43+
public class SigningExceptionTest {
4344

4445
private static final String EXPECTED_MESSAGE = "message";
4546
private static final RuntimeException EXPECTED_CAUSE = new RuntimeException();
4647

4748
@Test
48-
void constructor() {
49+
public void constructor() {
4950
SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
5051
assertEquals(EXPECTED_MESSAGE, signingException.getMessage());
5152
assertSame(EXPECTED_CAUSE, signingException.getCause());
5253
}
5354

5455
@Test
55-
void equals_true() {
56+
public void equals_true() throws IOException {
5657
SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
5758
SigningException otherSigningException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
5859
assertTrue(signingException.equals(otherSigningException));
5960
assertTrue(otherSigningException.equals(signingException));
6061
}
6162

6263
@Test
63-
void equals_false_message() {
64+
public void equals_false_message() throws IOException {
6465
SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
6566
SigningException otherSigningException = new SigningException("otherMessage", EXPECTED_CAUSE);
6667
assertFalse(signingException.equals(otherSigningException));
6768
assertFalse(otherSigningException.equals(signingException));
6869
}
6970

7071
@Test
71-
void equals_false_cause() {
72+
public void equals_false_cause() throws IOException {
7273
SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
7374
SigningException otherSigningException =
7475
new SigningException("otherMessage", new RuntimeException());
@@ -77,7 +78,7 @@ void equals_false_cause() {
7778
}
7879

7980
@Test
80-
void hashCode_equals() {
81+
public void hashCode_equals() throws IOException {
8182
SigningException signingException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
8283
SigningException otherSigningException = new SigningException(EXPECTED_MESSAGE, EXPECTED_CAUSE);
8384
assertEquals(signingException.hashCode(), otherSigningException.hashCode());

credentials/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050

5151
<dependencies>
5252
<dependency>
53-
<groupId>org.junit.jupiter</groupId>
54-
<artifactId>junit-jupiter-api</artifactId>
53+
<groupId>junit</groupId>
54+
<artifactId>junit</artifactId>
5555
<scope>test</scope>
5656
</dependency>
5757
</dependencies>

oauth2_http/javatests/com/google/auth/TestUtils.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131

3232
package com.google.auth;
3333

34-
import static org.junit.jupiter.api.Assertions.assertFalse;
35-
import static org.junit.jupiter.api.Assertions.assertNotNull;
36-
import static org.junit.jupiter.api.Assertions.assertTrue;
34+
import static org.junit.Assert.assertFalse;
35+
import static org.junit.Assert.assertNotNull;
36+
import static org.junit.Assert.assertTrue;
3737

3838
import com.google.api.client.http.HttpHeaders;
3939
import com.google.api.client.http.HttpResponseException;
@@ -46,8 +46,8 @@
4646
import java.io.ByteArrayInputStream;
4747
import java.io.IOException;
4848
import java.io.InputStream;
49+
import java.io.UnsupportedEncodingException;
4950
import java.net.URLDecoder;
50-
import java.nio.charset.StandardCharsets;
5151
import java.text.SimpleDateFormat;
5252
import java.util.Calendar;
5353
import java.util.Date;
@@ -64,31 +64,35 @@ public class TestUtils {
6464
public static void assertContainsBearerToken(Map<String, List<String>> metadata, String token) {
6565
assertNotNull(metadata);
6666
assertNotNull(token);
67-
assertTrue(hasBearerToken(metadata, token), "Bearer token not found");
67+
assertTrue("Bearer token not found", hasBearerToken(metadata, token));
6868
}
6969

7070
public static void assertNotContainsBearerToken(
7171
Map<String, List<String>> metadata, String token) {
7272
assertNotNull(metadata);
7373
assertNotNull(token);
74-
assertFalse(hasBearerToken(metadata, token), "Bearer token found");
74+
assertFalse("Bearer token found", hasBearerToken(metadata, token));
7575
}
7676

7777
private static boolean hasBearerToken(Map<String, List<String>> metadata, String token) {
7878
String expectedValue = AuthHttpConstants.BEARER + " " + token;
7979
List<String> authorizations = metadata.get(AuthHttpConstants.AUTHORIZATION);
80-
assertNotNull(authorizations, "Authorization headers not found");
80+
assertNotNull("Authorization headers not found", authorizations);
8181
return authorizations.contains(expectedValue);
8282
}
8383

8484
public static InputStream jsonToInputStream(GenericJson json) throws IOException {
8585
json.setFactory(JSON_FACTORY);
8686
String text = json.toPrettyString();
87-
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
87+
return new ByteArrayInputStream(text.getBytes("UTF-8"));
8888
}
8989

9090
public static InputStream stringToInputStream(String text) {
91-
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
91+
try {
92+
return new ByteArrayInputStream(text.getBytes("UTF-8"));
93+
} catch (UnsupportedEncodingException e) {
94+
throw new RuntimeException("Unexpected encoding exception", e);
95+
}
9296
}
9397

9498
public static Map<String, String> parseQuery(String query) throws IOException {

oauth2_http/javatests/com/google/auth/http/HttpCredentialsAdapterTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
package com.google.auth.http;
3333

3434
import static org.hamcrest.CoreMatchers.instanceOf;
35-
import static org.hamcrest.MatcherAssert.assertThat;
36-
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
import static org.junit.Assert.assertEquals;
36+
import static org.junit.Assert.assertThat;
3737

3838
import com.google.api.client.http.GenericUrl;
3939
import com.google.api.client.http.HttpHeaders;
@@ -47,17 +47,20 @@
4747
import com.google.auth.oauth2.OAuth2Credentials;
4848
import com.google.auth.oauth2.UserCredentials;
4949
import java.io.IOException;
50-
import org.junit.jupiter.api.Test;
50+
import org.junit.Test;
51+
import org.junit.runner.RunWith;
52+
import org.junit.runners.JUnit4;
5153

5254
/** Test case for {@link HttpCredentialsAdapter}. */
53-
class HttpCredentialsAdapterTest {
55+
@RunWith(JUnit4.class)
56+
public class HttpCredentialsAdapterTest {
5457

5558
private static final String CLIENT_SECRET = "jakuaL9YyieakhECKL2SwZcu";
5659
private static final String CLIENT_ID = "ya29.1.AADtN_UtlxN3PuGAxrN2XQnZTVRvDyVWnYq4I6dws";
5760
private static final String REFRESH_TOKEN = "1/Tl6awhpFjkMkSJoj1xsli0H2eL5YsMgU_NKPY2TyGWY";
5861

5962
@Test
60-
void initialize_populatesOAuth2Credentials() throws IOException {
63+
public void initialize_populatesOAuth2Credentials() throws IOException {
6164
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
6265
final String expectedAuthorization = InternalAuthHttpConstants.BEARER_PREFIX + accessToken;
6366
MockTokenServerTransportFactory transportFactory = new MockTokenServerTransportFactory();
@@ -84,7 +87,7 @@ void initialize_populatesOAuth2Credentials() throws IOException {
8487
}
8588

8689
@Test
87-
void initialize_populatesOAuth2Credentials_handle401() throws IOException {
90+
public void initialize_populatesOAuth2Credentials_handle401() throws IOException {
8891
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
8992
final String accessToken2 = "2/MkSJoj1xsli0AccessToken_NKPY2";
9093

@@ -122,7 +125,7 @@ void initialize_populatesOAuth2Credentials_handle401() throws IOException {
122125
}
123126

124127
@Test
125-
void initialize_noURI() throws IOException {
128+
public void initialize_noURI() throws IOException {
126129
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
127130
final String expectedAuthorization = InternalAuthHttpConstants.BEARER_PREFIX + accessToken;
128131
MockTokenServerTransportFactory tokenServerTransportFactory =
@@ -151,7 +154,7 @@ void initialize_noURI() throws IOException {
151154
}
152155

153156
@Test
154-
void getCredentials() {
157+
public void getCredentials() {
155158
final String accessToken = "1/MkSJoj1xsli0AccessToken_NKPY2";
156159
MockTokenServerTransportFactory tokenServerTransportFactory =
157160
new MockTokenServerTransportFactory();

0 commit comments

Comments
 (0)