From 7ed1a26c2ddbbb634981986e8632a64672b990cb Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Mon, 27 Feb 2017 16:44:50 -0800 Subject: [PATCH] Fix test failures when running in Eclipse Update MultipartAutoConfigurationTests to reset the Tomcat URL factory. --- .../web/MultipartAutoConfigurationTests.java | 12 ++++++++++++ .../ServerPropertiesAutoConfigurationTests.java | 13 +++++++++++++ .../websocket/WebSocketAutoConfigurationTests.java | 14 ++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java index ae64e4427c..58430d779f 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java @@ -17,10 +17,14 @@ package org.springframework.boot.autoconfigure.web; import java.net.URI; +import java.net.URL; import javax.servlet.MultipartConfigElement; +import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -76,6 +80,14 @@ public class MultipartAutoConfigurationTests { } } + @BeforeClass + @AfterClass + public static void uninstallUrlStreamHandlerFactory() { + ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", + null); + ReflectionTestUtils.setField(URL.class, "factory", null); + } + @Test public void containerWithNothing() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext( diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java index 0c2ad2fa72..a91c8930ae 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java @@ -17,9 +17,13 @@ package org.springframework.boot.autoconfigure.web; import java.io.File; +import java.net.URL; +import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -38,6 +42,7 @@ import org.springframework.boot.test.util.EnvironmentTestUtils; import org.springframework.context.ApplicationContextException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -70,6 +75,14 @@ public class ServerPropertiesAutoConfigurationTests { } } + @BeforeClass + @AfterClass + public static void uninstallUrlStreamHandlerFactory() { + ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", + null); + ReflectionTestUtils.setField(URL.class, "factory", null); + } + @Test public void createFromConfigClass() throws Exception { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java index 1fd20d3382..050fae10cd 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/WebSocketAutoConfigurationTests.java @@ -16,10 +16,15 @@ package org.springframework.boot.autoconfigure.websocket; +import java.net.URL; + import javax.websocket.server.ServerContainer; +import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; @@ -29,6 +34,7 @@ import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletConta import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -53,6 +59,14 @@ public class WebSocketAutoConfigurationTests { } } + @BeforeClass + @AfterClass + public static void uninstallUrlStreamHandlerFactory() { + ReflectionTestUtils.setField(TomcatURLStreamHandlerFactory.class, "instance", + null); + ReflectionTestUtils.setField(URL.class, "factory", null); + } + @Test public void tomcatServerContainerIsAvailableFromTheServletContext() { serverContainerIsAvailableFromTheServletContext(TomcatConfiguration.class,