do deprecate instead of removal

This commit is contained in:
金戟 2020-12-11 21:19:16 +08:00
parent 328c8540a8
commit 3f672e45da
4 changed files with 28 additions and 1 deletions

View File

@ -16,6 +16,7 @@ public class ConstPool {
public static final String MOCK_WITH = "com.alibaba.testable.core.annotation.MockWith";
public static final String MOCK_METHOD = "com.alibaba.testable.core.annotation.MockMethod";
public static final String MOCK_CONSTRUCTOR = "com.alibaba.testable.core.annotation.MockConstructor";
public static final String TESTABLE_MOCK = "com.alibaba.testable.core.annotation.TestableMock";
/**
* Name of the constructor method

View File

@ -58,6 +58,7 @@ public class TestClassHandler extends BaseClassHandler {
visibleAnnotationNames.add(n.desc);
}
if (visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_METHOD)) ||
visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.TESTABLE_MOCK)) ||
visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_CONSTRUCTOR))) {
mn.access &= ~ACC_PRIVATE;
mn.access &= ~ACC_PROTECTED;

View File

@ -119,7 +119,8 @@ public class TestableClassTransformer implements ClassFileTransformer {
String fullClassName = toDotSeparateFullClassName(an.desc);
if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
addMockConstructor(cn, methodInfos, mn);
} else if (fullClassName.equals(ConstPool.MOCK_METHOD)) {
} else if (fullClassName.equals(ConstPool.MOCK_METHOD) ||
fullClassName.equals(ConstPool.TESTABLE_MOCK)) {
String targetMethod = AnnotationUtil.getAnnotationParameter(
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
if (targetMethod.equals(ConstPool.CONSTRUCTOR)) {
@ -171,6 +172,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
for (AnnotationNode an : mn.visibleAnnotations) {
String fullClassName = toDotSeparateFullClassName(an.desc);
if (fullClassName.equals(ConstPool.MOCK_METHOD) ||
fullClassName.equals(ConstPool.TESTABLE_MOCK) ||
fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
loadedClass.put(new ComparableWeakRef<String>(className), CachedMockParameter.exist());
return true;

View File

@ -0,0 +1,23 @@
package com.alibaba.testable.core.annotation;
import java.lang.annotation.*;
/**
* Mark method as mock method
* @deprecated will be remove in v0.5.0, use @MockMethod or @MockConstructor instead
*
* @author flin
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Documented
@Deprecated
public @interface TestableMock {
/**
* mock specified method instead of method with same name
* @return target method name
*/
String targetMethod() default "";
}