upgrade surefire plugin to fix conflict with junit 5

This commit is contained in:
金戟 2020-11-01 09:02:00 +08:00
parent df63bc5c74
commit 6f74ba771c
5 changed files with 27 additions and 6 deletions

View File

@ -17,6 +17,7 @@
<junit.version>5.6.2</junit.version>
<testable.version>0.2.2-SNAPSHOT</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>
</properties>
@ -90,6 +91,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.surefire.version}</version>
</plugin>
</plugins>
</build>

View File

@ -41,6 +41,8 @@ public class ClassUtil {
private static final String CLASS_BOOLEAN = "java/lang/Boolean";
private static final String METHOD_VALUE_OF = "valueOf";
private final static String JOINER = "::";
private static final Map<Byte, String> TYPE_MAPPING = new HashMap<Byte, String>();
private static final Map<ComparableWeakRef<String>, Boolean> loadedClass =
new WeakHashMap<ComparableWeakRef<String>, Boolean>();
@ -62,7 +64,8 @@ public class ClassUtil {
* @param annotationName annotation to look for
*/
public static boolean anyMethodHasAnnotation(String className, String annotationName) {
Boolean found = loadedClass.get(new ComparableWeakRef<String>(className));
String cacheKey = className + JOINER + annotationName;
Boolean found = loadedClass.get(new ComparableWeakRef<String>(cacheKey));
if (found != null) {
return found;
}
@ -73,7 +76,7 @@ public class ClassUtil {
if (mn.visibleAnnotations != null) {
for (AnnotationNode an : mn.visibleAnnotations) {
if (toDotSeparateFullClassName(an.desc).equals(annotationName)) {
loadedClass.put(new ComparableWeakRef<String>(className), true);
loadedClass.put(new ComparableWeakRef<String>(cacheKey), true);
return true;
}
}
@ -82,7 +85,7 @@ public class ClassUtil {
} catch (Exception e) {
// ignore
}
loadedClass.put(new ComparableWeakRef<String>(className), false);
loadedClass.put(new ComparableWeakRef<String>(cacheKey), false);
return false;
}

View File

@ -12,9 +12,9 @@ class ClassUtilTest {
@Test
void should_able_to_get_annotation() {
assertEquals(false, ClassUtil.anyMethodHasAnnotation("class.not.exist", ""));
assertEquals(false, ClassUtil.anyMethodHasAnnotation("org.junit.jupiter.api.Assertions", "annotation.not.exist"));
assertEquals(true, ClassUtil.anyMethodHasAnnotation("org.junit.jupiter.api.Assertions", "org.apiguardian.api.API"));
assertFalse(ClassUtil.anyMethodHasAnnotation("class.not.exist", ""));
assertFalse(ClassUtil.anyMethodHasAnnotation("com.alibaba.testable.agent.util.ClassUtilTest", "annotation.not.exist"));
assertTrue(ClassUtil.anyMethodHasAnnotation("com.alibaba.testable.agent.util.ClassUtilTest", "org.junit.jupiter.api.Test"));
}
@Test

View File

@ -15,6 +15,7 @@
<project.compiler.level>1.6</project.compiler.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.compiler.version>3.8.1</plugin.compiler.version>
<plugin.surefire.version>3.0.0-M5</plugin.surefire.version>
<junit.version>5.6.2</junit.version>
</properties>
@ -39,6 +40,11 @@
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${plugin.surefire.version}</version>
</plugin>
</plugins>
</build>

View File

@ -15,6 +15,7 @@
<project.compiler.level>1.6</project.compiler.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plugin.compiler.version>3.8.1</plugin.compiler.version>
<plugin.surefire.version>3.0.0-M5</plugin.surefire.version>
<junit.version>5.6.2</junit.version>
<testable.version>0.2.2-SNAPSHOT</testable.version>
</properties>
@ -53,6 +54,11 @@
<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>