|
17 | 17 | package io.zonky.test.db.util; |
18 | 18 |
|
19 | 19 | import io.zonky.test.db.AutoConfigureEmbeddedDatabase; |
20 | | -import io.zonky.test.db.AutoConfigureEmbeddedDatabase.Replace; |
21 | | -import io.zonky.test.db.AutoConfigureEmbeddedDatabases; |
22 | 20 | import org.springframework.core.annotation.AnnotatedElementUtils; |
| 21 | +import org.springframework.util.ClassUtils; |
23 | 22 |
|
24 | 23 | import java.util.LinkedHashSet; |
25 | 24 | import java.util.Set; |
26 | 25 | import java.util.concurrent.ConcurrentHashMap; |
27 | 26 | import java.util.function.Function; |
28 | 27 | import java.util.function.Predicate; |
29 | 28 |
|
| 29 | +import static io.zonky.test.db.util.ReflectionUtils.invokeStaticMethod; |
30 | 30 | import static java.util.stream.Collectors.toCollection; |
31 | 31 |
|
32 | 32 | public class AnnotationUtils { |
33 | 33 |
|
| 34 | + private static final Class<?> testContextAnnotationUtilsClass; |
| 35 | + |
| 36 | + static { |
| 37 | + Class<?> targetClass; |
| 38 | + try { |
| 39 | + ClassLoader classLoader = AnnotationUtils.class.getClassLoader(); |
| 40 | + targetClass = ClassUtils.forName("org.springframework.test.context.TestContextAnnotationUtils", classLoader); |
| 41 | + } catch (ClassNotFoundException e) { |
| 42 | + targetClass = null; |
| 43 | + } |
| 44 | + testContextAnnotationUtilsClass = targetClass; |
| 45 | + } |
| 46 | + |
34 | 47 | private AnnotationUtils() {} |
35 | 48 |
|
36 | 49 | public static Set<AutoConfigureEmbeddedDatabase> getDatabaseAnnotations(Class<?> annotatedElement) { |
37 | | - Set<AutoConfigureEmbeddedDatabase> annotations = AnnotatedElementUtils.getMergedRepeatableAnnotations( |
38 | | - annotatedElement, AutoConfigureEmbeddedDatabase.class, AutoConfigureEmbeddedDatabases.class); |
| 50 | + Set<AutoConfigureEmbeddedDatabase> annotations; |
| 51 | + |
| 52 | + if (testContextAnnotationUtilsClass != null) { |
| 53 | + annotations = invokeStaticMethod(testContextAnnotationUtilsClass, "getMergedRepeatableAnnotations", annotatedElement, AutoConfigureEmbeddedDatabase.class); |
| 54 | + } else { |
| 55 | + annotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(annotatedElement, AutoConfigureEmbeddedDatabase.class); |
| 56 | + } |
39 | 57 |
|
40 | 58 | return annotations.stream() |
41 | 59 | .filter(distinctByKey(AutoConfigureEmbeddedDatabase::beanName)) |
|
0 commit comments