mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-07 19:00:45 +08:00
allow disable mock target checking
This commit is contained in:
parent
381ff52515
commit
ea4c6c5b3e
@ -1 +1,2 @@
|
||||
omni.constructor.enhance.enable = true
|
||||
mock.target.checking.enable = true
|
||||
|
@ -22,10 +22,11 @@ public class PropertiesParser {
|
||||
private static final String PKG_PREFIX_INCLUDES = "enhance.pkgPrefix.includes";
|
||||
private static final String LOG_FILE = "log.file";
|
||||
private static final String LOG_LEVEL = "log.level";
|
||||
private static final String ENABLE_MOCK_INJECT = "mock.enhance.enable";
|
||||
private static final String INNER_MOCK_CLASS_NAME = "mock.innerClass.name";
|
||||
private static final String MOCK_PKG_MAPPING_PREFIX = "mock.package.mapping.";
|
||||
private static final String DEFAULT_MOCK_SCOPE = "mock.scope.default";
|
||||
private static final String ENABLE_MOCK_INJECT = "mock.enhance.enable";
|
||||
private static final String ENABLE_MOCK_TARGET_CHECK = "mock.target.checking.enable";
|
||||
private static final String ENABLE_OMNI_INJECT = "omni.constructor.enhance.enable";
|
||||
private static final String ENABLE_THREAD_POOL = "thread.pool.enhance.enable";
|
||||
|
||||
@ -74,6 +75,8 @@ public class PropertiesParser {
|
||||
GlobalConfig.enhanceOmniConstructor = Boolean.parseBoolean(v);
|
||||
} else if (k.equals(ENABLE_MOCK_INJECT)) {
|
||||
GlobalConfig.enhanceMock = Boolean.parseBoolean(v);
|
||||
} else if (k.equals(ENABLE_MOCK_TARGET_CHECK)) {
|
||||
GlobalConfig.checkMockTargetExistence = Boolean.parseBoolean(v);
|
||||
} else if (k.equals(ENABLE_THREAD_POOL)) {
|
||||
GlobalConfig.enhanceThreadLocal = Boolean.parseBoolean(v);
|
||||
}
|
||||
|
@ -3,10 +3,7 @@ package com.alibaba.testable.agent.transformer;
|
||||
import com.alibaba.testable.agent.constant.ConstPool;
|
||||
import com.alibaba.testable.agent.model.MethodInfo;
|
||||
import com.alibaba.testable.agent.tool.ImmutablePair;
|
||||
import com.alibaba.testable.agent.util.AnnotationUtil;
|
||||
import com.alibaba.testable.agent.util.ClassUtil;
|
||||
import com.alibaba.testable.agent.util.DiagnoseUtil;
|
||||
import com.alibaba.testable.agent.util.MethodUtil;
|
||||
import com.alibaba.testable.agent.util.*;
|
||||
import com.alibaba.testable.core.exception.TargetNotExistException;
|
||||
import com.alibaba.testable.core.util.LogUtil;
|
||||
import org.objectweb.asm.Type;
|
||||
@ -85,11 +82,15 @@ public class MockClassParser {
|
||||
for (AnnotationNode an : mn.visibleAnnotations) {
|
||||
String fullClassName = toJavaStyleClassName(an.desc);
|
||||
if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
||||
checkTargetConstructorExists(mn);
|
||||
if (GlobalConfig.checkMockTargetExistence) {
|
||||
checkTargetConstructorExists(mn);
|
||||
}
|
||||
methodInfos.add(new MethodInfo(ClassUtil.getSourceClassName(cn.name), CONSTRUCTOR, mn.desc, cn.name,
|
||||
mn.name, mn.desc, isStatic(mn)));
|
||||
} else if (fullClassName.equals(ConstPool.MOCK_METHOD) && isValidMockMethod(mn, an)) {
|
||||
checkTargetMethodExists(mn, an);
|
||||
if (GlobalConfig.checkMockTargetExistence) {
|
||||
checkTargetMethodExists(mn, an);
|
||||
}
|
||||
String targetMethod = AnnotationUtil.getAnnotationParameter(
|
||||
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
||||
MethodInfo mi = getMethodInfo(cn, mn, an, targetMethod);
|
||||
|
@ -38,6 +38,7 @@ public class GlobalConfig {
|
||||
public static boolean enhanceMock = true;
|
||||
public static boolean enhanceOmniConstructor = false;
|
||||
public static boolean enhanceThreadLocal = false;
|
||||
public static boolean checkMockTargetExistence = false;
|
||||
public static String innerMockClassName = "Mock";
|
||||
|
||||
public static void setLogLevel(String level) {
|
||||
|
Loading…
Reference in New Issue
Block a user