| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,8 +31,9 @@ | |||
| 31 | 31 | ||
| 32 | 32 | package com.google.auth; | |
| 33 | 33 | ||
| 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; | ||
| 36 | 37 | ||
| 37 | 38 | import com.google.api.client.http.HttpHeaders; | |
| 38 | 39 | import com.google.api.client.http.HttpResponseException; | |
@@ -45,8 +46,8 @@ | |||
| 45 | 46 | import java.io.ByteArrayInputStream; | |
| 46 | 47 | import java.io.IOException; | |
| 47 | 48 | import java.io.InputStream; | |
| 48 | - import java.io.UnsupportedEncodingException; | ||
| 49 | 49 | import java.net.URLDecoder; | |
| 50 | + import java.nio.charset.StandardCharsets; | ||
| 50 | 51 | import java.text.SimpleDateFormat; | |
| 51 | 52 | import java.util.Calendar; | |
| 52 | 53 | import java.util.Date; | |
@@ -63,40 +64,31 @@ public class TestUtils { | |||
| 63 | 64 | public static void assertContainsBearerToken(Map<String, List<String>> metadata, String token) { | |
| 64 | 65 | assertNotNull(metadata); | |
| 65 | 66 | assertNotNull(token); | |
| 66 | - assertTrue("Bearer token not found", hasBearerToken(metadata, token)); | ||
| 67 | + assertTrue(hasBearerToken(metadata, token), "Bearer token not found"); | ||
| 67 | 68 | } | |
| 68 | 69 | ||
| 69 | 70 | public static void assertNotContainsBearerToken( | |
| 70 | 71 | Map<String, List<String>> metadata, String token) { | |
| 71 | 72 | assertNotNull(metadata); | |
| 72 | 73 | assertNotNull(token); | |
| 73 | - assertTrue("Bearer token found", !hasBearerToken(metadata, token)); | ||
| 74 | + assertFalse(hasBearerToken(metadata, token), "Bearer token found"); | ||
| 74 | 75 | } | |
| 75 | 76 | ||
| 76 | 77 | private static boolean hasBearerToken(Map<String, List<String>> metadata, String token) { | |
| 77 | 78 | String expectedValue = AuthHttpConstants.BEARER + " " + token; | |
| 78 | 79 | 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); | ||
| 86 | 82 | } | |
| 87 | 83 | ||
| 88 | 84 | public static InputStream jsonToInputStream(GenericJson json) throws IOException { | |
| 89 | 85 | json.setFactory(JSON_FACTORY); | |
| 90 | 86 | String text = json.toPrettyString(); | |
| 91 | - return new ByteArrayInputStream(text.getBytes("UTF-8")); | ||
| 87 | + return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8)); | ||
| 92 | 88 | } | |
| 93 | 89 | ||
| 94 | 90 | 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)); | ||
| 100 | 92 | } | |
| 101 | 93 | ||
| 102 | 94 | public static Map<String, String> parseQuery(String query) throws IOException { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,9 +31,9 @@ | |||
| 31 | 31 | ||
| 32 | 32 | package com.google.auth.oauth2; | |
| 33 | 33 | ||
| 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; | ||
| 37 | 37 | ||
| 38 | 38 | import com.google.api.client.http.LowLevelHttpRequest; | |
| 39 | 39 | import com.google.api.client.http.LowLevelHttpResponse; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,8 +31,8 @@ | |||
| 31 | 31 | ||
| 32 | 32 | package com.google.auth.oauth2; | |
| 33 | 33 | ||
| 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; | ||
| 36 | 36 | ||
| 37 | 37 | import com.google.api.client.http.HttpStatusCodes; | |
| 38 | 38 | import com.google.api.client.http.LowLevelHttpRequest; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments