use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class CountingAspectJAdvice method testIsProxy.
@Test
public void testIsProxy() throws Exception {
ITestBean bean = getTestBean();
assertThat(AopUtils.isAopProxy(bean)).as("Bean is not a proxy").isTrue();
// check the advice details
Advised advised = (Advised) bean;
Advisor[] advisors = advised.getAdvisors();
assertThat(advisors.length > 0).as("Advisors should not be empty").isTrue();
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class CountingAspectJAdvice method testAspectAppliedForInitializeBeanWithEmptyName.
@Test
public void testAspectAppliedForInitializeBeanWithEmptyName() {
ITestBean bean = (ITestBean) this.context.getAutowireCapableBeanFactory().initializeBean(new TestBean(), "");
CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice");
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(0);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(0);
bean.setName("Sally");
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
bean.getName();
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class JdkDynamicProxyTests method testInterceptorIsInvokedWithNoTarget.
@Test
public void testInterceptorIsInvokedWithNoTarget() {
// Test return value
final int age = 25;
MethodInterceptor mi = (invocation -> age);
AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
pc.addAdvice(mi);
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertThat(tb.getAge()).as("correct return value").isEqualTo(age);
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class JdkDynamicProxyTests method testTargetCanGetInvocationWithPrivateClass.
@Test
public void testTargetCanGetInvocationWithPrivateClass() {
final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() {
@Override
protected void assertions(MethodInvocation invocation) {
assertThat(invocation.getThis()).isEqualTo(this);
assertThat(invocation.getMethod().getDeclaringClass()).as("Invocation should be on ITestBean: " + invocation.getMethod()).isEqualTo(ITestBean.class);
}
};
AdvisedSupport pc = new AdvisedSupport(ITestBean.class, IOther.class);
pc.addAdvice(ExposeInvocationInterceptor.INSTANCE);
TrapTargetInterceptor tii = new TrapTargetInterceptor() {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
// Assert that target matches BEFORE invocation returns
assertThat(invocation.getThis()).as("Target is correct").isEqualTo(expectedTarget);
return super.invoke(invocation);
}
};
pc.addAdvice(tii);
pc.setTarget(expectedTarget);
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
tb.getName();
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeInstancesAreNotEqual.
@Test
public void testPrototypeInstancesAreNotEqual() {
assertThat(ITestBean.class.isAssignableFrom(factory.getType("prototype"))).as("Has correct object type").isTrue();
ITestBean test2 = (ITestBean) factory.getBean("prototype");
ITestBean test2_1 = (ITestBean) factory.getBean("prototype");
assertThat(test2 != test2_1).as("Prototype instances !=").isTrue();
assertThat(test2.equals(test2_1)).as("Prototype instances equal").isTrue();
assertThat(ITestBean.class.isAssignableFrom(factory.getType("prototype"))).as("Has correct object type").isTrue();
}
Aggregations