Browse Source

Made AutoProxyCreatorTests less dependent on container's own interrogation of FactoryBeans

Issue: SPR-9857
3.1.x
Juergen Hoeller 14 years ago
parent
commit
c90e2c6f10
  1. 13
      org.springframework.context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

13
org.springframework.context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java

@ -20,7 +20,6 @@ import java.lang.reflect.Proxy;
import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation; import org.aopalliance.intercept.MethodInvocation;
import static org.junit.Assert.*;
import org.junit.Test; import org.junit.Test;
import org.springframework.aop.TargetSource; import org.springframework.aop.TargetSource;
@ -37,6 +36,8 @@ import org.springframework.context.MessageSource;
import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticApplicationContext;
import org.springframework.context.support.StaticMessageSource; import org.springframework.context.support.StaticMessageSource;
import static org.junit.Assert.*;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Chris Beams * @author Chris Beams
@ -113,20 +114,18 @@ public final class AutoProxyCreatorTests {
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied"); ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass())); assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
// 4 invocations coming from FactoryBean inspection during lifecycle startup
TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor"); TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
assertEquals(4, ti.nrOfInvocations); int initialNr = ti.nrOfInvocations;
singletonToBeProxied.getName(); singletonToBeProxied.getName();
assertEquals(5, ti.nrOfInvocations); assertEquals(initialNr + 1, ti.nrOfInvocations);
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied"); FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(Proxy.isProxyClass(factory.getClass())); assertTrue(Proxy.isProxyClass(factory.getClass()));
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied"); TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(tb)); assertFalse(AopUtils.isAopProxy(tb));
assertEquals(7, ti.nrOfInvocations); assertEquals(initialNr + 3, ti.nrOfInvocations);
tb.getAge(); tb.getAge();
assertEquals(7, ti.nrOfInvocations); assertEquals(initialNr + 3, ti.nrOfInvocations);
} }
@Test @Test

Loading…
Cancel
Save