mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-04 08:40:20 +08:00
extra <init> constant to core package
This commit is contained in:
parent
6a5c817a3a
commit
8be5550331
@ -22,9 +22,4 @@ public class ConstPool {
|
|||||||
public static final String KOTLIN_POSTFIX_COMPANION = "$Companion";
|
public static final String KOTLIN_POSTFIX_COMPANION = "$Companion";
|
||||||
public static final String KOTLIN_PREFIX_ACCESS = "access$";
|
public static final String KOTLIN_PREFIX_ACCESS = "access$";
|
||||||
|
|
||||||
/**
|
|
||||||
* Name of the constructor method
|
|
||||||
*/
|
|
||||||
public static final String CONSTRUCTOR = "<init>";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.objectweb.asm.tree.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.testable.agent.util.ClassUtil.toDotSeparateFullClassName;
|
import static com.alibaba.testable.agent.util.ClassUtil.toDotSeparateFullClassName;
|
||||||
|
import static com.alibaba.testable.core.constant.ConstPool.CONSTRUCTOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
||||||
@ -60,7 +61,7 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
|||||||
il.add(new JumpInsnNode(IFNONNULL, label));
|
il.add(new JumpInsnNode(IFNONNULL, label));
|
||||||
il.add(new TypeInsnNode(NEW, mockClassName));
|
il.add(new TypeInsnNode(NEW, mockClassName));
|
||||||
il.add(new InsnNode(DUP));
|
il.add(new InsnNode(DUP));
|
||||||
il.add(new MethodInsnNode(INVOKESPECIAL, mockClassName, ConstPool.CONSTRUCTOR, VOID_ARGS + VOID_RES, false));
|
il.add(new MethodInsnNode(INVOKESPECIAL, mockClassName, CONSTRUCTOR, VOID_ARGS + VOID_RES, false));
|
||||||
il.add(new FieldInsnNode(PUTSTATIC, mockClassName, TESTABLE_REF, ClassUtil.toByteCodeClassName(mockClassName)));
|
il.add(new FieldInsnNode(PUTSTATIC, mockClassName, TESTABLE_REF, ClassUtil.toByteCodeClassName(mockClassName)));
|
||||||
il.add(label);
|
il.add(label);
|
||||||
il.add(new FrameNode(F_SAME, 0, null, 0, null));
|
il.add(new FrameNode(F_SAME, 0, null, 0, null));
|
||||||
@ -159,10 +160,10 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
|||||||
methodName = name;
|
methodName = name;
|
||||||
}
|
}
|
||||||
} else if (ClassUtil.toByteCodeClassName(ConstPool.MOCK_CONSTRUCTOR).equals(an.desc)) {
|
} else if (ClassUtil.toByteCodeClassName(ConstPool.MOCK_CONSTRUCTOR).equals(an.desc)) {
|
||||||
methodName = ConstPool.CONSTRUCTOR;
|
methodName = CONSTRUCTOR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (methodName.equals(ConstPool.CONSTRUCTOR)) {
|
if (methodName.equals(CONSTRUCTOR)) {
|
||||||
className = Type.getType(ClassUtil.getReturnType(mn.desc));
|
className = Type.getType(ClassUtil.getReturnType(mn.desc));
|
||||||
} else {
|
} else {
|
||||||
className = Type.getType(ClassUtil.getFirstParameter(mn.desc));
|
className = Type.getType(ClassUtil.getFirstParameter(mn.desc));
|
||||||
@ -242,7 +243,7 @@ public class MockClassHandler extends BaseClassWithContextHandler {
|
|||||||
} else if (ConstPool.MOCK_METHOD.equals(annotationName)) {
|
} else if (ConstPool.MOCK_METHOD.equals(annotationName)) {
|
||||||
String method = AnnotationUtil.getAnnotationParameter
|
String method = AnnotationUtil.getAnnotationParameter
|
||||||
(an, ConstPool.FIELD_TARGET_METHOD, null, String.class);
|
(an, ConstPool.FIELD_TARGET_METHOD, null, String.class);
|
||||||
if (ConstPool.CONSTRUCTOR.equals(method)) {
|
if (CONSTRUCTOR.equals(method)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.alibaba.testable.agent.constant.ConstPool.CONSTRUCTOR;
|
import static com.alibaba.testable.core.constant.ConstPool.CONSTRUCTOR;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
||||||
|
@ -17,6 +17,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.testable.agent.util.ClassUtil.toDotSeparateFullClassName;
|
import static com.alibaba.testable.agent.util.ClassUtil.toDotSeparateFullClassName;
|
||||||
|
import static com.alibaba.testable.core.constant.ConstPool.CONSTRUCTOR;
|
||||||
|
|
||||||
public class MockClassParser {
|
public class MockClassParser {
|
||||||
|
|
||||||
@ -96,7 +97,7 @@ public class MockClassParser {
|
|||||||
LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, getTargetMethodDesc(mn, an));
|
LogUtil.verbose(" Mock method \"%s\" as \"%s\"", mn.name, getTargetMethodDesc(mn, an));
|
||||||
String targetMethod = AnnotationUtil.getAnnotationParameter(
|
String targetMethod = AnnotationUtil.getAnnotationParameter(
|
||||||
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
||||||
if (ConstPool.CONSTRUCTOR.equals(targetMethod)) {
|
if (CONSTRUCTOR.equals(targetMethod)) {
|
||||||
addMockConstructor(methodInfos, cn, mn);
|
addMockConstructor(methodInfos, cn, mn);
|
||||||
} else {
|
} else {
|
||||||
MethodInfo mi = getMethodInfo(mn, an, targetMethod);
|
MethodInfo mi = getMethodInfo(mn, an, targetMethod);
|
||||||
@ -134,7 +135,7 @@ public class MockClassParser {
|
|||||||
|
|
||||||
private void addMockConstructor(List<MethodInfo> methodInfos, ClassNode cn, MethodNode mn) {
|
private void addMockConstructor(List<MethodInfo> methodInfos, ClassNode cn, MethodNode mn) {
|
||||||
String sourceClassName = ClassUtil.getSourceClassName(cn.name);
|
String sourceClassName = ClassUtil.getSourceClassName(cn.name);
|
||||||
methodInfos.add(new MethodInfo(sourceClassName, ConstPool.CONSTRUCTOR, mn.desc, mn.name, mn.desc));
|
methodInfos.add(new MethodInfo(sourceClassName, CONSTRUCTOR, mn.desc, mn.name, mn.desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,14 @@ package com.alibaba.testable.core.constant;
|
|||||||
|
|
||||||
public class ConstPool {
|
public class ConstPool {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the constructor method
|
||||||
|
*/
|
||||||
|
public static final String CONSTRUCTOR = "<init>";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Postfix or test and mock file
|
||||||
|
*/
|
||||||
public static final String TEST_POSTFIX = "Test";
|
public static final String TEST_POSTFIX = "Test";
|
||||||
public static final String MOCK_POSTFIX = "Mock";
|
public static final String MOCK_POSTFIX = "Mock";
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.alibaba.testable.core.constant.ConstPool.MOCK_POSTFIX;
|
import static com.alibaba.testable.core.constant.ConstPool.*;
|
||||||
import static com.alibaba.testable.core.constant.ConstPool.TEST_POSTFIX;
|
|
||||||
|
|
||||||
public class MockAssociationUtil {
|
public class MockAssociationUtil {
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ public class MockAssociationUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Object invokeOrigin(Class<?> originClass, String originMethod, Object... args) {
|
public static Object invokeOrigin(Class<?> originClass, String originMethod, Object... args) {
|
||||||
if (originMethod.equals("<init>")) {
|
if (originMethod.equals(CONSTRUCTOR)) {
|
||||||
return PrivateAccessor.construct(originClass, args);
|
return PrivateAccessor.construct(originClass, args);
|
||||||
} else if (args[0] == null) {
|
} else if (args[0] == null) {
|
||||||
return PrivateAccessor.invokeStatic(originClass, originMethod, CollectionUtil.slice(args, 1));
|
return PrivateAccessor.invokeStatic(originClass, originMethod, CollectionUtil.slice(args, 1));
|
||||||
|
Loading…
Reference in New Issue
Block a user