1 16 17 package org.springframework.aop.target; 18 19 import junit.framework.TestCase; 20 21 import org.springframework.aop.interceptor.SideEffectBean; 22 import org.springframework.beans.factory.BeanFactory; 23 import org.springframework.beans.factory.xml.XmlBeanFactory; 24 import org.springframework.core.io.ClassPathResource; 25 26 29 public class PrototypeTargetSourceTests extends TestCase { 30 31 32 private static final int INITIAL_COUNT = 10; 33 34 private BeanFactory beanFactory; 35 36 protected void setUp() throws Exception { 37 this.beanFactory = new XmlBeanFactory(new ClassPathResource("prototypeTests.xml", getClass())); 38 } 39 40 45 public void testPrototypeAndSingletonBehaveDifferently() { 46 SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton"); 47 assertEquals(INITIAL_COUNT, singleton.getCount() ); 48 singleton.doWork(); 49 assertEquals(INITIAL_COUNT + 1, singleton.getCount() ); 50 51 SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype"); 52 assertEquals(INITIAL_COUNT, prototype.getCount() ); 53 prototype.doWork(); 54 assertEquals(INITIAL_COUNT, prototype.getCount() ); 55 } 56 57 58 } 59 | Popular Tags |