diff --git a/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockConstructor.java b/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockConstructor.java index 70045b8..ee3d448 100644 --- a/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockConstructor.java +++ b/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockConstructor.java @@ -1,5 +1,7 @@ package com.alibaba.testable.core.annotation; +import com.alibaba.testable.core.model.MockScope; + import java.lang.annotation.*; /** @@ -11,4 +13,11 @@ import java.lang.annotation.*; @Target(ElementType.METHOD) @Documented public @interface MockConstructor { + + /** + * specify the effective scope of the mock method + * @return global or associated + */ + MockScope scope() default MockScope.ASSOCIATED; + } diff --git a/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockMethod.java b/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockMethod.java index 7733ace..824335a 100644 --- a/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockMethod.java +++ b/testable-core/src/main/java/com/alibaba/testable/core/annotation/MockMethod.java @@ -1,5 +1,7 @@ package com.alibaba.testable.core.annotation; +import com.alibaba.testable.core.model.MockScope; + import javax.lang.model.type.NullType; import java.lang.annotation.*; @@ -25,4 +27,10 @@ public @interface MockMethod { */ Class targetClass() default NullType.class; + /** + * specify the effective scope of the mock method + * @return global or associated + */ + MockScope scope() default MockScope.ASSOCIATED; + } diff --git a/testable-core/src/main/java/com/alibaba/testable/core/model/MockScope.java b/testable-core/src/main/java/com/alibaba/testable/core/model/MockScope.java new file mode 100644 index 0000000..4cb5982 --- /dev/null +++ b/testable-core/src/main/java/com/alibaba/testable/core/model/MockScope.java @@ -0,0 +1,15 @@ +package com.alibaba.testable.core.model; + +public enum MockScope { + + /** + * Mock method only available for test cases in the test class it belongs to + */ + ASSOCIATED, + + /** + * Mock method available for any test cases + */ + GLOBAL + +}