Skip to content

Commit 928dd04

Browse files
authored
chore: migrate tests in oauth2_http module from JUnit4 to JUnit5 - sixth iteration (googleapis#756) (googleapis#769)
1 parent 59dfb35 commit 928dd04

10 files changed

+303
-378
lines changed

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

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

3232
package com.google.auth;
3333

34-
import static org.junit.Assert.assertNotNull;
35-
import static org.junit.Assert.assertTrue;
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;
3637

3738
import com.google.api.client.http.HttpHeaders;
3839
import com.google.api.client.http.HttpResponseException;
@@ -45,8 +46,8 @@
4546
import java.io.ByteArrayInputStream;
4647
import java.io.IOException;
4748
import java.io.InputStream;
48-
import java.io.UnsupportedEncodingException;
4949
import java.net.URLDecoder;
50+
import java.nio.charset.StandardCharsets;
5051
import java.text.SimpleDateFormat;
5152
import java.util.Calendar;
5253
import java.util.Date;
@@ -63,40 +64,31 @@ public class TestUtils {
6364
public static void assertContainsBearerToken(Map<String, List<String>> metadata, String token) {
6465
assertNotNull(metadata);
6566
assertNotNull(token);
66-
assertTrue("Bearer token not found", hasBearerToken(metadata, token));
67+
assertTrue(hasBearerToken(metadata, token), "Bearer token not found");
6768
}
6869

6970
public static void assertNotContainsBearerToken(
7071
Map<String, List<String>> metadata, String token) {
7172
assertNotNull(metadata);
7273
assertNotNull(token);
73-
assertTrue("Bearer token found", !hasBearerToken(metadata, token));
74+
assertFalse(hasBearerToken(metadata, token), "Bearer token found");
7475
}
7576

7677
private static boolean hasBearerToken(Map<String, List<String>> metadata, String token) {
7778
String expectedValue = AuthHttpConstants.BEARER + " " + token;
7879
List<String> authorizations = metadata.get(AuthHttpConstants.AUTHORIZATION);
79-
assertNotNull("Authorization headers not found", authorizations);
80-
for (String authorization : authorizations) {
81-
if (expectedValue.equals(authorization)) {
82-
return true;
83-
}
84-
}
85-
return false;
80+
assertNotNull(authorizations, "Authorization headers not found");
81+
return authorizations.contains(expectedValue);
8682
}
8783

8884
public static InputStream jsonToInputStream(GenericJson json) throws IOException {
8985
json.setFactory(JSON_FACTORY);
9086
String text = json.toPrettyString();
91-
return new ByteArrayInputStream(text.getBytes("UTF-8"));
87+
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
9288
}
9389

9490
public static InputStream stringToInputStream(String text) {
95-
try {
96-
return new ByteArrayInputStream(text.getBytes("UTF-8"));
97-
} catch (UnsupportedEncodingException e) {
98-
throw new RuntimeException("Unexpected encoding exception", e);
99-
}
91+
return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
10092
}
10193

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

oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java

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

3232
package com.google.auth.oauth2;
3333

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

3838
import com.google.api.client.http.LowLevelHttpRequest;
3939
import com.google.api.client.http.LowLevelHttpResponse;

oauth2_http/javatests/com/google/auth/oauth2/MockStsTransport.java

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

3232
package com.google.auth.oauth2;
3333

34-
import static org.junit.Assert.assertEquals;
35-
import static org.junit.Assert.assertNotNull;
34+
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3636

3737
import com.google.api.client.http.HttpStatusCodes;
3838
import com.google.api.client.http.LowLevelHttpRequest;

0 commit comments

Comments
 (0)