mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-10 01:30:29 +08:00
expose constructor of void class
This commit is contained in:
parent
ef3891bd57
commit
3265803dec
@ -2,6 +2,7 @@ package com.alibaba.testable.agent.handler;
|
||||
|
||||
import com.alibaba.testable.agent.handler.test.JUnit4Framework;
|
||||
import com.alibaba.testable.agent.handler.test.JUnit5Framework;
|
||||
import com.alibaba.testable.agent.util.BytecodeUtil;
|
||||
import com.alibaba.testable.agent.util.ClassUtil;
|
||||
import com.alibaba.testable.agent.util.CollectionUtil;
|
||||
import org.objectweb.asm.Label;
|
||||
@ -41,7 +42,19 @@ public class OmniClassHandler extends BaseClassHandler {
|
||||
if (isInterface(cn) || isJunitTestClass(cn) || isUninstantiableClass(cn) || hasSpecialAnnotation(cn)) {
|
||||
return;
|
||||
}
|
||||
addConstructorWithVoidTypeParameter(cn);
|
||||
if (VOID_TYPE.equals(cn.name)) {
|
||||
exposePrivateConstructor(cn);
|
||||
} else {
|
||||
addConstructorWithVoidTypeParameter(cn);
|
||||
}
|
||||
}
|
||||
|
||||
private void exposePrivateConstructor(ClassNode cn) {
|
||||
for (MethodNode method : cn.methods) {
|
||||
if (method.name.equals(CONSTRUCTOR)) {
|
||||
method.access = BytecodeUtil.toPublicAccess(method.access);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addConstructorWithVoidTypeParameter(ClassNode cn) {
|
||||
@ -85,8 +98,8 @@ public class OmniClassHandler extends BaseClassHandler {
|
||||
}
|
||||
|
||||
private boolean isInterface(ClassNode cn) {
|
||||
// is interface, Object class or Void class
|
||||
return (cn.access & ACC_INTERFACE) != 0 || cn.superName == null || VOID_TYPE.equals(cn.name);
|
||||
// is interface or Object class
|
||||
return (cn.access & ACC_INTERFACE) != 0 || cn.superName == null;
|
||||
}
|
||||
|
||||
private boolean isJunitTestClass(ClassNode cn) {
|
||||
|
Loading…
Reference in New Issue
Block a user