KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > config > ObjectFactoryCreatingFactoryBeanTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.beans.factory.config;
18
19 import java.util.Date JavaDoc;
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 /**
30  * Tests for ObjectFactoryCreatingFactoryBean.
31  *
32  * @author Colin Sampaleanu
33  * @since 2004-05-11
34  */

35 public class ObjectFactoryCreatingFactoryBeanTests extends TestCase {
36
37     private BeanFactory beanFactory;
38
39     protected void setUp() throws Exception JavaDoc {
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 JavaDoc date1 = (Date JavaDoc) objectFactory.getObject();
49         Date JavaDoc date2 = (Date JavaDoc) 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