Skip to content

Commit 435cc67

Browse files
committed
Abort MBeanServer tests if BindException encountered
1 parent d0adadf commit 435cc67

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616

1717
package org.springframework.jmx;
1818

19+
import java.net.BindException;
20+
1921
import javax.management.MBeanServer;
2022
import javax.management.MBeanServerFactory;
2123
import javax.management.ObjectName;
2224

2325
import org.junit.jupiter.api.AfterEach;
2426
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.extension.RegisterExtension;
28+
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
29+
import org.opentest4j.TestAbortedException;
2530

2631
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
2732
import org.springframework.context.ConfigurableApplicationContext;
@@ -52,6 +57,16 @@
5257
*/
5358
public abstract class AbstractMBeanServerTests {
5459

60+
@RegisterExtension
61+
TestExecutionExceptionHandler bindExceptionHandler = (context, throwable) -> {
62+
// Abort test?
63+
if (throwable instanceof BindException) {
64+
throw new TestAbortedException("Failed to bind to MBeanServer", throwable);
65+
}
66+
// Else rethrow to conform to the contract of TestExecutionExceptionHandler
67+
throw throwable;
68+
};
69+
5570
protected MBeanServer server;
5671

5772

0 commit comments

Comments
 (0)