// Path: oauth2_http/javatests/com/google/auth/TestUtils.java
// public class TestUtils {
// 
//   private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
// 
//   public static void assertContainsBearerToken(Map<String, List<String>> metadata, String token) {
//     assertNotNull(metadata);
//     assertNotNull(token);
//     assertTrue(hasBearerToken(metadata, token), "Bearer token not found");
//   }
// 
//   public static void assertNotContainsBearerToken(
//       Map<String, List<String>> metadata, String token) {
//     assertNotNull(metadata);
//     assertNotNull(token);
//     assertFalse(hasBearerToken(metadata, token), "Bearer token found");
//   }
// 
//   private static boolean hasBearerToken(Map<String, List<String>> metadata, String token) {
//     String expectedValue = AuthHttpConstants.BEARER + " " + token;
//     List<String> authorizations = metadata.get(AuthHttpConstants.AUTHORIZATION);
//     assertNotNull(authorizations, "Authorization headers not found");
//     return authorizations.contains(expectedValue);
//   }
// 
//   public static InputStream jsonToInputStream(GenericJson json) throws IOException {
//     json.setFactory(JSON_FACTORY);
//     String text = json.toPrettyString();
//     return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
//   }
// 
//   public static InputStream stringToInputStream(String text) {
//     return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
//   }
// 
//   public static Map<String, String> parseQuery(String query) throws IOException {
//     Map<String, String> map = new HashMap<>();
//     Iterable<String> entries = Splitter.on('&').split(query);
//     for (String entry : entries) {
//       List<String> sides = Lists.newArrayList(Splitter.on('=').split(entry));
//       if (sides.size() != 2) {
//         throw new IOException("Invalid Query String");
//       }
//       String key = URLDecoder.decode(sides.get(0), "UTF-8");
//       String value = URLDecoder.decode(sides.get(1), "UTF-8");
//       map.put(key, value);
//     }
//     return map;
//   }
// 
//   public static String errorJson(String message) throws IOException {
//     GenericJson errorResponse = new GenericJson();
//     errorResponse.setFactory(JSON_FACTORY);
//     GenericJson errorObject = new GenericJson();
//     errorObject.put("message", message);
//     errorResponse.put("error", errorObject);
//     return errorResponse.toPrettyString();
//   }
// 
//   public static HttpResponseException buildHttpResponseException(
//       String error, @Nullable String errorDescription, @Nullable String errorUri)
//       throws IOException {
//     GenericJson json = new GenericJson();
//     json.setFactory(GsonFactory.getDefaultInstance());
//     json.set("error", error);
//     if (errorDescription != null) {
//       json.set("error_description", errorDescription);
//     }
//     if (errorUri != null) {
//       json.set("error_uri", errorUri);
//     }
//     return new HttpResponseException.Builder(
//             /* statusCode= */ 400, /* statusMessage= */ "statusMessage", new HttpHeaders())
//         .setContent(json.toPrettyString())
//         .build();
//   }
// 
//   public static String getDefaultExpireTime() {
//     Calendar calendar = Calendar.getInstance();
//     calendar.setTime(new Date());
//     calendar.add(Calendar.SECOND, 300);
//     return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(calendar.getTime());
//   }
// 
//   private TestUtils() {}
// }


import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.http.LowLevelHttpRequest;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
import com.google.auth.TestUtils;
import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Queue;
              GenericJson response = new GenericJson();
              response.setFactory(JSON_FACTORY);
              response.put("AccessKeyId", "accessKeyId");
              response.put("SecretAccessKey", "secretAccessKey");
              response.put("Token", "token");

              return new MockLowLevelHttpResponse()
                  .setContentType(Json.MEDIA_TYPE)
                  .setContent(response.toString());
            }

            if (METADATA_SERVER_URL.equals(url)) {
              String metadataRequestHeader = getFirstHeaderValue("Metadata-Flavor");
              if (!"Google".equals(metadataRequestHeader)) {
                throw new IOException("Metadata request header not found.");
              }

              if (metadataServerContentType != null && metadataServerContentType.equals("json")) {
                GenericJson response = new GenericJson();
                response.setFactory(JSON_FACTORY);
                response.put("subjectToken", SUBJECT_TOKEN);
                return new MockLowLevelHttpResponse()
                    .setContentType(Json.MEDIA_TYPE)
                    .setContent(response.toString());
              }
              return new MockLowLevelHttpResponse()
                  .setContentType("text/html")
                  .setContent(SUBJECT_TOKEN);
            }
            if (STS_URL.equals(url)) {
// Path: oauth2_http/javatests/com/google/auth/TestUtils.java
// public class TestUtils {
// 
//   private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
// 
//   public static void assertContainsBearerToken(Map<String, List<String>> metadata, String token) {
//     assertNotNull(metadata);
//     assertNotNull(token);
//     assertTrue(hasBearerToken(metadata, token), "Bearer token not found");
//   }
// 
//   public static void assertNotContainsBearerToken(
//       Map<String, List<String>> metadata, String token) {
//     assertNotNull(metadata);
//     assertNotNull(token);
//     assertFalse(hasBearerToken(metadata, token), "Bearer token found");
//   }
// 
//   private static boolean hasBearerToken(Map<String, List<String>> metadata, String token) {
//     String expectedValue = AuthHttpConstants.BEARER + " " + token;
//     List<String> authorizations = metadata.get(AuthHttpConstants.AUTHORIZATION);
//     assertNotNull(authorizations, "Authorization headers not found");
//     return authorizations.contains(expectedValue);
//   }
// 
//   public static InputStream jsonToInputStream(GenericJson json) throws IOException {
//     json.setFactory(JSON_FACTORY);
//     String text = json.toPrettyString();
//     return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
//   }
// 
//   public static InputStream stringToInputStream(String text) {
//     return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
//   }
// 
//   public static Map<String, String> parseQuery(String query) throws IOException {
//     Map<String, String> map = new HashMap<>();
//     Iterable<String> entries = Splitter.on('&').split(query);
//     for (String entry : entries) {
//       List<String> sides = Lists.newArrayList(Splitter.on('=').split(entry));
//       if (sides.size() != 2) {
//         throw new IOException("Invalid Query String");
//       }
//       String key = URLDecoder.decode(sides.get(0), "UTF-8");
//       String value = URLDecoder.decode(sides.get(1), "UTF-8");
//       map.put(key, value);
//     }
//     return map;
//   }
// 
//   public static String errorJson(String message) throws IOException {
//     GenericJson errorResponse = new GenericJson();
//     errorResponse.setFactory(JSON_FACTORY);
//     GenericJson errorObject = new GenericJson();
//     errorObject.put("message", message);
//     errorResponse.put("error", errorObject);
//     return errorResponse.toPrettyString();
//   }
// 
//   public static HttpResponseException buildHttpResponseException(
//       String error, @Nullable String errorDescription, @Nullable String errorUri)
//       throws IOException {
//     GenericJson json = new GenericJson();
//     json.setFactory(GsonFactory.getDefaultInstance());
//     json.set("error", error);
//     if (errorDescription != null) {
//       json.set("error_description", errorDescription);
//     }
//     if (errorUri != null) {
//       json.set("error_uri", errorUri);
//     }
//     return new HttpResponseException.Builder(
//             /* statusCode= */ 400, /* statusMessage= */ "statusMessage", new HttpHeaders())
//         .setContent(json.toPrettyString())
//         .build();
//   }
// 
//   public static String getDefaultExpireTime() {
//     Calendar calendar = Calendar.getInstance();
//     calendar.setTime(new Date());
//     calendar.add(Calendar.SECOND, 300);
//     return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(calendar.getTime());
//   }
// 
//   private TestUtils() {}
// }


// Path: oauth2_http/javatests/com/google/auth/oauth2/MockExternalAccountCredentialsTransport.java
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.api.client.http.LowLevelHttpRequest;
import com.google.api.client.http.LowLevelHttpResponse;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.Json;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.testing.http.MockHttpTransport;
import com.google.api.client.testing.http.MockLowLevelHttpRequest;
import com.google.api.client.testing.http.MockLowLevelHttpResponse;
import com.google.auth.TestUtils;
import com.google.common.base.Joiner;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Queue;

              GenericJson response = new GenericJson();
              response.setFactory(JSON_FACTORY);
              response.put("AccessKeyId", "accessKeyId");
              response.put("SecretAccessKey", "secretAccessKey");
              response.put("Token", "token");

              return new MockLowLevelHttpResponse()
                  .setContentType(Json.MEDIA_TYPE)
                  .setContent(response.toString());
            }

            if (METADATA_SERVER_URL.equals(url)) {
              String metadataRequestHeader = getFirstHeaderValue("Metadata-Flavor");
              if (!"Google".equals(metadataRequestHeader)) {
                throw new IOException("Metadata request header not found.");
              }

              if (metadataServerContentType != null && metadataServerContentType.equals("json")) {
                GenericJson response = new GenericJson();
                response.setFactory(JSON_FACTORY);
                response.put("subjectToken", SUBJECT_TOKEN);
                return new MockLowLevelHttpResponse()
                    .setContentType(Json.MEDIA_TYPE)
                    .setContent(response.toString());
              }
              return new MockLowLevelHttpResponse()
                  .setContentType("text/html")
                  .setContent(SUBJECT_TOKEN);
            }
            if (STS_URL.equals(url)) {
              Map<String, String> query = TestUtils.parseQuery(getContentAsString());