bump version to 0.3.0, fix javadoc

This commit is contained in:
金戟 2020-11-17 15:33:39 +08:00
parent 85276e1c55
commit b275f32e44
16 changed files with 81 additions and 30 deletions

View File

@ -16,7 +16,7 @@
<properties>
<java.version>1.8</java.version>
<testable.version>0.2.2-SNAPSHOT</testable.version>
<testable.version>0.3.0</testable.version>
</properties>
<dependencies>

View File

@ -17,7 +17,7 @@
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.3.72</kotlin.version>
<testable.version>0.2.2-SNAPSHOT</testable.version>
<testable.version>0.3.0</testable.version>
</properties>
<dependencies>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-agent</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.3.0</version>
<packaging>jar</packaging>
<name>testable-agent</name>
<description>Unit test enhancement toolkit</description>
@ -35,14 +35,14 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<asm.lib.version>8.0.1</asm.lib.version>
<junit.version>5.6.2</junit.version>
<testable.version>0.2.2-SNAPSHOT</testable.version>
<testable.version>0.3.0</testable.version>
<plugin.compiler.version>3.8.1</plugin.compiler.version>
<plugin.surefire.version>3.0.0-M5</plugin.surefire.version>
<plugin.jar.version>3.2.0</plugin.jar.version>
<plugin.shade.version>3.2.4</plugin.shade.version>
<plugin.source.version>3.2.0</plugin.source.version>
<plugin.javadoc.version>3.2.0</plugin.javadoc.version>
<plugin.gpg.version>1.6.0</plugin.gpg.version>
<plugin.gpg.version>1.6</plugin.gpg.version>
<plugin.staging.version>1.6.8</plugin.staging.version>
</properties>
@ -174,7 +174,7 @@
<version>${plugin.staging.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<serverId>oss</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>

View File

@ -9,8 +9,14 @@ public class AnnotationUtil {
/**
* Read value of annotation parameter
* @param <T> template of target parameter type
* @param an annotation node
* @param key name of parameter to look for
* @param defaultValue value if parameter not exist
* @param clazz type of target parameter
* @return value of parameter
*/
public static <T> T getAnnotationParameter(AnnotationNode an, String key, T defaultValue, Class<T> clazz) {
public static <T> T getAnnotationParameter(AnnotationNode an, String key, T defaultValue, Class<T> clazz) {
if (an.values != null) {
for (int i = 0; i < an.values.size(); i += 2) {
if (an.values.get(i).equals(key)) {

View File

@ -65,6 +65,7 @@ public class ClassUtil {
* Check whether any method in specified class has specified annotation
* @param className class that need to explore
* @param annotationName annotation to look for
* @return found annotation or not
*/
public static boolean anyMethodHasAnnotation(String className, String annotationName) {
String cacheKey = className + JOINER + annotationName;
@ -95,6 +96,7 @@ public class ClassUtil {
/**
* fit kotlin companion class name to original name
* @param name a class name (which could be a companion class)
* @return is companion class or not
*/
public static boolean isCompanionClassName(String name) {
return name.endsWith("$Companion");
@ -103,6 +105,7 @@ public class ClassUtil {
/**
* fit kotlin companion class name to original name
* @param name a class name (which could be a companion class)
* @return original name
*/
public static String fitCompanionClassName(String name) {
return name.replaceAll("\\$Companion$", "");
@ -111,6 +114,7 @@ public class ClassUtil {
/**
* get test class name from source class name
* @param sourceClassName source class name
* @return test class name
*/
public static String getTestClassName(String sourceClassName) {
return sourceClassName + ConstPool.TEST_POSTFIX;
@ -119,6 +123,7 @@ public class ClassUtil {
/**
* get source class name from test class name
* @param testClassName test class name
* @return source class name
*/
public static String getSourceClassName(String testClassName) {
return testClassName.substring(0, testClassName.length() - ConstPool.TEST_POSTFIX.length());
@ -126,6 +131,8 @@ public class ClassUtil {
/**
* parse method desc, fetch parameter types
* @param desc method description
* @return list of parameter types
*/
public static List<Byte> getParameterTypes(String desc) {
List<Byte> parameterTypes = new ArrayList<Byte>();
@ -151,6 +158,8 @@ public class ClassUtil {
/**
* parse method desc, fetch return value types
* @param desc method description
* @return types of return value
*/
public static String getReturnType(String desc) {
int returnTypeEdge = desc.lastIndexOf(PARAM_END);
@ -169,6 +178,7 @@ public class ClassUtil {
/**
* Get method node to convert primary type to object type
* @param type primary type to convert
* @return converter method node
*/
public static MethodInsnNode getPrimaryTypeConvertMethod(Byte type) {
String objectType = TYPE_MAPPING.get(type);
@ -176,12 +186,10 @@ public class ClassUtil {
new MethodInsnNode(INVOKESTATIC, objectType, METHOD_VALUE_OF, toDescriptor(type, objectType), false);
}
private static String toDescriptor(Byte type, String objectType) {
return "(" + (char)type.byteValue() + ")L" + objectType + ";";
}
/**
* convert slash separated name to dot separated name
* @param name original name
* @return converted name
*/
public static String toDotSeparatedName(String name) {
return name.replace(ConstPool.SLASH, ConstPool.DOT);
@ -189,6 +197,8 @@ public class ClassUtil {
/**
* convert dot separated name to slash separated name
* @param name original name
* @return converted name
*/
public static String toSlashSeparatedName(String name) {
return name.replace(ConstPool.DOT, ConstPool.SLASH);
@ -196,6 +206,8 @@ public class ClassUtil {
/**
* convert dot separated name to byte code class name
* @param className original name
* @return converted name
*/
public static String toByteCodeClassName(String className) {
return (char)TYPE_CLASS + toSlashSeparatedName(className) + (char)CLASS_END;
@ -203,6 +215,8 @@ public class ClassUtil {
/**
* convert byte code class name to dot separated human readable name
* @param className original name
* @return converted name
*/
public static String toDotSeparateFullClassName(String className) {
return toDotSeparatedName(className).substring(1, className.length() - 1);
@ -210,11 +224,17 @@ public class ClassUtil {
/**
* convert byte code class name to slash separated human readable name
* @param className original name
* @return converted name
*/
public static String toSlashSeparateFullClassName(String className) {
return toSlashSeparatedName(className).substring(1, className.length() - 1);
}
private static String toDescriptor(Byte type, String objectType) {
return "(" + (char)type.byteValue() + ")L" + objectType + ";";
}
private static boolean isPrimaryType(byte b) {
return b == TYPE_BYTE || b == TYPE_CHAR || b == TYPE_DOUBLE || b == TYPE_FLOAT
|| b == TYPE_INT || b == TYPE_LONG || b == TYPE_SHORT || b == TYPE_BOOL;

View File

@ -11,8 +11,9 @@ public class CollectionUtil {
* Check two collection has any equaled item
* @param collectionLeft the first collection
* @param collectionRight the second collection
* @return found or not
*/
public static boolean containsAny(Collection collectionLeft, Collection collectionRight) {
public static boolean containsAny(Collection<?> collectionLeft, Collection<?> collectionRight) {
for (Object o : collectionLeft) {
for (Object i : collectionRight) {
if (o.equals(i)) {
@ -26,6 +27,7 @@ public class CollectionUtil {
/**
* Generate a list of item
* @param items elements to add
* @return a ArrayList of provided elements
*/
public static <T> List<T> listOf(T... items) {
List<T> list = new ArrayList<T>(items.length);

View File

@ -9,6 +9,7 @@ public class StringUtil {
* repeat a text many times
* @param text content to repeat
* @param times count of repeating
* @return joined string
*/
public static String repeat(String text, int times) {
StringBuilder sb = new StringBuilder();

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-core</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.3.0</version>
<packaging>jar</packaging>
<name>testable-core</name>
<description>Unit test enhancement toolkit</description>
@ -38,7 +38,7 @@
<plugin.surefire.version>3.0.0-M5</plugin.surefire.version>
<plugin.source.version>3.2.0</plugin.source.version>
<plugin.javadoc.version>3.2.0</plugin.javadoc.version>
<plugin.gpg.version>1.6.0</plugin.gpg.version>
<plugin.gpg.version>1.6</plugin.gpg.version>
<plugin.staging.version>1.6.8</plugin.staging.version>
</properties>
@ -122,7 +122,7 @@
<version>${plugin.staging.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<serverId>oss</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>

View File

@ -23,6 +23,7 @@ public class InvokeVerifier {
/**
* Get counter to check whether specified mock method invoked
* @param mockMethodName name of a mock method
* @return the verifier object
*/
public static InvokeVerifier verify(String mockMethodName) {
String testClass = Thread.currentThread().getStackTrace()[InvokeRecordUtil.INDEX_OF_TEST_CLASS].getClassName();
@ -33,6 +34,7 @@ public class InvokeVerifier {
/**
* Expect mock method invoked with specified parameters
* @param args parameters to compare
* @return the verifier object
*/
public InvokeVerifier with(Object... args) {
boolean found = false;
@ -55,6 +57,7 @@ public class InvokeVerifier {
/**
* Expect next mock method call was invoked with specified parameters
* @param args parameters to compare
* @return the verifier object
*/
public InvokeVerifier withInOrder(Object... args) {
withInternal(args, 0);
@ -65,6 +68,7 @@ public class InvokeVerifier {
/**
* Expect mock method had never invoked with specified parameters
* @param args parameters to compare
* @return the verifier object
*/
public InvokeVerifier without(Object... args) {
for (Object[] r : records) {
@ -86,6 +90,7 @@ public class InvokeVerifier {
/**
* Expect mock method have been invoked specified times
* @param expectedCount times to compare
* @return the verifier object
*/
public InvokeVerifier withTimes(int expectedCount) {
if (expectedCount != records.size()) {
@ -98,6 +103,7 @@ public class InvokeVerifier {
/**
* Expect several consecutive invocations with the same parameters
* @param count number of invocations
* @return the verifier object
*/
public InvokeVerifier times(int count) {
if (lastVerification == null) {

View File

@ -11,18 +11,20 @@ import java.util.Map;
public class InvokeRecordUtil {
/**
* Mock method name -> List of invoke parameters
* Mock method name List of invoke parameters
*/
private static final Map<String, List<Object[]>> INVOKE_RECORDS = new HashMap<String, List<Object[]>>();
private final static String JOINER = "::";
/**
* [0]Thread -> [1]TestableUtil/TestableTool -> [2]TestClass
* [0]Thread [1]TestableUtil/TestableTool [2]TestClass
*/
public static final int INDEX_OF_TEST_CLASS = 2;
/**
* Record mock method invoke event
* @param args invocation parameters
* @param isConstructor whether mocked method is constructor
*/
public static void recordMockInvoke(Object[] args, boolean isConstructor) {
StackTraceElement mockMethodTraceElement = Thread.currentThread().getStackTrace()[INDEX_OF_TEST_CLASS];
@ -41,6 +43,9 @@ public class InvokeRecordUtil {
/**
* Get mock method invoke count
* @param mockMethodName mock method name
* @param testCaseName test case name
* @return parameters used when specified method invoked in specified test case
*/
public static List<Object[]> getInvokeRecord(String mockMethodName, String testCaseName) {
String key = testCaseName + JOINER + mockMethodName;

View File

@ -52,6 +52,7 @@ public class TestableUtil {
/**
* Get file name and line number of where current method was called
* @return in "filename:linenumber" format
*/
public static String getPreviousStackLocation() {
// 0 - Thread.getStackTrace(), 1 - this method, 2 - code call this method, 3 - code call the caller method

View File

@ -9,6 +9,8 @@ public class TypeUtil {
/**
* get classes of parameter objects
* @param parameterObjects objects
* @return class of those objects
*/
public static Class<?>[] getClassesFromObjects(Object[] parameterObjects) {
Class<?>[] cs = new Class[parameterObjects.length];
@ -20,13 +22,16 @@ public class TypeUtil {
/**
* get method by name and parameter matching
* @param availableMethods available methods
* @param methodName method to look for
* @param parameterTypes class to look for
* @return method which match the name and class
*/
public static Method getMethodByNameAndParameterTypes(Method[] availableMethods,
String methodName,
Class<?>[] parameterTypes) {
for (Method m : availableMethods) {
if (m.getName().equals(methodName) &&
typeEquals(m.getParameterTypes(), parameterTypes)) {
if (m.getName().equals(methodName) && typeEquals(m.getParameterTypes(), parameterTypes)) {
return m;
}
}
@ -35,6 +40,9 @@ public class TypeUtil {
/**
* type equals
* @param classesLeft class to be compared
* @param classesRight class to compare
* @return whether all class equals
*/
private static boolean typeEquals(Class<?>[] classesLeft, Class<?>[] classesRight) {
if (classesLeft.length != classesRight.length) {
@ -53,6 +61,7 @@ public class TypeUtil {
* fuzzy equal
* @param factTypes fact types (can be primary type)
* @param userTypes user types
* @return whether all class equals
*/
private static boolean fuzzyEqual(Class<?> factTypes, Class<?> userTypes) {
return (factTypes.equals(int.class) && userTypes.equals(Integer.class)) ||

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-maven-plugin</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.3.0</version>
<packaging>maven-plugin</packaging>
<name>testable-maven-plugin</name>
<description>Unit test enhancement toolkit</description>
@ -30,7 +30,7 @@
</scm>
<properties>
<testable.version>0.2.2-SNAPSHOT</testable.version>
<testable.version>0.3.0</testable.version>
<java.version>1.6</java.version>
<project.compiler.level>1.6</project.compiler.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -38,7 +38,7 @@
<plugin.maven.version>3.6.0</plugin.maven.version>
<plugin.source.version>3.2.0</plugin.source.version>
<plugin.javadoc.version>3.2.0</plugin.javadoc.version>
<plugin.gpg.version>1.6.0</plugin.gpg.version>
<plugin.gpg.version>1.6</plugin.gpg.version>
<plugin.staging.version>1.6.8</plugin.staging.version>
</properties>
@ -137,7 +137,7 @@
<version>${plugin.staging.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<serverId>oss</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alibaba.testable</groupId>
<artifactId>testable-processor</artifactId>
<version>0.2.2-SNAPSHOT</version>
<version>0.3.0</version>
<packaging>jar</packaging>
<name>testable-processor</name>
<description>Unit test enhancement toolkit</description>
@ -34,12 +34,12 @@
<project.compiler.level>1.6</project.compiler.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.6.2</junit.version>
<testable.version>0.2.2-SNAPSHOT</testable.version>
<testable.version>0.3.0</testable.version>
<plugin.compiler.version>3.8.1</plugin.compiler.version>
<plugin.surefire.version>3.0.0-M5</plugin.surefire.version>
<plugin.source.version>3.2.0</plugin.source.version>
<plugin.javadoc.version>3.2.0</plugin.javadoc.version>
<plugin.gpg.version>1.6.0</plugin.gpg.version>
<plugin.gpg.version>1.6</plugin.gpg.version>
<plugin.staging.version>1.6.8</plugin.staging.version>
</properties>
@ -146,7 +146,7 @@
<version>${plugin.staging.version}</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<serverId>oss</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>

View File

@ -69,8 +69,8 @@ public class EnablePrivateAccessTranslator extends BaseTranslator {
}
/**
* d.privateField = val -> PrivateAccessor.set(d, "privateField", val)
* d.privateMethod(args) -> PrivateAccessor.invoke(d, "privateMethod", args)
* d.privateField = val PrivateAccessor.set(d, "privateField", val)
* d.privateMethod(args) PrivateAccessor.invoke(d, "privateMethod", args)
*/
@Override
public void visitExec(JCExpressionStatement jcExpressionStatement) {
@ -87,7 +87,7 @@ public class EnablePrivateAccessTranslator extends BaseTranslator {
/**
* For private invoke invocation break point
* call(d.privateMethod(args)) -> call(PrivateAccessor.invoke(d, "privateMethod", args))
* call(d.privateMethod(args)) call(PrivateAccessor.invoke(d, "privateMethod", args))
*/
@Override
public void visitApply(JCMethodInvocation tree) {

View File

@ -11,6 +11,7 @@ public class StringUtil {
* Join strings
* @param list strings to join
* @param conjunction connection character
* @return joined string
*/
static public String join(List<String> list, String conjunction)
{