allow default mock with target

This commit is contained in:
金戟 2021-02-21 10:49:30 +08:00
parent 55ccabbb39
commit f9621a6f2e
2 changed files with 3 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InnerClassNode; import org.objectweb.asm.tree.InnerClassNode;
import javax.lang.model.type.NullType;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -229,10 +230,8 @@ public class TestableClassTransformer implements ClassFileTransformer {
ClassType type = AnnotationUtil.getAnnotationParameter(an, FIELD_TREAT_AS, ClassType.GuessByName, ClassType type = AnnotationUtil.getAnnotationParameter(an, FIELD_TREAT_AS, ClassType.GuessByName,
ClassType.class); ClassType.class);
if (isExpectedType(cn.name, type, expectedType)) { if (isExpectedType(cn.name, type, expectedType)) {
Type clazz = AnnotationUtil.getAnnotationParameter(an, FIELD_VALUE, null, Type.class); Type clazz = AnnotationUtil.getAnnotationParameter(an, FIELD_VALUE,
if (clazz == null) { Type.getType(NullType.class), Type.class);
return null;
}
return clazz.getClassName(); return clazz.getClassName();
} }
} }

View File

@ -18,7 +18,6 @@ public @interface MockWith {
/** /**
* explicitly specify mock class * explicitly specify mock class
* @note this parameter will become mandatory in v0.6
* @return type of mock class * @return type of mock class
*/ */
Class<?> value() default NullType.class; Class<?> value() default NullType.class;