mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-23 16:20:26 +08:00
do deprecate instead of removal
This commit is contained in:
parent
328c8540a8
commit
3f672e45da
@ -16,6 +16,7 @@ public class ConstPool {
|
|||||||
public static final String MOCK_WITH = "com.alibaba.testable.core.annotation.MockWith";
|
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_METHOD = "com.alibaba.testable.core.annotation.MockMethod";
|
||||||
public static final String MOCK_CONSTRUCTOR = "com.alibaba.testable.core.annotation.MockConstructor";
|
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
|
* Name of the constructor method
|
||||||
|
@ -58,6 +58,7 @@ public class TestClassHandler extends BaseClassHandler {
|
|||||||
visibleAnnotationNames.add(n.desc);
|
visibleAnnotationNames.add(n.desc);
|
||||||
}
|
}
|
||||||
if (visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_METHOD)) ||
|
if (visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_METHOD)) ||
|
||||||
|
visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.TESTABLE_MOCK)) ||
|
||||||
visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_CONSTRUCTOR))) {
|
visibleAnnotationNames.contains(ClassUtil.toByteCodeClassName(ConstPool.MOCK_CONSTRUCTOR))) {
|
||||||
mn.access &= ~ACC_PRIVATE;
|
mn.access &= ~ACC_PRIVATE;
|
||||||
mn.access &= ~ACC_PROTECTED;
|
mn.access &= ~ACC_PROTECTED;
|
||||||
|
@ -119,7 +119,8 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
|||||||
String fullClassName = toDotSeparateFullClassName(an.desc);
|
String fullClassName = toDotSeparateFullClassName(an.desc);
|
||||||
if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
if (fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
||||||
addMockConstructor(cn, methodInfos, mn);
|
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(
|
String targetMethod = AnnotationUtil.getAnnotationParameter(
|
||||||
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
an, ConstPool.FIELD_TARGET_METHOD, mn.name, String.class);
|
||||||
if (targetMethod.equals(ConstPool.CONSTRUCTOR)) {
|
if (targetMethod.equals(ConstPool.CONSTRUCTOR)) {
|
||||||
@ -171,6 +172,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
|
|||||||
for (AnnotationNode an : mn.visibleAnnotations) {
|
for (AnnotationNode an : mn.visibleAnnotations) {
|
||||||
String fullClassName = toDotSeparateFullClassName(an.desc);
|
String fullClassName = toDotSeparateFullClassName(an.desc);
|
||||||
if (fullClassName.equals(ConstPool.MOCK_METHOD) ||
|
if (fullClassName.equals(ConstPool.MOCK_METHOD) ||
|
||||||
|
fullClassName.equals(ConstPool.TESTABLE_MOCK) ||
|
||||||
fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
fullClassName.equals(ConstPool.MOCK_CONSTRUCTOR)) {
|
||||||
loadedClass.put(new ComparableWeakRef<String>(className), CachedMockParameter.exist());
|
loadedClass.put(new ComparableWeakRef<String>(className), CachedMockParameter.exist());
|
||||||
return true;
|
return true;
|
||||||
|
@ -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 "";
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user