From 9e7ceb2dc1394b78740df5b941ce8d5445f6a9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Wed, 24 Feb 2021 21:29:48 +0800 Subject: [PATCH] fix diagnose setup when using MockWith annotation --- .../agent/transformer/TestableClassTransformer.java | 1 + .../com/alibaba/testable/agent/util/DiagnoseUtil.java | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java index 1612dd0..ea5d4c4 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/transformer/TestableClassTransformer.java @@ -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(); } } diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/util/DiagnoseUtil.java b/testable-agent/src/main/java/com/alibaba/testable/agent/util/DiagnoseUtil.java index 2b67dbf..0e4221a 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/util/DiagnoseUtil.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/util/DiagnoseUtil.java @@ -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) {