From 9ab2f98df03b7653d0a02b0869cc831377f04f7a Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Mon, 17 Jun 2013 16:44:28 -0400 Subject: [PATCH] Tune expected exceptions to support more platforms It appears that some machines break when looking for ConnectionException, but not SocketException, both of which are IOExceptions. This seems to make tests pass on more machines without compromising the intentions of the API. [BS-162] --- .../EndpointWebMvcAutoConfigurationTests.java | 5 +++-- .../AbstractEmbeddedServletContainerFactoryTests.java | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java index a72771dcea..093ef5681a 100644 --- a/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java +++ b/spring-bootstrap-actuator/src/test/java/org/springframework/bootstrap/actuate/autoconfigure/EndpointWebMvcAutoConfigurationTests.java @@ -16,7 +16,7 @@ package org.springframework.bootstrap.actuate.autoconfigure; import java.io.FileNotFoundException; -import java.net.ConnectException; +import java.net.SocketException; import java.net.URI; import java.nio.charset.Charset; @@ -49,6 +49,7 @@ import static org.junit.Assert.assertThat; * Tests for {@link EndpointWebMvcAutoConfiguration}. * * @author Phillip Webb + * @author Greg Turnquist */ public class EndpointWebMvcAutoConfigurationTests { @@ -170,7 +171,7 @@ public class EndpointWebMvcAutoConfigurationTests { } } catch (Exception ex) { if (expected == null) { - if (ConnectException.class.isInstance(ex) + if (SocketException.class.isInstance(ex) || FileNotFoundException.class.isInstance(ex)) { return; } diff --git a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index f231c1d7db..a9c0b28920 100644 --- a/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-bootstrap/src/test/java/org/springframework/bootstrap/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -18,7 +18,7 @@ package org.springframework.bootstrap.context.embedded; import java.io.FileWriter; import java.io.IOException; -import java.net.ConnectException; +import java.net.SocketException; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; @@ -56,6 +56,7 @@ import static org.mockito.Mockito.mock; * Base for testing classes that extends {@link AbstractEmbeddedServletContainerFactory}. * * @author Phillip Webb + * @author Greg Turnquist */ public abstract class AbstractEmbeddedServletContainerFactoryTests { @@ -91,8 +92,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { factory.setPort(0); this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); - this.thrown.expect(ConnectException.class); - this.thrown.expectMessage("Connection refused"); + this.thrown.expect(SocketException.class); getResponse("http://localhost:8080/hello"); } @@ -102,7 +102,7 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { this.container = factory .getEmbeddedServletContainer(exampleServletRegistration()); this.container.stop(); - this.thrown.expect(ConnectException.class); + this.thrown.expect(SocketException.class); getResponse("http://localhost:8080/hello"); }