mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-25 11:51:15 +08:00
fix incorrect type name in byte code
This commit is contained in:
parent
a947939d08
commit
6009326150
@ -6,7 +6,7 @@ import java.util.List;
|
||||
/**
|
||||
* @author flin
|
||||
*/
|
||||
public class Const {
|
||||
public class ConstPool {
|
||||
|
||||
public static final String DOT = ".";
|
||||
public static final String SLASH = "/";
|
@ -1,15 +1,12 @@
|
||||
package com.alibaba.testable.agent.handler;
|
||||
|
||||
import com.alibaba.testable.agent.constant.Const;
|
||||
import com.alibaba.testable.agent.constant.ConstPool;
|
||||
import com.alibaba.testable.agent.util.ClassUtil;
|
||||
import com.alibaba.testable.agent.util.StringUtil;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import org.objectweb.asm.Type;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@ -52,7 +49,7 @@ public class SourceClassHandler extends ClassHandler {
|
||||
instructions = replaceMemberCallOps(mn, instructions, rangeStart, i);
|
||||
i = rangeStart;
|
||||
}
|
||||
} else if (CONSTRUCTOR.equals(node.name) && !Const.SYS_CLASSES.contains(node.owner)) {
|
||||
} else if (CONSTRUCTOR.equals(node.name) && !ConstPool.SYS_CLASSES.contains(node.owner)) {
|
||||
int rangeStart = getConstructorStart(instructions, node.owner, i);
|
||||
if (rangeStart >= 0) {
|
||||
instructions = replaceNewOps(mn, instructions, rangeStart, i);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.alibaba.testable.agent.handler;
|
||||
|
||||
import com.alibaba.testable.agent.util.ClassUtil;
|
||||
import com.alibaba.testable.agent.util.CollectionUtil;
|
||||
import org.objectweb.asm.tree.*;
|
||||
|
||||
@ -16,11 +17,11 @@ public class TestClassHandler extends ClassHandler {
|
||||
|
||||
static {
|
||||
// JUnit4
|
||||
testAnnotations.add("org.junit.Test");
|
||||
testAnnotations.add(ClassUtil.toByteCodeClassName("org.junit.Test"));
|
||||
// JUnit5
|
||||
testAnnotations.add("org.junit.jupiter.api.Test");
|
||||
testAnnotations.add(ClassUtil.toByteCodeClassName("org.junit.jupiter.api.Test"));
|
||||
// TestNG
|
||||
testAnnotations.add("org.testng.annotations.Test");
|
||||
testAnnotations.add(ClassUtil.toByteCodeClassName("org.testng.annotations.Test"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -32,6 +33,9 @@ public class TestClassHandler extends ClassHandler {
|
||||
|
||||
private void transformMethod(ClassNode cn, MethodNode mn) {
|
||||
List<String> visibleAnnotationNames = new ArrayList<String>();
|
||||
if (mn.visibleAnnotations == null) {
|
||||
return;
|
||||
}
|
||||
for (AnnotationNode n : mn.visibleAnnotations) {
|
||||
visibleAnnotationNames.add(n.desc);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.alibaba.testable.agent.util;
|
||||
|
||||
import com.alibaba.testable.agent.constant.Const;
|
||||
import com.alibaba.testable.agent.constant.ConstPool;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.tree.AnnotationNode;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
@ -37,7 +37,7 @@ public class ClassUtil {
|
||||
ClassNode cn = new ClassNode();
|
||||
new ClassReader(className).accept(cn, 0);
|
||||
for (AnnotationNode an : cn.visibleAnnotations) {
|
||||
String annotationName = an.desc.replace(Const.SLASH, Const.DOT).substring(1, an.desc.length() - 1);
|
||||
String annotationName = an.desc.replace(ConstPool.SLASH, ConstPool.DOT).substring(1, an.desc.length() - 1);
|
||||
annotations.add(annotationName);
|
||||
}
|
||||
return annotations;
|
||||
@ -98,4 +98,7 @@ public class ClassUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static String toByteCodeClassName(String className) {
|
||||
return TYPE_CLASS + className.replace(ConstPool.DOT, ConstPool.SLASH) + CLASS_END;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user