From 6d6e2ecb7fb752e3d3c440b2d912cb8393997d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Wed, 17 Feb 2021 17:59:13 +0800 Subject: [PATCH] add mock method scope --- .../testable/core/annotation/MockConstructor.java | 9 +++++++++ .../testable/core/annotation/MockMethod.java | 8 ++++++++ .../alibaba/testable/core/model/MockScope.java | 15 +++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 testable-core/src/main/java/com/alibaba/testable/core/model/MockScope.java 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 + +}