fit for class which enhanced by CGLIB,for example,some class annotated with '@Service' in Spring Framework

This commit is contained in:
itwild 2021-01-01 22:23:50 +08:00
parent 94127064e8
commit 631f45f4c5
2 changed files with 7 additions and 0 deletions

View File

@ -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
*/

View File

@ -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;
}