diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java similarity index 98% rename from org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java index 6698d787bf0552f74928c933b5b2de074551541b..18bdc08026c32da4eaec61372e60312ec3710207 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java @@ -16,6 +16,8 @@ package org.springframework.beans.factory.annotation; +import static org.junit.Assert.*; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -23,8 +25,7 @@ import java.lang.annotation.Target; import java.util.List; import java.util.Map; -import junit.framework.TestCase; - +import org.junit.Test; import org.springframework.beans.ITestBean; import org.springframework.beans.IndexedTestBean; import org.springframework.beans.NestedTestBean; @@ -41,9 +42,11 @@ import org.springframework.beans.factory.support.RootBeanDefinition; * @author Juergen Hoeller * @author Mark Fisher * @author Sam Brannen + * @author Chris Beams */ -public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { +public class AutowiredAnnotationBeanPostProcessorTests { + @Test public void testIncompleteBeanDefinition() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -58,6 +61,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { } } + @Test public void testResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -78,6 +82,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertSame(tb, bean.getTestBean2()); } + @Test public void testExtendedResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); @@ -109,6 +114,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertSame(bf, bean.getBeanFactory()); } + @Test public void testExtendedResourceInjectionWithOverriding() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); @@ -134,6 +140,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testExtendedResourceInjectionWithAtRequired() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); @@ -158,6 +165,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertSame(bf, bean.getBeanFactory()); } + @Test public void testOptionalResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -188,6 +196,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testOptionalCollectionResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -225,6 +234,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testOptionalCollectionResourceInjectionWithSingleElement() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -257,6 +267,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testOptionalResourceInjectionWithIncompleteDependencies() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -275,6 +286,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testOptionalResourceInjectionWithNoDependencies() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -291,6 +303,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testConstructorResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerResolvableDependency(BeanFactory.class, bf); @@ -322,6 +335,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertSame(bf, bean.getBeanFactory()); } + @Test public void testConstructorResourceInjectionWithMultipleCandidates() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -344,6 +358,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -367,6 +382,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testConstructorResourceInjectionWithMultipleCandidatesAndFallback() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -382,6 +398,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testConstructorResourceInjectionWithMultipleCandidatesAndDefaultFallback() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -395,6 +412,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testConstructorInjectionWithMap() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -423,6 +441,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.getTestBeanMap().values().contains(tb2)); } + @Test public void testFieldInjectionWithMap() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -451,6 +470,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertTrue(bean.getTestBeanMap().values().contains(tb2)); } + @Test public void testMethodInjectionWithMap() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -475,6 +495,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { assertSame(tb, bean.getTestBean()); } + @Test public void testMethodInjectionWithMapAndMultipleMatches() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -485,7 +506,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class)); try { - MapMethodInjectionBean bean = (MapMethodInjectionBean) bf.getBean("annotatedBean"); + bf.getBean("annotatedBean"); fail("should have failed, more than one bean of type"); } catch (BeanCreationException e) { @@ -494,6 +515,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -514,6 +536,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testMethodInjectionWithMapAndNoMatches() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -527,6 +550,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredFieldResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -545,6 +569,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenNoDependencyFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -566,6 +591,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -591,6 +617,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredMethodResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -609,6 +636,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredMethodResourceInjectionFailsWhenNoDependencyFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -630,6 +658,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationRequiredMethodResourceInjectionFailsWhenMultipleDependenciesFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -655,6 +684,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalFieldResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -675,6 +705,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalFieldResourceInjectionWhenNoDependencyFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -693,6 +724,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -718,6 +750,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalMethodResourceInjection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -738,6 +771,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalMethodResourceInjectionWhenNoDependencyFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -756,6 +790,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { bf.destroySingletons(); } + @Test public void testCustomAnnotationOptionalMethodResourceInjectionWhenMultipleDependenciesFound() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -788,6 +823,7 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { * href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040" * target="_blank">SPR-4040. */ + @Test public void testBeanAutowiredWithFactoryBean() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); @@ -1246,21 +1282,21 @@ public class AutowiredAnnotationBeanPostProcessorTests extends TestCase { private static class FactoryBeanDependentBean { @Autowired - private FactoryBean factoryBean; + private FactoryBean factoryBean; - public final FactoryBean getFactoryBean() { + public final FactoryBean getFactoryBean() { return this.factoryBean; } } - public static class StringFactoryBean implements FactoryBean { + public static class StringFactoryBean implements FactoryBean { - public Object getObject() throws Exception { + public String getObject() throws Exception { return ""; } - public Class getObjectType() { + public Class getObjectType() { return String.class; } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java similarity index 94% rename from org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java index f752db1a84217f5e87702343e30a39d56d6a49f8..51f71e2a5c3a0b48a07b6ccf8e60d492ed0b0cd2 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java +++ b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurerTests.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.annotation; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import org.junit.Test; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.AutowireCandidateResolver; @@ -28,13 +29,15 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; /** * @author Mark Fisher * @author Juergen Hoeller + * @author Chris Beams */ -public class CustomAutowireConfigurerTests extends TestCase { +public class CustomAutowireConfigurerTests { private static final String CONFIG_LOCATION = "classpath:org/springframework/beans/factory/annotation/customAutowireConfigurer.xml"; + @Test public void testCustomResolver() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/customAutowireConfigurer.xml b/org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/customAutowireConfigurer.xml similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/customAutowireConfigurer.xml rename to org.springframework.beans/src/test/java/org/springframework/beans/factory/annotation/customAutowireConfigurer.xml diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/HasMap.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/HasMap.java new file mode 100644 index 0000000000000000000000000000000000000000..3bac49498b5b78cad8244307b017b6f6bf3131ba --- /dev/null +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/HasMap.java @@ -0,0 +1,94 @@ +/* + * Copyright 2002-2005 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans.factory; + +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +/** + * Bean exposing a map. Used for bean factory tests. + * + * @author Rod Johnson + * @since 05.06.2003 + */ +public class HasMap { + + private Map map; + + private Set set; + + private Properties props; + + private Object[] objectArray; + + private Class[] classArray; + + private Integer[] intArray; + + private HasMap() { + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public Set getSet() { + return set; + } + + public void setSet(Set set) { + this.set = set; + } + + public Properties getProps() { + return props; + } + + public void setProps(Properties props) { + this.props = props; + } + + public Object[] getObjectArray() { + return objectArray; + } + + public void setObjectArray(Object[] objectArray) { + this.objectArray = objectArray; + } + + public Class[] getClassArray() { + return classArray; + } + + public void setClassArray(Class[] classArray) { + this.classArray = classArray; + } + + public Integer[] getIntegerArray() { + return intArray; + } + + public void setIntegerArray(Integer[] is) { + intArray = is; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessorTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessorTests.java index 0dddcb3e9770b290b20fb49c66e546a411e7cd52..cdc2db943a1b3d2772d7e1fdd4cbd9addf7505b1 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessorTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessorTests.java @@ -24,6 +24,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; /** * @author Rob Harrop + * @author Chris Beams * @since 2.0 */ public class RequiredAnnotationBeanPostProcessorTests extends TestCase { diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java index 92cc460f4824fc8c16e2800005d2ad836015af10..bec6f75e35b06c121309b9f2ad00b93770b8fbdd 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java @@ -16,10 +16,7 @@ package org.springframework.beans.factory.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.FileNotFoundException; import java.util.List; @@ -37,7 +34,6 @@ import org.springframework.beans.TestBean; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.support.ChildBeanDefinition; -import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedSet; diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java index f093bffe9fe114d9195e8bb863b3767939ff5953..ac4210f02a7d43d2bb815b9c032b0898ced97265 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBeanTests.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.config; -import junit.framework.TestCase; -import org.easymock.MockControl; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.*; +import org.junit.Test; import org.springframework.beans.FatalBeanException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; @@ -32,9 +33,11 @@ import org.springframework.test.AssertThrows; /** * @author Colin Sampaleanu * @author Rick Evans + * @author Chris Beams */ -public class ServiceLocatorFactoryBeanTests extends TestCase { +public class ServiceLocatorFactoryBeanTests { + @Test public void testNoArgGetter() { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues()); @@ -48,6 +51,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { assertNotNull(testService); } + @Test public void testErrorOnTooManyOrTooFew() throws Exception { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues()); @@ -84,6 +88,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testErrorOnTooManyOrTooFewWithCustomServiceLocatorException() { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues()); @@ -126,6 +131,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testStringArgGetter() throws Exception { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerSingleton("testService", TestService.class, new MutablePropertyValues()); @@ -136,6 +142,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { // test string-arg getter with null id final TestServiceLocator2 factory = (TestServiceLocator2) ctx.getBean("factory"); + @SuppressWarnings("unused") TestService testBean = factory.getTestService(null); // now test with explicit id testBean = factory.getTestService("testService"); @@ -147,6 +154,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testCombinedLocatorInterface() { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerPrototype("testService", TestService.class, new MutablePropertyValues()); @@ -171,6 +179,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { assertTrue(factory.toString().indexOf("TestServiceLocator3") != -1); } + @Test public void testServiceMappings() { StaticApplicationContext ctx = new StaticApplicationContext(); ctx.registerPrototype("testService1", TestService.class, new MutablePropertyValues()); @@ -198,6 +207,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { assertTrue(testBean4 instanceof ExtendedTestService); } + @Test public void testNoServiceLocatorInterfaceSupplied() throws Exception { new AssertThrows(IllegalArgumentException.class, "No serviceLocator interface supplied") { public void test() throws Exception { @@ -206,6 +216,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testWhenServiceLocatorInterfaceIsNotAnInterfaceType() throws Exception { new AssertThrows(IllegalArgumentException.class, "Bad (non-interface-type) serviceLocator interface supplied") { public void test() throws Exception { @@ -216,6 +227,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testWhenServiceLocatorExceptionClassToExceptionTypeWithOnlyNoArgCtor() throws Exception { new AssertThrows(IllegalArgumentException.class, "Bad (invalid-Exception-type) serviceLocatorException class supplied") { public void test() throws Exception { @@ -225,6 +237,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testWhenServiceLocatorExceptionClassIsNotAnExceptionSubclass() throws Exception { new AssertThrows(IllegalArgumentException.class, "Bad (non-Exception-type) serviceLocatorException class supplied") { public void test() throws Exception { @@ -234,6 +247,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testWhenServiceLocatorMethodCalledWithTooManyParameters() throws Exception { ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); factory.setServiceLocatorInterface(ServiceLocatorInterfaceWithExtraNonCompliantMethod.class); @@ -246,19 +260,19 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { }.runTest(); } + @Test public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception { - MockControl mockBeanFactory = MockControl.createControl(BeanFactory.class); - final BeanFactory beanFactory = (BeanFactory) mockBeanFactory.getMock(); - mockBeanFactory.replay(); + final BeanFactory beanFactory = createMock(BeanFactory.class); + replay(beanFactory); - new AssertThrows(FatalBeanException.class) { - public void test() throws Exception { - ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); - factory.setBeanFactory(beanFactory); - } - }.runTest(); + try { + ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean(); + factory.setBeanFactory(beanFactory); + } catch (FatalBeanException ex) { + // expected + } - mockBeanFactory.verify(); + verify(beanFactory); } @@ -315,6 +329,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { } + @SuppressWarnings("serial") public static class CustomServiceLocatorException1 extends NestedRuntimeException { public CustomServiceLocatorException1(String message, Throwable cause) { @@ -323,6 +338,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { } + @SuppressWarnings("serial") public static class CustomServiceLocatorException2 extends NestedCheckedException { public CustomServiceLocatorException2(Throwable cause) { @@ -331,6 +347,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { } + @SuppressWarnings("serial") public static class CustomServiceLocatorException3 extends NestedCheckedException { public CustomServiceLocatorException3(String message) { @@ -339,6 +356,7 @@ public class ServiceLocatorFactoryBeanTests extends TestCase { } + @SuppressWarnings("serial") public static class ExceptionClassWithOnlyZeroArgCtor extends Exception { } diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/LookupMethodWrappedByCglibProxyTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/LookupMethodWrappedByCglibProxyTests.java index 0a3c782d92e7408154a2948682fb135b08926fa5..65f83309278e00bd6c8b452a0a50e486755226c7 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/LookupMethodWrappedByCglibProxyTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/LookupMethodWrappedByCglibProxyTests.java @@ -16,8 +16,10 @@ package org.springframework.beans.factory.xml; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; import org.springframework.aop.interceptor.DebugInterceptor; import org.springframework.beans.ITestBean; import org.springframework.context.ApplicationContext; @@ -28,16 +30,19 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * * @author Rod Johnson * @author Juergen Hoeller + * @author Chris Beams */ -public class LookupMethodWrappedByCglibProxyTests extends TestCase { +public class LookupMethodWrappedByCglibProxyTests { private ApplicationContext applicationContext; - protected void setUp() { + @Before + public void setUp() { this.applicationContext = new ClassPathXmlApplicationContext("overloadOverrides.xml", getClass()); resetInterceptor(); } + @Test public void testAutoProxiedLookup() { OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload"); ITestBean jenny = olup.newTestBean(); @@ -46,6 +51,7 @@ public class LookupMethodWrappedByCglibProxyTests extends TestCase { assertInterceptorCount(2); } + @Test public void testRegularlyProxiedLookup() { OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload"); ITestBean jenny = olup.newTestBean(); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java new file mode 100644 index 0000000000000000000000000000000000000000..1d059ea569d8f103df55cc0e91a8d896861d134e --- /dev/null +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MapAndSet.java @@ -0,0 +1,39 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.beans.factory.xml; + +import java.util.Map; +import java.util.Set; + +/** + * @author Chris Beams + */ +public class MapAndSet { + + private Object obj; + + public MapAndSet(Map map) { + this.obj = map; + } + + public MapAndSet(Set set) { + this.obj = set; + } + + public Object getObject() { + return obj; + } +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java new file mode 100644 index 0000000000000000000000000000000000000000..8ed5f2517ec8919274cb4de193342bf35657abc9 --- /dev/null +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/MixedCollectionBean.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.beans.factory.xml; + +import java.util.Collection; + +/** + * Bean that exposes a simple property that can be set + * to a mix of references and individual values. + * + * @author Rod Johnson + * @since 27.05.2003 + */ +public class MixedCollectionBean { + + private Collection jumble; + + + public void setJumble(Collection jumble) { + this.jumble = jumble; + } + + public Collection getJumble() { + return jumble; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java index a25e932f3dedf62bc3ba2e5c846e66285b36034d..37fbba6c269f88020deaa64f128ab050a7b02142 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/QualifierAnnotationTests.java @@ -16,13 +16,14 @@ package org.springframework.beans.factory.xml; +import static org.junit.Assert.*; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import junit.framework.TestCase; - +import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -33,13 +34,15 @@ import org.springframework.context.support.StaticApplicationContext; /** * @author Mark Fisher * @author Juergen Hoeller + * @author Chris Beams */ -public class QualifierAnnotationTests extends TestCase { +public class QualifierAnnotationTests { private static final String CONFIG_LOCATION = "classpath:org/springframework/beans/factory/xml/qualifierAnnotationTests.xml"; + @Test public void testNonQualifiedFieldFails() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -54,6 +57,7 @@ public class QualifierAnnotationTests extends TestCase { } } + @Test public void testQualifiedByValue() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -65,6 +69,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("Larry", person.getName()); } + @Test public void testQualifiedByBeanName() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -76,6 +81,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("LarryBean", person.getName()); } + @Test public void testQualifiedByAlias() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -87,6 +93,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("LarryBean", person.getName()); } + @Test public void testQualifiedByAnnotation() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -98,6 +105,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("LarrySpecial", person.getName()); } + @Test public void testQualifiedByCustomValue() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -109,6 +117,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("Curly", person.getName()); } + @Test public void testQualifiedByAnnotationValue() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -120,6 +129,7 @@ public class QualifierAnnotationTests extends TestCase { assertEquals("LarrySpecial", person.getName()); } + @Test public void testQualifiedByAttributesFailsWithoutCustomQualifierRegistered() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); @@ -134,6 +144,7 @@ public class QualifierAnnotationTests extends TestCase { } } + @Test public void testQualifiedByAttributesWithCustomQualifierRegistered() { StaticApplicationContext context = new StaticApplicationContext(); BeanDefinitionReader reader = new XmlBeanDefinitionReader(context); diff --git a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/collections.xml b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/collections.xml index eafd9ff15d7858ff427abb7b2a6ca60fd739b7b8..9a735571d89b55968486f94163b51ec0345734fc 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/collections.xml +++ b/org.springframework.testsuite/src/test/java/org/springframework/beans/factory/xml/collections.xml @@ -352,7 +352,7 @@ - + My Map