diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java index bb13357..1cf5c5e 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java @@ -68,7 +68,7 @@ public class SourceClassHandler extends BaseClassHandler { MethodInsnNode node = (MethodInsnNode)instructions[i]; if (CONSTRUCTOR.equals(node.name)) { LogUtil.verbose(" Line %d, constructing \"%s\"", getLineNum(instructions, i), - MethodUtil.toJavaDesc(node.owner, node.desc)); + MethodUtil.toJavaMethodDesc(node.owner, node.desc)); MethodInfo newOperatorInjectMethod = getNewOperatorInjectMethod(newOperatorInjectMethods, node); if (newOperatorInjectMethod != null) { // it's a new operation and an inject method for it exist @@ -83,7 +83,7 @@ public class SourceClassHandler extends BaseClassHandler { } } else { LogUtil.verbose(" Line %d, invoking \"%s\"", getLineNum(instructions, i), - MethodUtil.toJavaDesc(node.owner, node.name, node.desc)); + MethodUtil.toJavaMethodDesc(node.owner, node.name, node.desc)); MethodInfo mockMethod = getMemberInjectMethodName(memberInjectMethods, node); if (mockMethod != null) { // it's a member or static method and an inject method for it exist diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/Framework.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/Framework.java index 62ac2da..8d15b70 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/Framework.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/Framework.java @@ -1,10 +1,11 @@ package com.alibaba.testable.agent.handler.test; - import com.alibaba.testable.agent.model.TestCaseMethodType; +import com.alibaba.testable.agent.util.CollectionUtil; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.MethodNode; +import java.util.List; import java.util.Set; abstract public class Framework { @@ -22,7 +23,7 @@ abstract public class Framework { hasTestAfterMethod = true; return true; } else { - return methodAnnotations.contains(getTestAnnotation()); + return CollectionUtil.containsAny(methodAnnotations, getTestAnnotations()); } } @@ -31,7 +32,7 @@ abstract public class Framework { return TestCaseMethodType.OTHERS; } for (AnnotationNode an : mn.visibleAnnotations) { - if (an.desc.equals(getTestAnnotation())) { + if (getTestAnnotations().contains(an.desc)) { return TestCaseMethodType.TEST; } else if (an.desc.equals(getTestAfterAnnotation())) { return TestCaseMethodType.AFTER_TEST; @@ -40,7 +41,7 @@ abstract public class Framework { return TestCaseMethodType.OTHERS; } - public abstract String getTestAnnotation(); + public abstract List getTestAnnotations(); public abstract String getTestAfterAnnotation(); diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit4Framework.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit4Framework.java index 13c1fda..762a47c 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit4Framework.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit4Framework.java @@ -1,13 +1,16 @@ package com.alibaba.testable.agent.handler.test; +import java.util.Collections; +import java.util.List; + public class JUnit4Framework extends Framework { private static final String ANNOTATION_TEST = "Lorg/junit/Test;"; private static final String ANNOTATION_AFTER_TEST = "Lorg/junit/After;"; @Override - public String getTestAnnotation() { - return ANNOTATION_TEST; + public List getTestAnnotations() { + return Collections.singletonList(ANNOTATION_TEST); } @Override diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit5Framework.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit5Framework.java index 13705c2..43909af 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit5Framework.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/JUnit5Framework.java @@ -1,13 +1,17 @@ package com.alibaba.testable.agent.handler.test; +import java.util.Arrays; +import java.util.List; + public class JUnit5Framework extends Framework { private static final String ANNOTATION_TEST = "Lorg/junit/jupiter/api/Test;"; + private static final String ANNOTATION_PARAMETERIZED_TEST = "Lorg/junit/jupiter/params/ParameterizedTest;"; private static final String ANNOTATION_AFTER_TEST = "Lorg/junit/jupiter/api/AfterEach;"; @Override - public String getTestAnnotation() { - return ANNOTATION_TEST; + public List getTestAnnotations() { + return Arrays.asList(ANNOTATION_TEST, ANNOTATION_PARAMETERIZED_TEST); } @Override diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgFramework.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgFramework.java index 60d8c4e..9dd71db 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgFramework.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgFramework.java @@ -1,13 +1,16 @@ package com.alibaba.testable.agent.handler.test; +import java.util.Collections; +import java.util.List; + public class TestNgFramework extends Framework { private static final String ANNOTATION_TEST = "Lorg/testng/annotations/Test;"; private static final String ANNOTATION_AFTER_TEST = "Lorg/testng/annotations/AfterMethod;"; @Override - public String getTestAnnotation() { - return ANNOTATION_TEST; + public List getTestAnnotations() { + return Collections.singletonList(ANNOTATION_TEST); } @Override diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgOnClassFramework.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgOnClassFramework.java index 3f13e87..45eece6 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgOnClassFramework.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/test/TestNgOnClassFramework.java @@ -1,6 +1,7 @@ package com.alibaba.testable.agent.handler.test; import com.alibaba.testable.agent.model.TestCaseMethodType; +import com.alibaba.testable.agent.util.CollectionUtil; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.MethodNode; @@ -12,7 +13,7 @@ public class TestNgOnClassFramework extends TestNgFramework { @Override public boolean fit(Set classAnnotations, Set methodAnnotations) { - if (classAnnotations.contains(getTestAnnotation())) { + if (CollectionUtil.containsAny(classAnnotations, getTestAnnotations())) { if (methodAnnotations.contains(getTestAfterAnnotation())) { hasTestAfterMethod = true; } diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/MockClassParser.java b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/MockClassParser.java index fc1da9e..46cf2f0 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/MockClassParser.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/MockClassParser.java @@ -16,7 +16,6 @@ import org.objectweb.asm.tree.MethodNode; import java.util.ArrayList; import java.util.List; -import static com.alibaba.testable.agent.constant.ByteCodeConst.TYPE_CLASS; import static com.alibaba.testable.agent.util.ClassUtil.toDotSeparateFullClassName; import static com.alibaba.testable.agent.util.MethodUtil.isStatic; import static com.alibaba.testable.core.constant.ConstPool.CONSTRUCTOR; @@ -88,10 +87,10 @@ public class MockClassParser { String fullClassName = toDotSeparateFullClassName(an.desc); if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) { LogUtil.verbose(" Mock constructor \"%s\" as \"%s\"", mn.name, - MethodUtil.toJavaDesc(MethodUtil.getReturnType(mn.desc), mn.desc)); + MethodUtil.toJavaMethodDesc(MethodUtil.getReturnType(mn.desc), mn.desc)); addMockConstructor(methodInfos, cn, mn); } else if (fullClassName.equals(ConstPool.MOCK_METHOD) && AnnotationUtil.isValidMockMethod(mn, an)) { - LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, MethodUtil.toJavaDesc( + LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, MethodUtil.toJavaMethodDesc( getTargetMethodOwner(mn, an), getTargetMethodName(mn, an), getTargetMethodDesc(mn, an))); String targetMethod = AnnotationUtil.getAnnotationParameter( an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class); diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/util/MethodUtil.java b/testable-agent/src/main/java/com/alibaba/testable/agent/util/MethodUtil.java index c059f8b..2f02e7a 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/util/MethodUtil.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/util/MethodUtil.java @@ -112,8 +112,8 @@ public class MethodUtil { * @param desc method constructor in bytecode format * @return java style constructor descriptor */ - public static String toJavaDesc(String owner, String desc) { - String parameters = MethodUtil.extractParameters(desc); + public static String toJavaMethodDesc(String owner, String desc) { + String parameters = toJavaParameterDesc(extractParameters(desc)); return String.format("%s(%s)", owner, parameters); } @@ -124,9 +124,19 @@ public class MethodUtil { * @param desc method descriptor in bytecode format * @return java style method descriptor */ - public static String toJavaDesc(String owner, String name, String desc) { - String returnType = MethodUtil.getReturnType(desc); - String parameters = MethodUtil.extractParameters(desc); - return String.format("%s %s::%s(%s)", returnType, owner, name, parameters); + public static String toJavaMethodDesc(String owner, String name, String desc) { + String ownerInDotFormat = ClassUtil.toDotSeparatedName(owner); + String returnType = toJavaParameterDesc(getReturnType(desc)); + String parameters = toJavaParameterDesc(extractParameters(desc)); + return String.format("%s %s::%s(%s)", returnType, ownerInDotFormat, name, parameters); + } + + /** + * convert bytecode style parameter descriptor to java style descriptor + * @param desc bytecode style descriptor + * @return java style descriptor + */ + private static String toJavaParameterDesc(String desc) { + return desc; } }