mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-09 20:00:21 +08:00
fix compatibility with spring boot
This commit is contained in:
parent
cc2deeff1c
commit
844323af3a
@ -31,7 +31,7 @@ public class OmniClassHandler extends BaseClassHandler {
|
||||
|
||||
@Override
|
||||
protected void transform(ClassNode cn) {
|
||||
if (isInterface(cn) || isJunitTestClass(cn)) {
|
||||
if (isInterface(cn) || isJunitTestClass(cn) || isUninstantiableClass(cn)) {
|
||||
return;
|
||||
}
|
||||
MethodNode constructor = new MethodNode(ACC_PUBLIC, CONSTRUCTOR,
|
||||
@ -51,6 +51,16 @@ public class OmniClassHandler extends BaseClassHandler {
|
||||
cn.methods.add(constructor);
|
||||
}
|
||||
|
||||
private boolean isUninstantiableClass(ClassNode cn) {
|
||||
// if the class has no even default constructor, skip it
|
||||
for (MethodNode mn : cn.methods) {
|
||||
if (mn.name.equals(CONSTRUCTOR)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isInterface(ClassNode cn) {
|
||||
// is interface or the object class
|
||||
return (cn.access & ACC_INTERFACE) != 0 || cn.superName == null;
|
||||
|
@ -41,7 +41,8 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
||||
/**
|
||||
* Just avoid spend time to scan those surely non-user classes, should keep these lists as tiny as possible
|
||||
*/
|
||||
private final String[] BLACKLIST_PREFIXES = new String[] { "sun/", "com/sun/", "org/gradle/" };
|
||||
private final String[] BLACKLIST_PREFIXES = new String[] { "sun/", "com/sun/", "org/gradle/",
|
||||
"org/springframework/boot/autoconfigure/" };
|
||||
|
||||
public MockClassParser mockClassParser = new MockClassParser();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user