fix diagnose setup when using MockWith annotation

This commit is contained in:
金戟 2021-02-24 21:29:48 +08:00
parent 8dfd0b4516
commit 9e7ceb2dc1
2 changed files with 6 additions and 5 deletions

View File

@ -232,6 +232,7 @@ public class TestableClassTransformer implements ClassFileTransformer {
if (isExpectedType(cn.name, type, expectedType)) {
Type clazz = AnnotationUtil.getAnnotationParameter(an, FIELD_VALUE,
Type.getType(NullType.class), Type.class);
DiagnoseUtil.setupByClass(ClassUtil.getClassNode(clazz.getClassName()));
return clazz.getClassName();
}
}

View File

@ -15,21 +15,21 @@ public class DiagnoseUtil {
private static final String FIELD_DIAGNOSE = "diagnose";
public static void setupByClass(ClassNode cn) {
if (cn.visibleAnnotations == null) {
if (cn == null || cn.visibleAnnotations == null) {
return;
}
for (AnnotationNode an : cn.visibleAnnotations) {
setupByAnnotation(an);
if (toDotSeparateFullClassName(an.desc).equals(ConstPool.MOCK_DIAGNOSE)) {
setupDiagnose(an, FIELD_VALUE);
}
}
}
public static void setupByAnnotation(AnnotationNode an) {
// to be remove in v0.6
if (toDotSeparateFullClassName(an.desc).equals(MOCK_WITH)) {
setupDiagnose(an, FIELD_DIAGNOSE);
}
if (toDotSeparateFullClassName(an.desc).equals(ConstPool.MOCK_DIAGNOSE)) {
setupDiagnose(an, FIELD_VALUE);
}
}
private static void setupDiagnose(AnnotationNode an, String fieldDiagnose) {