1 16 17 package org.springframework.beans.factory.config; 18 19 import java.util.Date ; 20 21 import junit.framework.TestCase; 22 23 import org.springframework.beans.BeansException; 24 import org.springframework.beans.factory.BeanFactory; 25 import org.springframework.beans.factory.ObjectFactory; 26 import org.springframework.beans.factory.xml.XmlBeanFactory; 27 import org.springframework.core.io.ClassPathResource; 28 29 35 public class ObjectFactoryCreatingFactoryBeanTests extends TestCase { 36 37 private BeanFactory beanFactory; 38 39 protected void setUp() throws Exception { 40 this.beanFactory = new XmlBeanFactory(new ClassPathResource( 41 "ObjectFactoryCreatingFactoryBeanTests.xml", getClass())); 42 } 43 44 public void testBasicOperation() throws BeansException { 45 TestBean testBean = (TestBean) beanFactory.getBean("testBean"); 46 ObjectFactory objectFactory = testBean.getObjectFactory(); 47 48 Date date1 = (Date ) objectFactory.getObject(); 49 Date date2 = (Date ) objectFactory.getObject(); 50 assertTrue(date1 != date2); 51 } 52 53 public static class TestBean { 54 public ObjectFactory objectFactory; 55 56 public ObjectFactory getObjectFactory() { 57 return objectFactory; 58 } 59 60 public void setObjectFactory(ObjectFactory objectFactory) { 61 this.objectFactory = objectFactory; 62 } 63 } 64 } 65 | Popular Tags |