Skip to content

Commit

Permalink
Abort MBeanServer tests if BindException encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Sep 24, 2019
1 parent d0adadf commit 435cc67
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +57,16 @@
*/
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;


Expand Down

0 comments on commit 435cc67

Please sign in to comment.