[SPR-8387] Fixed logic error in DelegatingSmartContextLoader.processContextConfiguration().

This commit is contained in:
Sam Brannen 2011-07-15 19:19:29 +00:00
parent b8624b470c
commit e34fa6abb1
3 changed files with 45 additions and 33 deletions

View File

@ -64,7 +64,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
*/
public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
final boolean hasResources = configAttributes.hasResources();
final boolean originallyHadResources = configAttributes.hasResources();
for (SmartContextLoader loader : candidates) {
if (logger.isDebugEnabled()) {
@ -75,7 +75,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
// If the original locations and classes were not empty, there's no
// need to bother with default generation checks; just let each
// loader process the configuration.
if (hasResources) {
if (originallyHadResources) {
loader.processContextConfiguration(configAttributes);
}
// Otherwise, if the loader claims to generate defaults, let it
@ -91,7 +91,7 @@ public class DelegatingSmartContextLoader implements SmartContextLoader {
// If any loader claims to generate defaults but none actually did,
// throw an exception.
if (generatesDefaults() && !configAttributes.hasResources()) {
if (originallyHadResources && generatesDefaults() && !configAttributes.hasResources()) {
throw new IllegalStateException(String.format("None of the SmartContextLoader candidates %s "
+ "was able to generate defaults for context configuration [%s].", candidates, configAttributes));
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2011 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.
@ -13,49 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.context.expression;
import static junit.framework.Assert.*;
import static junit.framework.Assert.assertEquals;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Andy Clement
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
public class ExpressionUsageTests {
@Test
public void testSpr5906() throws Exception {
Properties props = (Properties)applicationContext.getBean("derived");
// verify the property values have been evaluated as expressions
assertEquals("Dave",props.getProperty("user.name"));
assertEquals("Andy",props.getProperty("username"));
// verify the property keys have been evaluated as expressions
assertEquals("exists",props.getProperty("Dave"));
assertEquals("exists also",props.getProperty("Andy"));
}
public static class Foo {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Autowired
@Qualifier("derived")
private Properties props;
@Autowired
@Qualifier("andy2")
@ -65,10 +47,37 @@ public class ExpressionUsageTests extends AbstractJUnit4SpringContextTests {
@Qualifier("andy")
private Foo andy;
@Test
public void testSpr5906() throws Exception {
// verify the property values have been evaluated as expressions
assertEquals("Dave", props.getProperty("user.name"));
assertEquals("Andy", props.getProperty("username"));
// verify the property keys have been evaluated as expressions
assertEquals("exists", props.getProperty("Dave"));
assertEquals("exists also", props.getProperty("Andy"));
}
@Test
public void testSpr5847() throws Exception {
assertEquals("Andy", andy2.getName());
assertEquals("Andy", andy.getName());
}
}
public static class Foo {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -27,6 +27,9 @@
<logger name="org.springframework.test.context.support.AnnotationConfigContextLoader">
<level value="warn" />
</logger>
<logger name="org.springframework.test.context.support">
<level value="warn" />
</logger>
<!-- Root Logger -->
<root>