3131
3232package 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
3738import com .google .api .client .http .HttpHeaders ;
3839import com .google .api .client .http .HttpResponseException ;
4546import java .io .ByteArrayInputStream ;
4647import java .io .IOException ;
4748import java .io .InputStream ;
48- import java .io .UnsupportedEncodingException ;
4949import java .net .URLDecoder ;
50+ import java .nio .charset .StandardCharsets ;
5051import java .text .SimpleDateFormat ;
5152import java .util .Calendar ;
5253import 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 {
0 commit comments