commit a23cdb29d9de1f62a89215b612f4c9d2cb4c6bc5 Author: 金戟 Date: Sat May 9 00:09:44 2020 +0800 add testable and testableinject annotation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2432c64 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# maven ignore +target/ +*.jar +*.war +*.zip +*.tar +*.tar.gz + +# eclipse ignore +.settings/ +.project +.classpath + +# idea ignore +.idea/ +*.ipr +*.iml +*.iws + +# temp ignore +*.log +*.cache +*.diff +*.patch +*.tmp +*.java~ +*.properties~ +*.xml~ + +# system ignore +.DS_Store +Thumbs.db + +# others +note/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a22bb8d --- /dev/null +++ b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + Testable + Unit test enhancement toolkit + com.alibaba + testable + 0.0.1-SNAPSHOT + + + 3.8.1 + 3.0.0-M4 + + UTF-8 + 1.7 + + + + + sun.jdk + tools + ${java.version} + system + ${java.home}/../lib/tools.jar + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${plugin.compiler.version} + + ${project.compiler.level} + ${project.compiler.level} + ${project.build.sourceEncoding} + + -proc:none + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${plugin.surefire.version} + + + + + diff --git a/src/main/java/com/alibaba/testable/annotation/Testable.java b/src/main/java/com/alibaba/testable/annotation/Testable.java new file mode 100644 index 0000000..5eaf1b8 --- /dev/null +++ b/src/main/java/com/alibaba/testable/annotation/Testable.java @@ -0,0 +1,17 @@ +package com.alibaba.testable.annotation; + +import java.lang.annotation.*; + +/** + * On type, make all methods in the class testable + * On method, make the method testable + * On field (in test class), fit the variable for unit test + * + * @author linfan + */ +@Retention(RetentionPolicy.SOURCE) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) +@Documented +public @interface Testable { + +} diff --git a/src/main/java/com/alibaba/testable/annotation/TestableInject.java b/src/main/java/com/alibaba/testable/annotation/TestableInject.java new file mode 100644 index 0000000..ae43884 --- /dev/null +++ b/src/main/java/com/alibaba/testable/annotation/TestableInject.java @@ -0,0 +1,14 @@ +package com.alibaba.testable.annotation; + +import java.lang.annotation.*; + +/** + * Use marked variable replace the ones in testable class + * + * @author linfan + */ +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.FIELD) +@Documented +public @interface TestableInject { +} diff --git a/src/main/java/com/alibaba/testable/processor/TestableInjectProcessor.java b/src/main/java/com/alibaba/testable/processor/TestableInjectProcessor.java new file mode 100644 index 0000000..960a231 --- /dev/null +++ b/src/main/java/com/alibaba/testable/processor/TestableInjectProcessor.java @@ -0,0 +1,15 @@ +package com.alibaba.testable.processor; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.TypeElement; +import java.util.Set; + +public class TestableInjectProcessor extends AbstractProcessor { + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return false; + } + +} diff --git a/src/main/java/com/alibaba/testable/processor/TestableProcessor.java b/src/main/java/com/alibaba/testable/processor/TestableProcessor.java new file mode 100644 index 0000000..15d2236 --- /dev/null +++ b/src/main/java/com/alibaba/testable/processor/TestableProcessor.java @@ -0,0 +1,15 @@ +package com.alibaba.testable.processor; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.lang.model.element.TypeElement; +import java.util.Set; + +public class TestableProcessor extends AbstractProcessor { + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return false; + } + +} diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 0000000..ca38b72 --- /dev/null +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1,2 @@ +com.alibaba.testable.processor.TestableProcessor +com.alibaba.testable.processor.TestableInjectProcessor