Skip to content

Commit c290839

Browse files
committed
Investigate claim on SO regarding ctx cache in TCF
This commit introduces a test that investigates a claim made on Stack Overflow regarding context caching in the TestContext Framework (TCF).
1 parent 48fea0b commit c290839

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spring-test/src/test/java/org/springframework/test/context/support/AbstractContextLoaderUtilsTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.test.context.ContextLoader;
3737
import org.springframework.test.context.MergedContextConfiguration;
3838
import org.springframework.test.context.TestContextBootstrapper;
39+
import org.springframework.test.context.web.WebAppConfiguration;
3940

4041
import static org.junit.Assert.*;
4142

@@ -170,6 +171,10 @@ static class LocationsFoo {
170171
static class ClassesFoo {
171172
}
172173

174+
@WebAppConfiguration
175+
static class WebClassesFoo extends ClassesFoo {
176+
}
177+
173178
@ContextConfiguration(locations = "/bar.xml", inheritLocations = true, loader = AnnotationConfigContextLoader.class)
174179
@ActiveProfiles("bar")
175180
static class LocationsBar extends LocationsFoo {

spring-test/src/test/java/org/springframework/test/context/support/ContextLoaderUtilsMergedConfigTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import org.springframework.test.context.ContextConfiguration;
2626
import org.springframework.test.context.ContextLoader;
2727
import org.springframework.test.context.MergedContextConfiguration;
28+
import org.springframework.test.context.web.WebDelegatingSmartContextLoader;
29+
import org.springframework.test.context.web.WebMergedContextConfiguration;
30+
31+
import static org.junit.Assert.*;
2832

2933
/**
3034
* Unit tests for {@link ContextLoaderUtils} involving {@link MergedContextConfiguration}.
@@ -94,6 +98,28 @@ public void buildMergedConfigWithLocalAnnotationAndClasses() {
9498
DelegatingSmartContextLoader.class);
9599
}
96100

101+
/**
102+
* Introduced to investigate claims made in a discussion on
103+
* <a href="http://stackoverflow.com/questions/24725438/what-could-cause-a-class-implementing-applicationlistenercontextrefreshedevent">Stack Overflow</a>.
104+
*/
105+
@Test
106+
public void buildMergedConfigWithAtWebAppConfigurationWithAnnotationAndClassesOnSuperclass() {
107+
Class<?> webTestClass = WebClassesFoo.class;
108+
Class<?> standardTestClass = ClassesFoo.class;
109+
WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) buildMergedContextConfiguration(webTestClass);
110+
MergedContextConfiguration standardMergedConfig = buildMergedContextConfiguration(standardTestClass);
111+
112+
assertEquals(webMergedConfig, webMergedConfig);
113+
assertEquals(standardMergedConfig, standardMergedConfig);
114+
assertNotEquals(standardMergedConfig, webMergedConfig);
115+
assertNotEquals(webMergedConfig, standardMergedConfig);
116+
117+
assertMergedConfig(webMergedConfig, webTestClass, EMPTY_STRING_ARRAY, new Class<?>[] { FooConfig.class },
118+
WebDelegatingSmartContextLoader.class);
119+
assertMergedConfig(standardMergedConfig, standardTestClass, EMPTY_STRING_ARRAY,
120+
new Class<?>[] { FooConfig.class }, DelegatingSmartContextLoader.class);
121+
}
122+
97123
@Test
98124
public void buildMergedConfigWithLocalAnnotationAndOverriddenContextLoaderAndLocations() {
99125
Class<?> testClass = PropertiesLocationsFoo.class;

0 commit comments

Comments
 (0)