Fix [deprecation] compiler warnings

Fix deprecation compiler warnings by refactoring code or applying
@SuppressWarnings("deprecation") annotations. JUnit tests of
internally deprecated classes are now themselves marked as
@Deprecated.

Numerous EasyMock deprecation warnings will remain until the
migration to mockito can be completed.
This commit is contained in:
Phillip Webb
2012-12-31 13:08:39 -08:00
parent 9364043a64
commit 6626a38730
153 changed files with 1665 additions and 1188 deletions

View File

@@ -16,16 +16,21 @@
package org.springframework.beans.factory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.StaticListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.cglib.proxy.NoOp;
import org.springframework.core.io.Resource;
import org.springframework.util.ObjectUtils;
@@ -35,9 +40,6 @@ import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.TestBean;
import static org.junit.Assert.*;
import static test.util.TestResourceUtils.qualifiedResource;
/**
* @author Rod Johnson
* @author Juergen Hoeller
@@ -60,10 +62,17 @@ public final class BeanFactoryUtilsTests {
public void setUp() {
// Interesting hierarchical factory to test counts.
// Slow to read so we cache it.
XmlBeanFactory grandParent = new XmlBeanFactory(ROOT_CONTEXT);
XmlBeanFactory parent = new XmlBeanFactory(MIDDLE_CONTEXT, grandParent);
XmlBeanFactory child = new XmlBeanFactory(LEAF_CONTEXT, parent);
this.dependentBeansBF = new XmlBeanFactory(DEPENDENT_BEANS_CONTEXT);
DefaultListableBeanFactory grandParent = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(grandParent).loadBeanDefinitions(ROOT_CONTEXT);
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(grandParent);
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(MIDDLE_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(LEAF_CONTEXT);
this.dependentBeansBF = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) this.dependentBeansBF).loadBeanDefinitions(DEPENDENT_BEANS_CONTEXT);
dependentBeansBF.preInstantiateSingletons();
this.listableBeanFactory = child;
}

View File

@@ -16,7 +16,8 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static test.util.TestResourceUtils.qualifiedResource;
import java.text.DateFormat;
@@ -34,7 +35,8 @@ import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.core.io.Resource;
@@ -70,7 +72,8 @@ public final class ConcurrentBeanFactoryTests {
@Before
public void setUp() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(CONTEXT);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(CONTEXT);
factory.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
@Override
public void registerCustomEditors(PropertyEditorRegistry registry) {

View File

@@ -549,7 +549,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("spouse", new RuntimeBeanReference("self"));
lbf.registerBeanDefinition("self", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("self", bd);
TestBean self = (TestBean) lbf.getBean("self");
assertEquals(self, self.getSpouse());
}
@@ -560,7 +562,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("ag", "foobar");
lbf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("tb", bd);
lbf.getBean("tb");
fail("Should throw exception on invalid property");
}
@@ -846,7 +850,9 @@ public class DefaultListableBeanFactoryTests {
});
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,1");
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
@@ -870,7 +876,9 @@ public class DefaultListableBeanFactoryTests {
lbf.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,1");
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
@@ -887,7 +895,9 @@ public class DefaultListableBeanFactoryTests {
});
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", new RuntimeBeanReference("myFloat"));
lbf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
lbf.registerSingleton("myFloat", "1,1");
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
@@ -990,7 +1000,8 @@ public class DefaultListableBeanFactoryTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Tony");
pvs.add("age", "48");
RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class);
bd.setPropertyValues(pvs);
bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
lbf.registerBeanDefinition("test", bd);
@@ -1039,7 +1050,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1051,7 +1063,8 @@ public class DefaultListableBeanFactoryTests {
public void testArrayPropertyWithOptionalAutowiring() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1064,7 +1077,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("integer1", new Integer(4));
bf.registerSingleton("integer2", new Integer(5));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1076,7 +1090,8 @@ public class DefaultListableBeanFactoryTests {
public void testArrayConstructorWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1091,7 +1106,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1107,7 +1123,8 @@ public class DefaultListableBeanFactoryTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(ArrayBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("arrayBean", rbd);
ArrayBean ab = (ArrayBean) bf.getBean("arrayBean");
@@ -1121,7 +1138,7 @@ public class DefaultListableBeanFactoryTests {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
Object registered = lbf.autowire(NoDependencies.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertEquals(1, lbf.getBeanDefinitionCount());
assertTrue(registered instanceof NoDependencies);
}
@@ -1131,11 +1148,12 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
// Depends on age, name and spouse (TestBean)
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertEquals(1, lbf.getBeanDefinitionCount());
DependenciesBean kerry = (DependenciesBean) registered;
TestBean rod = (TestBean) lbf.getBean("rod");
@@ -1147,10 +1165,11 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
Object registered = lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
Object registered = lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
assertEquals(1, lbf.getBeanDefinitionCount());
ConstructorDependency kerry = (ConstructorDependency) registered;
TestBean rod = (TestBean) lbf.getBean("rod");
@@ -1165,7 +1184,7 @@ public class DefaultListableBeanFactoryTests {
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("rod2", bd2);
try {
lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, false);
lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
fail("Should have thrown UnsatisfiedDependencyException");
}
catch (UnsatisfiedDependencyException ex) {
@@ -1180,11 +1199,12 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertEquals(1, lbf.getBeanDefinitionCount());
try {
lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
lbf.autowire(UnsatisfiedConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, true);
fail("Should have unsatisfied constructor dependency on SideEffectBean");
}
catch (UnsatisfiedDependencyException ex) {
@@ -1467,7 +1487,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean();
assertEquals(0, tb.getAge());
lbf.applyBeanPropertyValues(tb, "test");
@@ -1479,7 +1501,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(null, pvs));
RootBeanDefinition bd = new RootBeanDefinition();
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean();
assertEquals(0, tb.getAge());
lbf.applyBeanPropertyValues(tb, "test");
@@ -1493,7 +1517,9 @@ public class DefaultListableBeanFactoryTests {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("test", bd);
TestBean tb = new TestBean();
assertEquals(0, tb.getAge());
lbf.configureBean(tb, "test");
@@ -1509,7 +1535,9 @@ public class DefaultListableBeanFactoryTests {
lbf.registerBeanDefinition("spouse", bd);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("age", "99");
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_NAME));
RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class);
tbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_NAME);
lbf.registerBeanDefinition("test", tbd);
TestBean tb = new TestBean();
lbf.configureBean(tb, "test");
assertSame(lbf, tb.getBeanFactory());
@@ -1523,7 +1551,8 @@ public class DefaultListableBeanFactoryTests {
for (int i = 0; i < 1000; i++) {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("bean" + i, bd);
}
lbf.preInstantiateSingletons();
@@ -1537,7 +1566,9 @@ public class DefaultListableBeanFactoryTests {
@Test
public void testCircularReferenceThroughAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try {
lbf.preInstantiateSingletons();
fail("Should have thrown UnsatisfiedDependencyException");
@@ -1549,7 +1580,9 @@ public class DefaultListableBeanFactoryTests {
@Test
public void testCircularReferenceThroughFactoryBeanAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try {
lbf.preInstantiateSingletons();
fail("Should have thrown UnsatisfiedDependencyException");
@@ -1561,7 +1594,9 @@ public class DefaultListableBeanFactoryTests {
@Test
public void testCircularReferenceThroughFactoryBeanTypeCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
try {
lbf.getBeansOfType(String.class);
fail("Should have thrown UnsatisfiedDependencyException");
@@ -1573,9 +1608,12 @@ public class DefaultListableBeanFactoryTests {
@Test
public void testAvoidCircularReferenceThroughAutowiring() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
lbf.registerBeanDefinition("string",
new RootBeanDefinition(String.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyFactoryBean.class);
bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("test", bd);
RootBeanDefinition bd2 = new RootBeanDefinition(String.class);
bd2.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
lbf.registerBeanDefinition("string", bd2);
lbf.preInstantiateSingletons();
}

View File

@@ -22,9 +22,10 @@ import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
/**
@@ -37,7 +38,8 @@ public class FactoryBeanLookupTests {
@Before
public void setUp() {
beanFactory = new XmlBeanFactory(
beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader((BeanDefinitionRegistry) beanFactory).loadBeanDefinitions(
new ClassPathResource("FactoryBeanLookupTests-context.xml", this.getClass()));
}

View File

@@ -16,12 +16,15 @@
package org.springframework.beans.factory;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -38,14 +41,16 @@ public final class FactoryBeanTests {
@Test
public void testFactoryBeanReturnsNull() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(RETURNS_NULL_CONTEXT);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(RETURNS_NULL_CONTEXT);
Object result = factory.getBean("factoryBean");
assertNull(result);
}
@Test
public void testFactoryBeansWithAutowiring() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory);
@@ -62,7 +67,8 @@ public final class FactoryBeanTests {
@Test
public void testFactoryBeansWithIntermediateFactoryBeanAutowiringFailure() throws Exception {
XmlBeanFactory factory = new XmlBeanFactory(WITH_AUTOWIRING_CONTEXT);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(WITH_AUTOWIRING_CONTEXT);
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory);

View File

@@ -16,6 +16,14 @@
package org.springframework.beans.factory.annotation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.Serializable;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -25,15 +33,11 @@ import java.util.List;
import java.util.Map;
import org.junit.Test;
import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.NestedTestBean;
import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -41,7 +45,10 @@ import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.*;
import test.beans.ITestBean;
import test.beans.IndexedTestBean;
import test.beans.NestedTestBean;
import test.beans.TestBean;
/**
* Unit tests for {@link AutowiredAnnotationBeanPostProcessor}.
@@ -608,7 +615,9 @@ public final class AutowiredAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryInjectionBean.class, false));
RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ObjectFactoryInjectionBean bean = (ObjectFactoryInjectionBean) bf.getBean("annotatedBean");

View File

@@ -32,6 +32,7 @@ import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -406,7 +407,9 @@ public class InjectAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class, false));
RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierFieldInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean"));
bf.registerBeanDefinition("testBean", bd);
@@ -426,7 +429,9 @@ public class InjectAnnotationBeanPostProcessorTests {
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(bf);
bf.addBeanPostProcessor(bpp);
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class, false));
RootBeanDefinition annotatedBeanDefinition = new RootBeanDefinition(ObjectFactoryQualifierMethodInjectionBean.class);
annotatedBeanDefinition.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bf.registerBeanDefinition("annotatedBean", annotatedBeanDefinition);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.addQualifier(new AutowireCandidateQualifier(Qualifier.class, "testBean"));
bf.registerBeanDefinition("testBean", bd);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2012 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.
@@ -27,6 +27,7 @@ import org.junit.Test;
* @author Rick Evans
* @author Chris Beams
*/
@SuppressWarnings("deprecation")
public final class CommonsLogFactoryBeanTests {
@Test

View File

@@ -62,10 +62,14 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb1", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(pvs);
bf.registerBeanDefinition("tb1", bd1);
pvs = new MutablePropertyValues();
pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class));
bf.registerBeanDefinition("tb2", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(pvs);
bf.registerBeanDefinition("tb2", bd2);
TestBean tb1 = (TestBean) bf.getBean("tb1");
assertEquals(df.parse("2.12.1975"), tb1.getDate());
@@ -85,10 +89,14 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb1", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(pvs);
bf.registerBeanDefinition("tb1", bd1);
pvs = new MutablePropertyValues();
pvs.add("someMap[myKey]", new TypedStringValue("2.12.1975", Date.class));
bf.registerBeanDefinition("tb2", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(pvs);
bf.registerBeanDefinition("tb2", bd2);
TestBean tb1 = (TestBean) bf.getBean("tb1");
assertEquals(df.parse("2.12.1975"), tb1.getDate());
@@ -107,7 +115,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
@@ -125,7 +135,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("date", "2.12.1975");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
@@ -143,7 +155,9 @@ public final class CustomEditorConfigurerTests {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("stringArray", "xxx");
bf.registerBeanDefinition("tb", new RootBeanDefinition(TestBean.class, pvs));
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb");
assertTrue(tb.getStringArray() != null && tb.getStringArray().length == 1);

View File

@@ -38,6 +38,7 @@ public class DeprecatedBeanWarnerTests {
@Test
@SuppressWarnings("deprecation")
public void postProcess() {
beanFactory = new DefaultListableBeanFactory();
BeanDefinition def = new RootBeanDefinition(MyDeprecatedBean.class);

View File

@@ -16,21 +16,25 @@
package org.springframework.beans.factory.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static test.util.TestResourceUtils.qualifiedResource;
import java.util.Date;
import javax.inject.Provider;
import org.junit.After;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import org.junit.Before;
import org.junit.Test;
import static test.util.TestResourceUtils.*;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import org.springframework.util.SerializationTestUtils;
@@ -45,11 +49,12 @@ public class ObjectFactoryCreatingFactoryBeanTests {
private static final Resource CONTEXT =
qualifiedResource(ObjectFactoryCreatingFactoryBeanTests.class, "context.xml");
private XmlBeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
@Before
public void setUp() {
this.beanFactory = new XmlBeanFactory(CONTEXT);
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(CONTEXT);
this.beanFactory.setSerializationId("test");
}

View File

@@ -16,11 +16,15 @@
package org.springframework.beans.factory.config;
import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static test.util.TestResourceUtils.qualifiedResource;
import org.junit.Test;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import test.beans.ITestBean;
@@ -39,7 +43,8 @@ public class PropertyPathFactoryBeanTests {
@Test
public void testPropertyPathFactoryBeanWithSingletonResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertEquals(new Integer(12), xbf.getBean("propertyPath1"));
assertEquals(new Integer(11), xbf.getBean("propertyPath2"));
assertEquals(new Integer(10), xbf.getBean("tb.age"));
@@ -53,7 +58,8 @@ public class PropertyPathFactoryBeanTests {
@Test
public void testPropertyPathFactoryBeanWithPrototypeResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse"));
assertEquals(TestBean.class, xbf.getType("propertyPath3"));
Object result1 = xbf.getBean("tb.spouse");
@@ -72,14 +78,16 @@ public class PropertyPathFactoryBeanTests {
@Test
public void testPropertyPathFactoryBeanWithNullResult() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse.spouse"));
assertNull(xbf.getBean("tb.spouse.spouse"));
}
@Test
public void testPropertyPathFactoryBeanAsInnerBean() {
XmlBeanFactory xbf = new XmlBeanFactory(CONTEXT);
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
assertSame(spouse, tbWithInner.getSpouse());

View File

@@ -371,7 +371,8 @@ public final class PropertyResourceConfigurerTests {
pvs2.add("name", "name${var}${var}${");
pvs2.add("spouse", new RuntimeBeanReference("${ref}"));
pvs2.add("someMap", singletonMap);
RootBeanDefinition parent = new RootBeanDefinition(TestBean.class, pvs1);
RootBeanDefinition parent = new RootBeanDefinition(TestBean.class);
parent.setPropertyValues(pvs1);
ChildBeanDefinition bd = new ChildBeanDefinition("${parent}", pvs2);
factory.registerBeanDefinition("parent1", parent);
factory.registerBeanDefinition("tb1", bd);
@@ -382,7 +383,8 @@ public final class PropertyResourceConfigurerTests {
pvs.add("name", "name${var}${var}${");
pvs.add("spouse", new RuntimeBeanReference("${ref}"));
pvs.add("someMap", singletonMap);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
factory.registerBeanDefinition("tb1", bd);
}
@@ -412,7 +414,9 @@ public final class PropertyResourceConfigurerTests {
someMap.put("key2", "${age}name");
MutablePropertyValues innerPvs = new MutablePropertyValues();
innerPvs.add("touchy", "${os.name}");
someMap.put("key3", new RootBeanDefinition(TestBean.class, innerPvs));
RootBeanDefinition innerBd = new RootBeanDefinition(TestBean.class);
innerBd.setPropertyValues(innerPvs);
someMap.put("key3", innerBd);
MutablePropertyValues innerPvs2 = new MutablePropertyValues(innerPvs);
someMap.put("${key4}", new BeanDefinitionHolder(new ChildBeanDefinition("tb1", innerPvs2), "child"));
pvs.add("someMap", someMap);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2012 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.
@@ -20,6 +20,8 @@ import java.util.Arrays;
import junit.framework.TestCase;
import org.springframework.beans.factory.config.BeanDefinition;
import test.beans.TestBean;
/**
@@ -31,7 +33,8 @@ public class BeanDefinitionBuilderTests extends TestCase {
public void testBeanClassWithSimpleProperty() {
String[] dependsOn = new String[] { "A", "B", "C" };
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
bdb.setSingleton(false).addPropertyReference("age", "15");
bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bdb.addPropertyReference("age", "15");
for (int i = 0; i < dependsOn.length; i++) {
bdb.addDependsOn(dependsOn[i]);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2012 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.
@@ -18,6 +18,7 @@ package org.springframework.beans.factory.support;
import junit.framework.TestCase;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import test.beans.TestBean;
@@ -120,10 +121,11 @@ public class BeanDefinitionTests extends TestCase {
bd.getPropertyValues().add("name", "myName");
bd.getPropertyValues().add("age", "99");
ChildBeanDefinition childBd = new ChildBeanDefinition("bd");
GenericBeanDefinition childBd = new GenericBeanDefinition();
childBd.setParentName("bd");
RootBeanDefinition mergedBd = new RootBeanDefinition(bd);
mergedBd.overrideFrom(childBd);
mergedBd.overrideFrom((BeanDefinition) childBd);
assertEquals(2, mergedBd.getConstructorArgumentValues().getArgumentCount());
assertEquals(2, mergedBd.getPropertyValues().size());
assertEquals(bd, mergedBd);

View File

@@ -16,6 +16,13 @@
package org.springframework.beans.factory.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -28,24 +35,21 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.Assert.*;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.UrlResource;
import test.beans.GenericBean;
import test.beans.GenericIntegerBean;
import test.beans.GenericSetOfIntegerBean;
import test.beans.TestBean;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.UrlResource;
/**
* @author Juergen Hoeller
* @author Chris Beams
@@ -94,7 +98,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("genericBean", rbd);
GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("genericBean");
@@ -126,7 +131,8 @@ public class BeanFactoryGenericsTests {
public void testGenericListPropertyWithOptionalAutowiring() throws MalformedURLException {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@@ -152,7 +158,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericListOfArraysProperty() throws MalformedURLException {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericBean<?> gb = (GenericBean<?>) bf.getBean("listOfArrays");
assertEquals(1, gb.getListOfArrays().size());
@@ -186,7 +194,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("integer1", new Integer(4));
bf.registerSingleton("integer2", new Integer(5));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@@ -198,7 +207,8 @@ public class BeanFactoryGenericsTests {
public void testGenericSetConstructorWithOptionalAutowiring() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@@ -236,7 +246,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@@ -252,7 +263,8 @@ public class BeanFactoryGenericsTests {
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
rbd.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
bf.registerBeanDefinition("genericBean", rbd);
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
@@ -576,7 +588,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericListBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
List<?> list = (List<?>) bf.getBean("list");
assertEquals(1, list.size());
assertEquals(new URL("http://localhost:8080"), list.get(0));
@@ -584,7 +598,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericSetBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
Set<?> set = (Set<?>) bf.getBean("set");
assertEquals(1, set.size());
assertEquals(new URL("http://localhost:8080"), set.iterator().next());
@@ -592,7 +608,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericMapBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
Map<?, ?> map = (Map<?, ?>) bf.getBean("map");
assertEquals(1, map.size());
assertEquals(new Integer(10), map.keySet().iterator().next());
@@ -601,7 +619,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericallyTypedIntegerBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericIntegerBean gb = (GenericIntegerBean) bf.getBean("integerBean");
assertEquals(new Integer(10), gb.getGenericProperty());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0));
@@ -610,7 +630,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean");
assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
@@ -619,7 +641,9 @@ public class BeanFactoryGenericsTests {
@Test
public void testSetBean() throws Exception {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("genericBeanTests.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("genericBeanTests.xml", getClass()));
UrlSet us = (UrlSet) bf.getBean("setBean");
assertEquals(1, us.size());
assertEquals(new URL("http://www.springframework.org"), us.iterator().next());

View File

@@ -16,11 +16,11 @@
package org.springframework.beans.factory.support.security;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.lang.reflect.Method;
import java.net.URL;
@@ -56,7 +56,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.SecurityContextProvider;
import org.springframework.beans.factory.support.security.support.ConstructorBean;
import org.springframework.beans.factory.support.security.support.CustomCallbackBean;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.Resource;
@@ -72,7 +72,7 @@ import org.springframework.core.io.Resource;
*/
public class CallbacksSecurityTests {
private XmlBeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
private SecurityContextProvider provider;
private static class NonPrivilegedBean {
@@ -312,7 +312,8 @@ public class CallbacksSecurityTests {
DefaultResourceLoader drl = new DefaultResourceLoader();
Resource config = drl
.getResource("/org/springframework/beans/factory/support/security/callbacks.xml");
beanFactory = new XmlBeanFactory(config);
beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(config);
beanFactory.setSecurityContextProvider(provider);
}

View File

@@ -20,7 +20,6 @@ import java.beans.PropertyEditorSupport;
import java.util.StringTokenizer;
import junit.framework.TestCase;
import junit.framework.Assert;
import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyBatchUpdateException;
@@ -88,7 +87,7 @@ public abstract class AbstractBeanFactoryTests extends TestCase {
*/
public void testLifecycleCallbacks() {
LifecycleBean lb = (LifecycleBean) getBeanFactory().getBean("lifecycle");
Assert.assertEquals("lifecycle", lb.getBeanName());
assertEquals("lifecycle", lb.getBeanName());
// The dummy business method will throw an exception if the
// necessary callbacks weren't invoked in the right order.
lb.businessMethod();
@@ -365,4 +364,4 @@ class MustBeInitialized implements InitializingBean {
throw new RuntimeException("Factory didn't call afterPropertiesSet() on MustBeInitialized object");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2012 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.
@@ -20,8 +20,6 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.ListableBeanFactory;
import junit.framework.Assert;
import test.beans.TestBean;
/**
@@ -48,24 +46,24 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
protected final void assertCount(int count) {
String[] defnames = getListableBeanFactory().getBeanDefinitionNames();
Assert.assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
assertTrue("We should have " + count + " beans, not " + defnames.length, defnames.length == count);
}
public void assertTestBeanCount(int count) {
String[] defNames = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, false);
Assert.assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " +
assertTrue("We should have " + count + " beans for class org.springframework.beans.TestBean, not " +
defNames.length, defNames.length == count);
int countIncludingFactoryBeans = count + 2;
String[] names = getListableBeanFactory().getBeanNamesForType(TestBean.class, true, true);
Assert.assertTrue("We should have " + countIncludingFactoryBeans +
assertTrue("We should have " + countIncludingFactoryBeans +
" beans for class org.springframework.beans.TestBean, not " + names.length,
names.length == countIncludingFactoryBeans);
}
public void testGetDefinitionsForNoSuchClass() {
String[] defnames = getListableBeanFactory().getBeanNamesForType(String.class);
Assert.assertTrue("No string definitions", defnames.length == 0);
assertTrue("No string definitions", defnames.length == 0);
}
/**
@@ -73,18 +71,18 @@ public abstract class AbstractListableBeanFactoryTests extends AbstractBeanFacto
* what type factories may return, and it may even change over time.)
*/
public void testGetCountForFactoryClass() {
Assert.assertTrue("Should have 2 factories, not " +
assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
Assert.assertTrue("Should have 2 factories, not " +
assertTrue("Should have 2 factories, not " +
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length,
getListableBeanFactory().getBeanNamesForType(FactoryBean.class).length == 2);
}
public void testContainsBeanDefinition() {
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
Assert.assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
assertTrue(getListableBeanFactory().containsBeanDefinition("rod"));
assertTrue(getListableBeanFactory().containsBeanDefinition("roderick"));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 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,9 +16,7 @@
package org.springframework.beans.factory.xml;
import junit.framework.Assert;
import junit.framework.TestCase;
import test.beans.TestBean;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.config.RuntimeBeanReference;
@@ -26,6 +24,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/**
* @author Rob Harrop
* @author Juergen Hoeller
@@ -34,43 +34,45 @@ public class AutowireWithExclusionTests extends TestCase {
public void testByTypeAutowireWithAutoSelfExclusion() throws Exception {
CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
TestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals(sally, rob.getSpouse());
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithExclusion() throws Exception {
CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-exclusion.xml");
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithExclusionInParentFactory() throws Exception {
CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithPrimaryInParentFactory() throws Exception {
CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@@ -78,15 +80,16 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithPrimaryOverridingParentFactory() throws Exception {
CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@@ -95,16 +98,17 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithPrimaryInParentAndChild() throws Exception {
CountingFactory.reset();
XmlBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
DefaultListableBeanFactory parent = getBeanFactory("autowire-with-exclusion.xml");
parent.getBeanDefinition("props1").setPrimary(true);
parent.preInstantiateSingletons();
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class, RootBeanDefinition.AUTOWIRE_BY_TYPE);
RootBeanDefinition robDef = new RootBeanDefinition(TestBean.class);
robDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
robDef.getPropertyValues().add("spouse", new RuntimeBeanReference("sally"));
child.registerBeanDefinition("rob2", robDef);
RootBeanDefinition propsDef = new RootBeanDefinition(PropertiesFactoryBean.class);
@@ -113,29 +117,29 @@ public class AutowireWithExclusionTests extends TestCase {
child.registerBeanDefinition("props3", propsDef);
TestBean rob = (TestBean) child.getBean("rob2");
assertEquals("props3", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithInclusion() throws Exception {
CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-inclusion.xml");
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testByTypeAutowireWithSelectiveInclusion() throws Exception {
CountingFactory.reset();
XmlBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-with-selective-inclusion.xml");
beanFactory.preInstantiateSingletons();
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
Assert.assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
assertEquals(1, CountingFactory.getFactoryBeanInstanceCount());
}
public void testConstructorAutowireWithAutoSelfExclusion() throws Exception {
XmlBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
TestBean rob = (TestBean) beanFactory.getBean("rob");
TestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals(sally, rob.getSpouse());
@@ -147,13 +151,16 @@ public class AutowireWithExclusionTests extends TestCase {
}
public void testConstructorAutowireWithExclusion() throws Exception {
XmlBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
DefaultListableBeanFactory beanFactory = getBeanFactory("autowire-constructor-with-exclusion.xml");
TestBean rob = (TestBean) beanFactory.getBean("rob");
assertEquals("props1", rob.getSomeProperties().getProperty("name"));
}
private XmlBeanFactory getBeanFactory(String configPath) {
return new XmlBeanFactory(new ClassPathResource(configPath, getClass()));
private DefaultListableBeanFactory getBeanFactory(String configPath) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource(configPath, getClass()));
return bf;
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.beans.factory.xml;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -38,9 +39,9 @@ public class CollectingReaderEventListener implements ReaderEventListener {
private final List defaults = new LinkedList();
private final Map componentDefinitions = CollectionFactory.createLinkedMapIfPossible(8);
private final Map componentDefinitions = new LinkedHashMap<>(8);
private final Map aliasMap = CollectionFactory.createLinkedMapIfPossible(8);
private final Map aliasMap = new LinkedHashMap<>(8);
private final List imports = new LinkedList();
@@ -92,4 +93,4 @@ public class CollectingReaderEventListener implements ReaderEventListener {
return Collections.unmodifiableList(this.imports);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2012 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,25 +16,30 @@
package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
import org.junit.Test;
import test.beans.TestBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class CollectionsWithDefaultTypesTests {
private final XmlBeanFactory beanFactory;
private final DefaultListableBeanFactory beanFactory;
public CollectionsWithDefaultTypesTests() {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collectionsWithDefaultTypes.xml", getClass()));
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("collectionsWithDefaultTypes.xml", getClass()));
}
@Test

View File

@@ -18,6 +18,7 @@ package org.springframework.beans.factory.xml;
import junit.framework.TestCase;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
@@ -25,11 +26,13 @@ import org.springframework.core.io.ClassPathResource;
*/
public class DefaultLifecycleMethodsTests extends TestCase {
private XmlBeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
@Override
protected void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("defaultLifecycleMethods.xml", getClass()));
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(new ClassPathResource(
"defaultLifecycleMethods.xml", getClass()));
}
public void testLifecycleMethodsInvoked() {
@@ -49,7 +52,9 @@ public class DefaultLifecycleMethodsTests extends TestCase {
public void testIgnoreDefaultLifecycleMethods() throws Exception {
try {
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass()));
bf.preInstantiateSingletons();
bf.destroySingletons();
}

View File

@@ -20,6 +20,7 @@ import junit.framework.TestCase;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
/**
@@ -27,11 +28,13 @@ import org.springframework.core.io.ClassPathResource;
*/
public class MetadataAttachmentTests extends TestCase {
private XmlBeanFactory beanFactory;
private DefaultListableBeanFactory beanFactory;
@Override
protected void setUp() throws Exception {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("withMeta.xml", getClass()));
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("withMeta.xml", getClass()));
}
public void testMetadataAttachment() throws Exception {

View File

@@ -21,8 +21,8 @@ import static org.junit.Assert.assertThat;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.env.ConfigurableEnvironment;

View File

@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.beans.DummyBean;
@@ -32,7 +33,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void simpleValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "simple";
// beanFactory.getBean("simple1", DummyBean.class);
DummyBean nameValue = beanFactory.getBean(name, DummyBean.class);
@@ -41,7 +42,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void simpleRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "simple-ref";
// beanFactory.getBean("name-value1", TestBean.class);
DummyBean nameValue = beanFactory.getBean(name, DummyBean.class);
@@ -50,7 +51,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void nameValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
String name = "name-value";
// beanFactory.getBean("name-value1", TestBean.class);
TestBean nameValue = beanFactory.getBean(name, TestBean.class);
@@ -60,7 +61,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void nameRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
TestBean nameValue = beanFactory.getBean("name-value", TestBean.class);
DummyBean nameRef = beanFactory.getBean("name-ref", DummyBean.class);
@@ -70,7 +71,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void typeIndexedValue() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean typeRef = beanFactory.getBean("indexed-value", DummyBean.class);
assertEquals("at", typeRef.getName());
@@ -80,7 +81,7 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test
public void typeIndexedRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean typeRef = beanFactory.getBean("indexed-ref", DummyBean.class);
assertEquals("some-name", typeRef.getName());
@@ -89,20 +90,23 @@ public class SimpleConstructorNamespaceHandlerTests {
@Test(expected = BeanDefinitionStoreException.class)
public void ambiguousConstructor() throws Exception {
new XmlBeanFactory(new ClassPathResource("simpleConstructorNamespaceHandlerTestsWithErrors.xml", getClass()));
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource("simpleConstructorNamespaceHandlerTestsWithErrors.xml", getClass()));
}
@Test
public void constructorWithNameEndingInRef() throws Exception {
XmlBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DefaultListableBeanFactory beanFactory = createFactory("simpleConstructorNamespaceHandlerTests.xml");
DummyBean derivedBean = beanFactory.getBean("beanWithRefConstructorArg", DummyBean.class);
assertEquals(10, derivedBean.getAge());
assertEquals("silly name", derivedBean.getName());
}
private XmlBeanFactory createFactory(String resourceName) {
XmlBeanFactory fact = new XmlBeanFactory(new ClassPathResource(resourceName, getClass()));
//fact.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer());
return fact;
private DefaultListableBeanFactory createFactory(String resourceName) {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
new ClassPathResource(resourceName, getClass()));
return bf;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2012 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.
@@ -17,13 +17,15 @@
package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.beans.ITestBean;
import test.beans.TestBean;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.core.io.ClassPathResource;
/**
* @author Rob Harrop
* @author Juergen Hoeller
@@ -33,8 +35,9 @@ public class SimplePropertyNamespaceHandlerTests {
@Test
public void simpleBeanConfigured() throws Exception {
XmlBeanFactory beanFactory =
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean rob = (TestBean) beanFactory.getBean("rob");
ITestBean sally = (TestBean) beanFactory.getBean("sally");
assertEquals("Rob Harrop", rob.getName());
@@ -44,8 +47,9 @@ public class SimplePropertyNamespaceHandlerTests {
@Test
public void innerBeanConfigured() throws Exception {
XmlBeanFactory beanFactory =
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
TestBean sally = (TestBean) beanFactory.getBean("sally2");
ITestBean rob = sally.getSpouse();
assertEquals("Rob Harrop", rob.getName());
@@ -55,13 +59,16 @@ public class SimplePropertyNamespaceHandlerTests {
@Test(expected = BeanDefinitionStoreException.class)
public void withPropertyDefinedTwice() throws Exception {
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTestsWithErrors.xml", getClass()));
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTestsWithErrors.xml", getClass()));
}
@Test
public void propertyWithNameEndingInRef() throws Exception {
XmlBeanFactory beanFactory =
new XmlBeanFactory(new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
new ClassPathResource("simplePropertyNamespaceHandlerTests.xml", getClass()));
ITestBean sally = (TestBean) beanFactory.getBean("derivedSally");
assertEquals("r", sally.getSpouse().getName());
}

View File

@@ -16,7 +16,14 @@
package org.springframework.beans.factory.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -27,21 +34,19 @@ import java.util.Properties;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.IdentityHashMap;
import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArraySet;
import org.junit.Test;
import static org.junit.Assert.*;
import test.beans.TestBean;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.ListFactoryBean;
import org.springframework.beans.factory.config.MapFactoryBean;
import org.springframework.beans.factory.config.SetFactoryBean;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.io.ClassPathResource;
import test.beans.TestBean;
/**
* Tests for collections in XML bean definitions.
*
@@ -51,10 +56,12 @@ import org.springframework.core.io.ClassPathResource;
*/
public class XmlBeanCollectionTests {
private final XmlBeanFactory beanFactory;
private final DefaultListableBeanFactory beanFactory;
public XmlBeanCollectionTests() {
this.beanFactory = new XmlBeanFactory(new ClassPathResource("collections.xml", getClass()));
this.beanFactory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("collections.xml", getClass()));
}
@Test

View File

@@ -21,8 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import junit.framework.Assert;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.BeanFactory;
@@ -44,21 +42,25 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
private DefaultListableBeanFactory parent;
private XmlBeanFactory factory;
private DefaultListableBeanFactory factory;
@Override
protected void setUp() {
parent = new DefaultListableBeanFactory();
Map m = new HashMap();
m.put("name", "Albert");
parent.registerBeanDefinition("father",
new RootBeanDefinition(TestBean.class, new MutablePropertyValues(m)));
RootBeanDefinition bd1 = new RootBeanDefinition(TestBean.class);
bd1.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("father", bd1);
m = new HashMap();
m.put("name", "Roderick");
parent.registerBeanDefinition("rod",
new RootBeanDefinition(TestBean.class, new MutablePropertyValues(m)));
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPropertyValues(new MutablePropertyValues(m));
parent.registerBeanDefinition("rod", bd2);
this.factory = new XmlBeanFactory(new ClassPathResource("test.xml", getClass()), parent);
this.factory = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(this.factory).loadBeanDefinitions(
new ClassPathResource("test.xml", getClass()));
this.factory.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
@@ -106,7 +108,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
public void testDescriptionButNoProperties() throws Exception {
TestBean validEmpty = (TestBean) getBeanFactory().getBean("validEmptyWithDescription");
Assert.assertEquals(0, validEmpty.getAge());
assertEquals(0, validEmpty.getAge());
}
/**
@@ -117,94 +119,94 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
TestBean tb1 = (TestBean) getBeanFactory().getBean("aliased");
TestBean alias1 = (TestBean) getBeanFactory().getBean("myalias");
Assert.assertTrue(tb1 == alias1);
assertTrue(tb1 == alias1);
List tb1Aliases = Arrays.asList(getBeanFactory().getAliases("aliased"));
Assert.assertEquals(2, tb1Aliases.size());
Assert.assertTrue(tb1Aliases.contains("myalias"));
Assert.assertTrue(tb1Aliases.contains("youralias"));
Assert.assertTrue(beanNames.contains("aliased"));
Assert.assertFalse(beanNames.contains("myalias"));
Assert.assertFalse(beanNames.contains("youralias"));
assertEquals(2, tb1Aliases.size());
assertTrue(tb1Aliases.contains("myalias"));
assertTrue(tb1Aliases.contains("youralias"));
assertTrue(beanNames.contains("aliased"));
assertFalse(beanNames.contains("myalias"));
assertFalse(beanNames.contains("youralias"));
TestBean tb2 = (TestBean) getBeanFactory().getBean("multiAliased");
TestBean alias2 = (TestBean) getBeanFactory().getBean("alias1");
TestBean alias3 = (TestBean) getBeanFactory().getBean("alias2");
TestBean alias3a = (TestBean) getBeanFactory().getBean("alias3");
TestBean alias3b = (TestBean) getBeanFactory().getBean("alias4");
Assert.assertTrue(tb2 == alias2);
Assert.assertTrue(tb2 == alias3);
Assert.assertTrue(tb2 == alias3a);
Assert.assertTrue(tb2 == alias3b);
assertTrue(tb2 == alias2);
assertTrue(tb2 == alias3);
assertTrue(tb2 == alias3a);
assertTrue(tb2 == alias3b);
List tb2Aliases = Arrays.asList(getBeanFactory().getAliases("multiAliased"));
Assert.assertEquals(4, tb2Aliases.size());
Assert.assertTrue(tb2Aliases.contains("alias1"));
Assert.assertTrue(tb2Aliases.contains("alias2"));
Assert.assertTrue(tb2Aliases.contains("alias3"));
Assert.assertTrue(tb2Aliases.contains("alias4"));
Assert.assertTrue(beanNames.contains("multiAliased"));
Assert.assertFalse(beanNames.contains("alias1"));
Assert.assertFalse(beanNames.contains("alias2"));
Assert.assertFalse(beanNames.contains("alias3"));
Assert.assertFalse(beanNames.contains("alias4"));
assertEquals(4, tb2Aliases.size());
assertTrue(tb2Aliases.contains("alias1"));
assertTrue(tb2Aliases.contains("alias2"));
assertTrue(tb2Aliases.contains("alias3"));
assertTrue(tb2Aliases.contains("alias4"));
assertTrue(beanNames.contains("multiAliased"));
assertFalse(beanNames.contains("alias1"));
assertFalse(beanNames.contains("alias2"));
assertFalse(beanNames.contains("alias3"));
assertFalse(beanNames.contains("alias4"));
TestBean tb3 = (TestBean) getBeanFactory().getBean("aliasWithoutId1");
TestBean alias4 = (TestBean) getBeanFactory().getBean("aliasWithoutId2");
TestBean alias5 = (TestBean) getBeanFactory().getBean("aliasWithoutId3");
Assert.assertTrue(tb3 == alias4);
Assert.assertTrue(tb3 == alias5);
assertTrue(tb3 == alias4);
assertTrue(tb3 == alias5);
List tb3Aliases = Arrays.asList(getBeanFactory().getAliases("aliasWithoutId1"));
Assert.assertEquals(2, tb3Aliases.size());
Assert.assertTrue(tb3Aliases.contains("aliasWithoutId2"));
Assert.assertTrue(tb3Aliases.contains("aliasWithoutId3"));
Assert.assertTrue(beanNames.contains("aliasWithoutId1"));
Assert.assertFalse(beanNames.contains("aliasWithoutId2"));
Assert.assertFalse(beanNames.contains("aliasWithoutId3"));
assertEquals(2, tb3Aliases.size());
assertTrue(tb3Aliases.contains("aliasWithoutId2"));
assertTrue(tb3Aliases.contains("aliasWithoutId3"));
assertTrue(beanNames.contains("aliasWithoutId1"));
assertFalse(beanNames.contains("aliasWithoutId2"));
assertFalse(beanNames.contains("aliasWithoutId3"));
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
Assert.assertEquals(null, tb4.getName());
assertEquals(null, tb4.getName());
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
Assert.assertEquals(5, drs.size());
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#0"));
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#1"));
Assert.assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
assertEquals(5, drs.size());
assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#0"));
assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#1"));
assertTrue(drs.containsKey(DummyReferencer.class.getName() + "#2"));
}
public void testFactoryNesting() {
ITestBean father = (ITestBean) getBeanFactory().getBean("father");
Assert.assertTrue("Bean from root context", father != null);
assertTrue("Bean from root context", father != null);
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
Assert.assertTrue("Bean from child context", "Rod".equals(rod.getName()));
Assert.assertTrue("Bean has external reference", rod.getSpouse() == father);
assertTrue("Bean from child context", "Rod".equals(rod.getName()));
assertTrue("Bean has external reference", rod.getSpouse() == father);
rod = (TestBean) parent.getBean("rod");
Assert.assertTrue("Bean from root context", "Roderick".equals(rod.getName()));
assertTrue("Bean from root context", "Roderick".equals(rod.getName()));
}
public void testFactoryReferences() {
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
DummyReferencer ref = (DummyReferencer) getBeanFactory().getBean("factoryReferencer");
Assert.assertTrue(ref.getTestBean1() == ref.getTestBean2());
Assert.assertTrue(ref.getDummyFactory() == factory);
assertTrue(ref.getTestBean1() == ref.getTestBean2());
assertTrue(ref.getDummyFactory() == factory);
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("factoryReferencerWithConstructor");
Assert.assertTrue(ref2.getTestBean1() == ref2.getTestBean2());
Assert.assertTrue(ref2.getDummyFactory() == factory);
assertTrue(ref2.getTestBean1() == ref2.getTestBean2());
assertTrue(ref2.getDummyFactory() == factory);
}
public void testPrototypeReferences() {
// check that not broken by circular reference resolution mechanism
DummyReferencer ref1 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2());
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref1.getTestBean2());
DummyReferencer ref2 = (DummyReferencer) getBeanFactory().getBean("prototypeReferencer");
Assert.assertTrue("Not the same referencer", ref1 != ref2);
Assert.assertTrue("Not referencing same bean twice", ref2.getTestBean1() != ref2.getTestBean2());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean1());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean2() != ref2.getTestBean2());
Assert.assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2());
assertTrue("Not the same referencer", ref1 != ref2);
assertTrue("Not referencing same bean twice", ref2.getTestBean1() != ref2.getTestBean2());
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean1());
assertTrue("Not referencing same bean twice", ref1.getTestBean2() != ref2.getTestBean2());
assertTrue("Not referencing same bean twice", ref1.getTestBean1() != ref2.getTestBean2());
}
public void testBeanPostProcessor() throws Exception {
@@ -212,22 +214,22 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
TestBean kathy = (TestBean) getBeanFactory().getBean("kathy");
DummyFactory factory = (DummyFactory) getBeanFactory().getBean("&singletonFactory");
TestBean factoryCreated = (TestBean) getBeanFactory().getBean("singletonFactory");
Assert.assertTrue(kerry.isPostProcessed());
Assert.assertTrue(kathy.isPostProcessed());
Assert.assertTrue(factory.isPostProcessed());
Assert.assertTrue(factoryCreated.isPostProcessed());
assertTrue(kerry.isPostProcessed());
assertTrue(kathy.isPostProcessed());
assertTrue(factory.isPostProcessed());
assertTrue(factoryCreated.isPostProcessed());
}
public void testEmptyValues() {
TestBean rod = (TestBean) getBeanFactory().getBean("rod");
TestBean kerry = (TestBean) getBeanFactory().getBean("kerry");
Assert.assertTrue("Touchy is empty", "".equals(rod.getTouchy()));
Assert.assertTrue("Touchy is empty", "".equals(kerry.getTouchy()));
assertTrue("Touchy is empty", "".equals(rod.getTouchy()));
assertTrue("Touchy is empty", "".equals(kerry.getTouchy()));
}
public void testCommentsAndCdataInValue() {
TestBean bean = (TestBean) getBeanFactory().getBean("commentsInValue");
Assert.assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName());
assertEquals("Failed to handle comments and CDATA properly", "this is a <!--comment-->", bean.getName());
}
}