From 435cc670269b1b0453c3f3a58f5918c752629694 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 24 Sep 2019 18:56:48 +0200 Subject: [PATCH] Abort MBeanServer tests if BindException encountered --- .../jmx/AbstractMBeanServerTests.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java b/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java index 6b7f11b98c..1e0d69fc0a 100644 --- a/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java +++ b/spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java @@ -16,12 +16,17 @@ package org.springframework.jmx; +import java.net.BindException; + import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.ObjectName; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.extension.TestExecutionExceptionHandler; +import org.opentest4j.TestAbortedException; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.context.ConfigurableApplicationContext; @@ -52,6 +57,16 @@ import static org.assertj.core.api.Assertions.assertThat; */ public abstract class AbstractMBeanServerTests { + @RegisterExtension + TestExecutionExceptionHandler bindExceptionHandler = (context, throwable) -> { + // Abort test? + if (throwable instanceof BindException) { + throw new TestAbortedException("Failed to bind to MBeanServer", throwable); + } + // Else rethrow to conform to the contract of TestExecutionExceptionHandler + throw throwable; + }; + protected MBeanServer server;