diff --git a/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java index de4ef83cfd5..53684d54d51 100644 --- a/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/web/BasicAnnotationConfigWacTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,14 @@ package org.springframework.test.context.web; -import static org.junit.Assert.*; - import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; +import static org.junit.Assert.*; + /** * @author Sam Brannen * @since 3.2 @@ -37,12 +38,25 @@ public class BasicAnnotationConfigWacTests extends AbstractBasicWacTests { public String foo() { return "enigma"; } + + @Bean + public ServletContextAwareBean servletContextAwareBean() { + return new ServletContextAwareBean(); + } } + @Autowired + protected ServletContextAwareBean servletContextAwareBean; @Test public void fooEnigmaAutowired() { assertEquals("enigma", foo); } + @Test + public void servletContextAwareBeanProcessed() { + assertNotNull(servletContextAwareBean); + assertNotNull(servletContextAwareBean.servletContext); + } + } diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java new file mode 100644 index 00000000000..9b0be486b3c --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBean.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.web; + +import javax.servlet.ServletContext; + +import org.springframework.web.context.ServletContextAware; + +/** + * Introduced to investigate claims in SPR-11145. + * + * @author Sam Brannen + * @since 4.0.2 + */ +public class ServletContextAwareBean implements ServletContextAware { + + protected ServletContext servletContext; + + @Override + public void setServletContext(ServletContext servletContext) { + this.servletContext = servletContext; + } + +} diff --git a/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java new file mode 100644 index 00000000000..1c9275d9fab --- /dev/null +++ b/spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java @@ -0,0 +1,49 @@ +/* + * Copyright 2002-2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.web; + +import org.junit.Test; +import org.junit.runner.JUnitCore; +import org.springframework.test.context.junit4.TrackingRunListener; + +import static org.junit.Assert.*; + +/** + * Introduced to investigate claims in SPR-11145. + * + *

+ * Yes, this test class does in fact use JUnit to run JUnit. ;) + * + * @author Sam Brannen + * @since 4.0.2 + */ +public class ServletContextAwareBeanWacTests { + + @Test + public void ensureServletContextAwareBeanIsProcessedProperlyWhenExecutingJUnitManually() { + TrackingRunListener listener = new TrackingRunListener(); + JUnitCore junit = new JUnitCore(); + junit.addListener(listener); + + junit.run(BasicAnnotationConfigWacTests.class); + + assertEquals(3, listener.getTestStartedCount()); + assertEquals(3, listener.getTestFinishedCount()); + assertEquals(0, listener.getTestFailureCount()); + } + +}