Skip to content

Commit e34fa6a

Browse files
committed
[SPR-8387] Fixed logic error in DelegatingSmartContextLoader.processContextConfiguration().
1 parent b8624b4 commit e34fa6a

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

org.springframework.test/src/main/java/org/springframework/test/context/support/DelegatingSmartContextLoader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean generatesDefaults() {
6464
*/
6565
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
6666

67-
final boolean hasResources = configAttributes.hasResources();
67+
final boolean originallyHadResources = configAttributes.hasResources();
6868

6969
for (SmartContextLoader loader : candidates) {
7070
if (logger.isDebugEnabled()) {
@@ -75,7 +75,7 @@ public void processContextConfiguration(ContextConfigurationAttributes configAtt
7575
// If the original locations and classes were not empty, there's no
7676
// need to bother with default generation checks; just let each
7777
// loader process the configuration.
78-
if (hasResources) {
78+
if (originallyHadResources) {
7979
loader.processContextConfiguration(configAttributes);
8080
}
8181
// Otherwise, if the loader claims to generate defaults, let it
@@ -91,7 +91,7 @@ else if (loader.generatesDefaults()) {
9191

9292
// If any loader claims to generate defaults but none actually did,
9393
// throw an exception.
94-
if (generatesDefaults() && !configAttributes.hasResources()) {
94+
if (originallyHadResources && generatesDefaults() && !configAttributes.hasResources()) {
9595
throw new IllegalStateException(String.format("None of the SmartContextLoader candidates %s "
9696
+ "was able to generate defaults for context configuration [%s].", candidates, configAttributes));
9797
}
Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2011 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,62 +13,71 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.test.context.expression;
1718

18-
import static junit.framework.Assert.*;
19+
import static junit.framework.Assert.assertEquals;
1920

2021
import java.util.Properties;
22+
2123
import org.junit.Test;
24+
import org.junit.runner.RunWith;
2225
import org.springframework.beans.factory.annotation.Autowired;
2326
import org.springframework.beans.factory.annotation.Qualifier;
2427
import org.springframework.test.context.ContextConfiguration;
25-
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
28+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2629

2730
/**
2831
* @author Andy Clement
2932
* @author Dave Syer
3033
*/
34+
@RunWith(SpringJUnit4ClassRunner.class)
3135
@ContextConfiguration
32-
public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
36+
public class ExpressionUsageTests {
37+
38+
@Autowired
39+
@Qualifier("derived")
40+
private Properties props;
41+
42+
@Autowired
43+
@Qualifier("andy2")
44+
private Foo andy2;
45+
46+
@Autowired
47+
@Qualifier("andy")
48+
private Foo andy;
49+
3350

3451
@Test
3552
public void testSpr5906() throws Exception {
36-
Properties props = (Properties)applicationContext.getBean("derived");
37-
3853
// verify the property values have been evaluated as expressions
39-
assertEquals("Dave",props.getProperty("user.name"));
40-
assertEquals("Andy",props.getProperty("username"));
41-
54+
assertEquals("Dave", props.getProperty("user.name"));
55+
assertEquals("Andy", props.getProperty("username"));
56+
4257
// verify the property keys have been evaluated as expressions
43-
assertEquals("exists",props.getProperty("Dave"));
44-
assertEquals("exists also",props.getProperty("Andy"));
58+
assertEquals("exists", props.getProperty("Dave"));
59+
assertEquals("exists also", props.getProperty("Andy"));
60+
}
61+
62+
@Test
63+
public void testSpr5847() throws Exception {
64+
assertEquals("Andy", andy2.getName());
65+
assertEquals("Andy", andy.getName());
4566
}
46-
67+
68+
4769
public static class Foo {
70+
4871
private String name;
4972

73+
5074
public String getName() {
5175
return name;
5276
}
5377

5478
public void setName(String name) {
5579
this.name = name;
5680
}
57-
58-
}
59-
60-
@Autowired
61-
@Qualifier("andy2")
62-
private Foo andy2;
63-
64-
@Autowired
65-
@Qualifier("andy")
66-
private Foo andy;
67-
68-
@Test
69-
public void testSpr5847() throws Exception {
70-
assertEquals("Andy", andy2.getName());
71-
assertEquals("Andy", andy.getName());
7281
}
7382

74-
}
83+
}

org.springframework.test/src/test/resources/log4j.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
<logger name="org.springframework.test.context.support.AnnotationConfigContextLoader">
2828
<level value="warn" />
2929
</logger>
30+
<logger name="org.springframework.test.context.support">
31+
<level value="warn" />
32+
</logger>
3033

3134
<!-- Root Logger -->
3235
<root>

0 commit comments

Comments
 (0)