add testable and testableinject annotation

This commit is contained in:
金戟 2020-05-09 00:09:44 +08:00
commit a23cdb29d9
7 changed files with 153 additions and 0 deletions

35
.gitignore vendored Normal file
View File

@ -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/

55
pom.xml Normal file
View File

@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Testable</name>
<description>Unit test enhancement toolkit</description>
<groupId>com.alibaba</groupId>
<artifactId>testable</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<plugin.compiler.version>3.8.1</plugin.compiler.version>
<plugin.surefire.version>3.0.0-M4</plugin.surefire.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.compiler.level>1.7</project.compiler.level>
</properties>
<dependencies>
<dependency>
<groupId>sun.jdk</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<!--compiler plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${plugin.compiler.version}</version>
<configuration>
<source>${project.compiler.level}</source>
<target>${project.compiler.level}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<!--指定为不编译-->
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.surefire.version}</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -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 {
}

View File

@ -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 {
}

View File

@ -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<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}

View File

@ -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<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
return false;
}
}

View File

@ -0,0 +1,2 @@
com.alibaba.testable.processor.TestableProcessor
com.alibaba.testable.processor.TestableInjectProcessor