|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import java.util.List;
|
20 | 20 |
|
21 | 21 | import org.springframework.beans.BeanUtils;
|
22 |
| -import org.springframework.core.annotation.AnnotatedElementUtils; |
23 | 22 | import org.springframework.lang.Nullable;
|
24 | 23 | import org.springframework.test.context.ContextConfigurationAttributes;
|
25 | 24 | import org.springframework.test.context.ContextCustomizer;
|
26 | 25 | import org.springframework.test.context.ContextCustomizerFactory;
|
| 26 | +import org.springframework.test.context.TestContextAnnotationUtils; |
| 27 | +import org.springframework.test.context.web.WebAppConfiguration; |
27 | 28 | import org.springframework.util.ClassUtils;
|
28 | 29 |
|
29 | 30 | /**
|
30 | 31 | * {@link ContextCustomizerFactory} which creates a {@link MockServerContainerContextCustomizer}
|
31 |
| - * if WebSocket support is present in the classpath and the test class is annotated |
32 |
| - * with {@code @WebAppConfiguration}. |
| 32 | + * if WebSocket support is present in the classpath and the test class or one of |
| 33 | + * its enclosing classes is annotated or meta-annotated with |
| 34 | + * {@link WebAppConfiguration @WebAppConfiguration}. |
33 | 35 | *
|
34 | 36 | * @author Sam Brannen
|
35 | 37 | * @since 4.3.1
|
36 | 38 | */
|
37 | 39 | class MockServerContainerContextCustomizerFactory implements ContextCustomizerFactory {
|
38 | 40 |
|
39 |
| - private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME = |
40 |
| - "org.springframework.test.context.web.WebAppConfiguration"; |
41 |
| - |
42 | 41 | private static final String MOCK_SERVER_CONTAINER_CONTEXT_CUSTOMIZER_CLASS_NAME =
|
43 | 42 | "org.springframework.test.context.web.socket.MockServerContainerContextCustomizer";
|
44 | 43 |
|
@@ -68,8 +67,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
|
68 | 67 | }
|
69 | 68 |
|
70 | 69 | private static boolean isAnnotatedWithWebAppConfiguration(Class<?> testClass) {
|
71 |
| - return (AnnotatedElementUtils.findMergedAnnotationAttributes(testClass, |
72 |
| - WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false) != null); |
| 70 | + return TestContextAnnotationUtils.hasAnnotation(testClass, WebAppConfiguration.class); |
73 | 71 | }
|
74 | 72 |
|
75 | 73 | }
|
0 commit comments