From 631f45f4c50726fc7f0c619fef3b8d483c69ca40 Mon Sep 17 00:00:00 2001 From: itwild Date: Fri, 1 Jan 2021 22:23:50 +0800 Subject: [PATCH] fit for class which enhanced by CGLIB,for example,some class annotated with '@Service' in Spring Framework --- .../java/com/alibaba/testable/agent/constant/ConstPool.java | 2 ++ .../main/java/com/alibaba/testable/agent/util/ClassUtil.java | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/constant/ConstPool.java b/testable-agent/src/main/java/com/alibaba/testable/agent/constant/ConstPool.java index 1ac673e..e12e209 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/constant/ConstPool.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/constant/ConstPool.java @@ -17,6 +17,8 @@ public class ConstPool { public static final String MOCK_CONSTRUCTOR = "com.alibaba.testable.core.annotation.MockConstructor"; public static final String TESTABLE_MOCK = "com.alibaba.testable.core.annotation.TestableMock"; + public static final String CGLIB_CLASS_INFIX = "$$EnhancerByCGLIB$$"; + /** * Name of the constructor method */ diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/util/ClassUtil.java b/testable-agent/src/main/java/com/alibaba/testable/agent/util/ClassUtil.java index 0d0cec1..f7a9870 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/util/ClassUtil.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/util/ClassUtil.java @@ -79,6 +79,11 @@ public class ClassUtil { * @return test class name */ public static String getTestClassName(String sourceClassName) { + // check the class if generated by CGLIB + int idx = sourceClassName.indexOf(ConstPool.CGLIB_CLASS_INFIX); + if (idx != -1) { + sourceClassName = sourceClassName.substring(0, idx); + } return sourceClassName + ConstPool.TEST_POSTFIX; }