Skip to content

Commit c24e98e

Browse files
committed
Avoid reflection for instantiating MockServerContainerContextCustomizer
Since MockServerContainerContextCustomizerFactory already has a `webSocketPresent` check, there should be no need to instantiate MockServerContainerContextCustomizer via reflection. See spring-projectsgh-29028 Closes spring-projectsgh-29035
1 parent 92b5827 commit c24e98e

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 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.
@@ -18,7 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import org.springframework.beans.BeanUtils;
2221
import org.springframework.core.annotation.AnnotatedElementUtils;
2322
import org.springframework.lang.Nullable;
2423
import org.springframework.test.context.ContextConfigurationAttributes;
@@ -39,9 +38,6 @@ class MockServerContainerContextCustomizerFactory implements ContextCustomizerFa
3938
private static final String WEB_APP_CONFIGURATION_ANNOTATION_CLASS_NAME =
4039
"org.springframework.test.context.web.WebAppConfiguration";
4140

42-
private static final String MOCK_SERVER_CONTAINER_CONTEXT_CUSTOMIZER_CLASS_NAME =
43-
"org.springframework.test.context.web.socket.MockServerContainerContextCustomizer";
44-
4541
private static final boolean webSocketPresent = ClassUtils.isPresent("jakarta.websocket.server.ServerContainer",
4642
MockServerContainerContextCustomizerFactory.class.getClassLoader());
4743

@@ -52,17 +48,8 @@ public ContextCustomizer createContextCustomizer(Class<?> testClass,
5248
List<ContextConfigurationAttributes> configAttributes) {
5349

5450
if (webSocketPresent && isAnnotatedWithWebAppConfiguration(testClass)) {
55-
try {
56-
Class<?> clazz = ClassUtils.forName(MOCK_SERVER_CONTAINER_CONTEXT_CUSTOMIZER_CLASS_NAME,
57-
getClass().getClassLoader());
58-
return (ContextCustomizer) BeanUtils.instantiateClass(clazz);
59-
}
60-
catch (Throwable ex) {
61-
throw new IllegalStateException("Failed to enable WebSocket test support; could not load class: " +
62-
MOCK_SERVER_CONTAINER_CONTEXT_CUSTOMIZER_CLASS_NAME, ex);
63-
}
51+
return new MockServerContainerContextCustomizer();
6452
}
65-
6653
// Else, nothing to customize
6754
return null;
6855
}

0 commit comments

Comments
 (0)