Skip to content

Commit 0ebc86c

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java # spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java
2 parents c24e98e + 2c75eb8 commit 0ebc86c

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,25 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.core.annotation.AnnotatedElementUtils;
2221
import org.springframework.lang.Nullable;
2322
import org.springframework.test.context.ContextConfigurationAttributes;
2423
import org.springframework.test.context.ContextCustomizer;
2524
import org.springframework.test.context.ContextCustomizerFactory;
25+
import org.springframework.test.context.TestContextAnnotationUtils;
26+
import org.springframework.test.context.web.WebAppConfiguration;
2627
import org.springframework.util.ClassUtils;
2728

2829
/**
2930
* {@link ContextCustomizerFactory} which creates a {@link MockServerContainerContextCustomizer}
30-
* if WebSocket support is present in the classpath and the test class is annotated
31-
* with {@code @WebAppConfiguration}.
31+
* if WebSocket support is present in the classpath and the test class or one of
32+
* its enclosing classes is annotated or meta-annotated with
33+
* {@link WebAppConfiguration @WebAppConfiguration}.
3234
*
3335
* @author Sam Brannen
3436
* @since 4.3.1
3537
*/
3638
class MockServerContainerContextCustomizerFactory implements ContextCustomizerFactory {
3739

38-
private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME =
39-
"org.springframework.test.context.web.WebAppConfiguration";
40-
4140
private static final boolean webSocketPresent = ClassUtils.isPresent("jakarta.websocket.server.ServerContainer",
4241
MockServerContainerContextCustomizerFactory.class.getClassLoader());
4342

@@ -55,8 +54,7 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
5554
}
5655

5756
private static boolean isAnnotatedWithWebAppConfiguration(Class<?> testClass) {
58-
return (AnnotatedElementUtils.findMergedAnnotationAttributes(testClass,
59-
WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME, false, false) != null);
57+
return TestContextAnnotationUtils.hasAnnotation(testClass, WebAppConfiguration.class);
6058
}
6159

6260
}

spring-test/src/test/java/org/springframework/test/context/web/socket/WebSocketServletServerContainerFactoryBeanTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.test.context.web.socket;
1818

1919
import jakarta.websocket.server.ServerContainer;
20+
import org.junit.jupiter.api.Nested;
2021
import org.junit.jupiter.api.Test;
2122

2223
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,6 +46,20 @@ void servletServerContainerFactoryBeanSupport(@Autowired ServerContainer serverC
4546
assertThat(serverContainer.getDefaultMaxTextMessageBufferSize()).isEqualTo(42);
4647
}
4748

49+
/*
50+
* @Nested test class to verify that the MockServerContainerContextCustomizerFactory
51+
* properly supports finding @WebAppConfiguration on an enclosing class.
52+
*/
53+
@Nested
54+
class NestedTests {
55+
56+
@Test // gh-29037
57+
void servletServerContainerFactoryBeanSupport(@Autowired ServerContainer serverContainer) {
58+
assertThat(serverContainer.getDefaultMaxTextMessageBufferSize()).isEqualTo(42);
59+
}
60+
61+
}
62+
4863

4964
@Configuration
5065
@EnableWebSocket

0 commit comments

Comments
 (0)