// Path: telemetry-instrumentation/src/main/java/com/yammer/telemetry/instrumentation/ClassInstrumentationHandler.java
// public interface ClassInstrumentationHandler {
//     boolean transformed(CtClass cc, ClassPool pool);
// }
// 
// Path: telemetry-agent/src/main/java/com/yammer/telemetry/agent/handlers/SubTypeInstrumentationHandler.java
// public abstract class SubTypeInstrumentationHandler implements ClassInstrumentationHandler {
//     private static final Logger LOGGER = Logger.getLogger(SubTypeInstrumentationHandler.class.getName());
//     protected final String superTypeName;
//     private boolean enabled = true;
// 
//     public SubTypeInstrumentationHandler(String superTypeName) {
//         this.superTypeName = superTypeName;
//     }
// 
//     public boolean isEnabled() {
//         return enabled;
//     }
// 
//     @Override
//     public final boolean transformed(CtClass cc, ClassPool pool) {
//         try {
//             if (canTransform(cc, pool)) {
//                 return transform(cc, pool);
//             }
//         } catch (NotFoundException | CannotCompileException | IOException e) {
//             // Disable the handler for the remainder.
//             LOGGER.warning("Error instrumenting " + cc.getName() + ": " + e.toString() + " [" + getClass().getName() + "]");
//             enabled = false;
//         }
// 
//         return false;
//     }
// 
//     private boolean canTransform(CtClass cc, ClassPool pool) throws NotFoundException {
//         return isEnabled() && cc.subtypeOf(pool.get(superTypeName));
//     }
// 
//     protected abstract boolean transform(CtClass cc, ClassPool pool) throws NotFoundException, CannotCompileException, IOException;
// }
// 
// Path: telemetry-test-framework/src/main/java/com/yammer/telemetry/test/TransformingClassLoader.java
// public class TransformingClassLoader extends URLClassLoader {
//     private final TelemetryTransformer transformer;
//     private final ClassPool classPool;
// 
//     public TransformingClassLoader(TelemetryTransformer transformer) {
//         super(new URL[] {});
//         this.transformer = checkNotNull(transformer);
//         classPool = new ClassPool(null);
//         classPool.appendSystemPath();
//     }
// 
//     @Override
//     public Class<?> loadClass(String name) throws ClassNotFoundException {
//         Class<?> loadedClass = super.findLoadedClass(name);
//         if (loadedClass != null) return loadedClass;
//         try (InputStream classStream = super.getResourceAsStream(name.replace('.', '/') + ".class")) {
//             byte[] classfileBuffer = ByteStreams.toByteArray(classStream);
//             byte[] transformedBytes = transformer.transform(this, name, classfileBuffer, classPool);
// 
//             if (transformedBytes == null) {
//                 if (name.startsWith("java")) {
//                     return super.loadClass(name);
//                 }
//                 return super.defineClass(name, classfileBuffer, 0, classfileBuffer.length);
//             } else {
//                 return super.defineClass(name, transformedBytes, 0, transformedBytes.length);
//             }
//         } catch (IOException | IllegalClassFormatException | RuntimeException e) {
//             throw new ClassNotFoundException(name, e);
//         }
//     }
// }
// 
// Path: telemetry-instrumentation/src/main/java/com/yammer/telemetry/instrumentation/TelemetryTransformer.java
// public class TelemetryTransformer implements ClassFileTransformer {
//     private final Set<ClassInstrumentationHandler> handlers = new HashSet<>();
// 
//     public void addHandler(ClassInstrumentationHandler handler) {
//         handlers.add(handler);
//     }
// 
//     @Override
//     public byte[] transform(ClassLoader loader,
//                             String className,
//                             Class<?> classBeingRedefined,
//                             ProtectionDomain protectionDomain,
//                             byte[] classfileBuffer) throws IllegalClassFormatException {
//         return transform(loader, className, classfileBuffer, ClassPool.getDefault());
//     }
// 
//     /**
//      * Allows specifying the ClassPool, this allows tests to essentially 'reload' classes.
//      *
//      * @param loader
//      * @param className
//      * @param classfileBuffer
//      * @param cp
//      * @return
//      * @throws IllegalClassFormatException
//      */
//     public byte[] transform(ClassLoader loader,
//                             String className,
//                             byte[] classfileBuffer,
//                             ClassPool cp) throws IllegalClassFormatException {
//         try {
//             final String realClassName = className.replace('/', '.');
//             cp.insertClassPath(new LoaderClassPath(loader));
//             cp.insertClassPath(new ByteArrayClassPath(realClassName, classfileBuffer));
//             CtClass cc = cp.get(realClassName);
// 
//             boolean classUpdated = false;
//             for (ClassInstrumentationHandler handler : handlers) {
//                 if (classUpdated = handler.transformed(cc, cp)) {
//                     break;
//                 }
//             }
// 
//             if (classUpdated) {
//                 return cc.toBytecode();
//             } else {
//                 return null;
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//             return null;
//         } catch (Throwable t) {
//             t.printStackTrace();
//             throw t;
//         }
//     }
// }
// 
// Path: telemetry-agent/src/test/java/com/yammer/telemetry/agent/TelemetryTransformerTest.java
// public static boolean wrapMethod(CtClass cc, String method, String body) {
//     try {
//         if (cc.isFrozen()) cc.defrost();
// 
//         CtMethod getMethod = cc.getDeclaredMethod(method);
//         CtMethod copiedMethod = CtNewMethod.copy(getMethod, cc.makeUniqueName(method), cc, null);
// 
//         copiedMethod.setModifiers(Modifier.PRIVATE);
//         cc.addMethod(copiedMethod);
// 
//         getMethod.setBody(body, "this", copiedMethod.getName());
// 
//         return true;
//     } catch (NotFoundException | CannotCompileException e) {
//         throw new RuntimeException(e);
//     }
// }


import com.yammer.telemetry.instrumentation.ClassInstrumentationHandler;
import com.yammer.telemetry.agent.handlers.SubTypeInstrumentationHandler;
import com.yammer.telemetry.test.TransformingClassLoader;
import com.yammer.telemetry.instrumentation.TelemetryTransformer;
import javassist.*;
import org.junit.Test;
import java.io.IOException;
import static com.yammer.telemetry.agent.TelemetryTransformerTest.ClassUtils.wrapMethod;
import static org.junit.Assert.*;
package com.yammer.telemetry.agent;




public class TelemetryTransformerTest {
    @Test
    public void testUnmodifiedWhenNoHandlersAdded() throws Exception {
// Path: telemetry-instrumentation/src/main/java/com/yammer/telemetry/instrumentation/ClassInstrumentationHandler.java
// public interface ClassInstrumentationHandler {
//     boolean transformed(CtClass cc, ClassPool pool);
// }
// 
// Path: telemetry-agent/src/main/java/com/yammer/telemetry/agent/handlers/SubTypeInstrumentationHandler.java
// public abstract class SubTypeInstrumentationHandler implements ClassInstrumentationHandler {
//     private static final Logger LOGGER = Logger.getLogger(SubTypeInstrumentationHandler.class.getName());
//     protected final String superTypeName;
//     private boolean enabled = true;
// 
//     public SubTypeInstrumentationHandler(String superTypeName) {
//         this.superTypeName = superTypeName;
//     }
// 
//     public boolean isEnabled() {
//         return enabled;
//     }
// 
//     @Override
//     public final boolean transformed(CtClass cc, ClassPool pool) {
//         try {
//             if (canTransform(cc, pool)) {
//                 return transform(cc, pool);
//             }
//         } catch (NotFoundException | CannotCompileException | IOException e) {
//             // Disable the handler for the remainder.
//             LOGGER.warning("Error instrumenting " + cc.getName() + ": " + e.toString() + " [" + getClass().getName() + "]");
//             enabled = false;
//         }
// 
//         return false;
//     }
// 
//     private boolean canTransform(CtClass cc, ClassPool pool) throws NotFoundException {
//         return isEnabled() && cc.subtypeOf(pool.get(superTypeName));
//     }
// 
//     protected abstract boolean transform(CtClass cc, ClassPool pool) throws NotFoundException, CannotCompileException, IOException;
// }
// 
// Path: telemetry-test-framework/src/main/java/com/yammer/telemetry/test/TransformingClassLoader.java
// public class TransformingClassLoader extends URLClassLoader {
//     private final TelemetryTransformer transformer;
//     private final ClassPool classPool;
// 
//     public TransformingClassLoader(TelemetryTransformer transformer) {
//         super(new URL[] {});
//         this.transformer = checkNotNull(transformer);
//         classPool = new ClassPool(null);
//         classPool.appendSystemPath();
//     }
// 
//     @Override
//     public Class<?> loadClass(String name) throws ClassNotFoundException {
//         Class<?> loadedClass = super.findLoadedClass(name);
//         if (loadedClass != null) return loadedClass;
//         try (InputStream classStream = super.getResourceAsStream(name.replace('.', '/') + ".class")) {
//             byte[] classfileBuffer = ByteStreams.toByteArray(classStream);
//             byte[] transformedBytes = transformer.transform(this, name, classfileBuffer, classPool);
// 
//             if (transformedBytes == null) {
//                 if (name.startsWith("java")) {
//                     return super.loadClass(name);
//                 }
//                 return super.defineClass(name, classfileBuffer, 0, classfileBuffer.length);
//             } else {
//                 return super.defineClass(name, transformedBytes, 0, transformedBytes.length);
//             }
//         } catch (IOException | IllegalClassFormatException | RuntimeException e) {
//             throw new ClassNotFoundException(name, e);
//         }
//     }
// }
// 
// Path: telemetry-instrumentation/src/main/java/com/yammer/telemetry/instrumentation/TelemetryTransformer.java
// public class TelemetryTransformer implements ClassFileTransformer {
//     private final Set<ClassInstrumentationHandler> handlers = new HashSet<>();
// 
//     public void addHandler(ClassInstrumentationHandler handler) {
//         handlers.add(handler);
//     }
// 
//     @Override
//     public byte[] transform(ClassLoader loader,
//                             String className,
//                             Class<?> classBeingRedefined,
//                             ProtectionDomain protectionDomain,
//                             byte[] classfileBuffer) throws IllegalClassFormatException {
//         return transform(loader, className, classfileBuffer, ClassPool.getDefault());
//     }
// 
//     /**
//      * Allows specifying the ClassPool, this allows tests to essentially 'reload' classes.
//      *
//      * @param loader
//      * @param className
//      * @param classfileBuffer
//      * @param cp
//      * @return
//      * @throws IllegalClassFormatException
//      */
//     public byte[] transform(ClassLoader loader,
//                             String className,
//                             byte[] classfileBuffer,
//                             ClassPool cp) throws IllegalClassFormatException {
//         try {
//             final String realClassName = className.replace('/', '.');
//             cp.insertClassPath(new LoaderClassPath(loader));
//             cp.insertClassPath(new ByteArrayClassPath(realClassName, classfileBuffer));
//             CtClass cc = cp.get(realClassName);
// 
//             boolean classUpdated = false;
//             for (ClassInstrumentationHandler handler : handlers) {
//                 if (classUpdated = handler.transformed(cc, cp)) {
//                     break;
//                 }
//             }
// 
//             if (classUpdated) {
//                 return cc.toBytecode();
//             } else {
//                 return null;
//             }
//         } catch (Exception e) {
//             e.printStackTrace();
//             return null;
//         } catch (Throwable t) {
//             t.printStackTrace();
//             throw t;
//         }
//     }
// }
// 
// Path: telemetry-agent/src/test/java/com/yammer/telemetry/agent/TelemetryTransformerTest.java
// public static boolean wrapMethod(CtClass cc, String method, String body) {
//     try {
//         if (cc.isFrozen()) cc.defrost();
// 
//         CtMethod getMethod = cc.getDeclaredMethod(method);
//         CtMethod copiedMethod = CtNewMethod.copy(getMethod, cc.makeUniqueName(method), cc, null);
// 
//         copiedMethod.setModifiers(Modifier.PRIVATE);
//         cc.addMethod(copiedMethod);
// 
//         getMethod.setBody(body, "this", copiedMethod.getName());
// 
//         return true;
//     } catch (NotFoundException | CannotCompileException e) {
//         throw new RuntimeException(e);
//     }
// }


// Path: telemetry-agent/src/test/java/com/yammer/telemetry/agent/TelemetryTransformerTest.java
import com.yammer.telemetry.instrumentation.ClassInstrumentationHandler;
import com.yammer.telemetry.agent.handlers.SubTypeInstrumentationHandler;
import com.yammer.telemetry.test.TransformingClassLoader;
import com.yammer.telemetry.instrumentation.TelemetryTransformer;
import javassist.*;
import org.junit.Test;
import java.io.IOException;
import static com.yammer.telemetry.agent.TelemetryTransformerTest.ClassUtils.wrapMethod;
import static org.junit.Assert.*;

package com.yammer.telemetry.agent;




public class TelemetryTransformerTest {
    @Test
    public void testUnmodifiedWhenNoHandlersAdded() throws Exception {
        TelemetryTransformer transformer = new TelemetryTransformer();