// Path: telemetry-test-framework/src/main/java/com/yammer/telemetry/test/TelemetryTestHelpers.java
// public static void runTransformed(Class<?> clazz, ClassInstrumentationHandler... handlers) throws Exception {
//     Method[] methods = clazz.getDeclaredMethods();
//     Map<Method, Throwable> testFailures = new HashMap<>();
//     int ran = 0;
// 
//     for (Method method : methods) {
//         if (method.isAnnotationPresent(TransformedTest.class)) {
//             try {
//                 ran++;
//                 runTransformed(clazz, method.getName(), handlers);
//             } catch (Exception e) {
//                 //noinspection ThrowableResultOfMethodCallIgnored
//                 testFailures.put(method, unwrap(e));
//             }
//         }
//     }
// 
//     if (!testFailures.isEmpty()) {
//         StringWriter builder = new StringWriter();
//         PrintWriter writer = new PrintWriter(builder);
//         writer.println("Transformed tests failed:");
//         for (Map.Entry<Method, Throwable> entry : testFailures.entrySet()) {
//             writer.printf("%s:%n%s%n%n", entry.getKey(), entry.getValue());
//             //noinspection ThrowableResultOfMethodCallIgnored
//             entry.getValue().printStackTrace(writer);
//             writer.println();
//         }
//         fail(builder.toString());
//     }
// 
//     if (ran == 0) {
//         fail("No tests were found within '" + clazz.getName() + "' that were annotated as '" + TransformedTest.class.getName() + "'");
//     }
// }


import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.yammer.telemetry.test.TransformedTest;
import com.yammer.telemetry.tracing.*;
import javassist.ClassPool;
import javassist.CtClass;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.conn.BasicClientConnectionManager;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import static com.yammer.telemetry.test.TelemetryTestHelpers.runTransformed;
import static org.junit.Assert.*;
    @Test
    public void testHttpClientSubClassDoesGetTransformedIfNonAbstractExecuteMethodExists() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(HttpClientSubClass.class.getName());
        assertTrue(handler.transform(ctClass, cp));
    }

    @Test
    public void testHttpClientAbstractSubClassDoesNotGetTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(HttpClientAbstractSubClass.class.getName());
        assertFalse(handler.transform(ctClass, cp));
    }

    @Test
    public void testHttpClientSubClassGetsTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(AbstractHttpClient.class.getName());
        assertTrue(handler.transform(ctClass, cp));
    }

    @Test
    public void testNonHttpClientClassDoesNotGetTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(String.class.getName());
        assertFalse(handler.transform(ctClass, cp));
    }

    @Test
    public void runTransformedTests() throws Exception {
// Path: telemetry-test-framework/src/main/java/com/yammer/telemetry/test/TelemetryTestHelpers.java
// public static void runTransformed(Class<?> clazz, ClassInstrumentationHandler... handlers) throws Exception {
//     Method[] methods = clazz.getDeclaredMethods();
//     Map<Method, Throwable> testFailures = new HashMap<>();
//     int ran = 0;
// 
//     for (Method method : methods) {
//         if (method.isAnnotationPresent(TransformedTest.class)) {
//             try {
//                 ran++;
//                 runTransformed(clazz, method.getName(), handlers);
//             } catch (Exception e) {
//                 //noinspection ThrowableResultOfMethodCallIgnored
//                 testFailures.put(method, unwrap(e));
//             }
//         }
//     }
// 
//     if (!testFailures.isEmpty()) {
//         StringWriter builder = new StringWriter();
//         PrintWriter writer = new PrintWriter(builder);
//         writer.println("Transformed tests failed:");
//         for (Map.Entry<Method, Throwable> entry : testFailures.entrySet()) {
//             writer.printf("%s:%n%s%n%n", entry.getKey(), entry.getValue());
//             //noinspection ThrowableResultOfMethodCallIgnored
//             entry.getValue().printStackTrace(writer);
//             writer.println();
//         }
//         fail(builder.toString());
//     }
// 
//     if (ran == 0) {
//         fail("No tests were found within '" + clazz.getName() + "' that were annotated as '" + TransformedTest.class.getName() + "'");
//     }
// }


// Path: telemetry-agent/src/test/java/com/yammer/telemetry/agent/handlers/ApacheHttpClientClassHandlerTest.java
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
import com.yammer.telemetry.test.TransformedTest;
import com.yammer.telemetry.tracing.*;
import javassist.ClassPool;
import javassist.CtClass;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.AbstractHttpClient;
import org.apache.http.impl.conn.BasicClientConnectionManager;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;
import org.junit.Test;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.util.Collection;
import java.util.List;
import static com.yammer.telemetry.test.TelemetryTestHelpers.runTransformed;
import static org.junit.Assert.*;

    @Test
    public void testHttpClientSubClassDoesGetTransformedIfNonAbstractExecuteMethodExists() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(HttpClientSubClass.class.getName());
        assertTrue(handler.transform(ctClass, cp));
    }

    @Test
    public void testHttpClientAbstractSubClassDoesNotGetTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(HttpClientAbstractSubClass.class.getName());
        assertFalse(handler.transform(ctClass, cp));
    }

    @Test
    public void testHttpClientSubClassGetsTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(AbstractHttpClient.class.getName());
        assertTrue(handler.transform(ctClass, cp));
    }

    @Test
    public void testNonHttpClientClassDoesNotGetTransformed() throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass ctClass = cp.get(String.class.getName());
        assertFalse(handler.transform(ctClass, cp));
    }

    @Test
    public void runTransformedTests() throws Exception {
        runTransformed(TransformedTests.class, handler);