use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class MethodInvocationTests method testToStringDoesntHitTarget.
/**
* toString on target can cause failure.
*/
@Test
public void testToStringDoesntHitTarget() throws Throwable {
Object target = new TestBean() {
@Override
public String toString() {
throw new UnsupportedOperationException("toString");
}
};
List<Object> is = new LinkedList<>();
Method m = Object.class.getMethod("hashCode");
Object proxy = new Object();
ReflectiveMethodInvocation invocation = new ReflectiveMethodInvocation(proxy, target, m, null, null, is);
// If it hits target, the test will fail with the UnsupportedOpException
// in the inner class above.
invocation.toString();
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PerThisAspect method testMultiplePerTargetAspectsWithOrderAnnotation.
@Test
public void testMultiplePerTargetAspectsWithOrderAnnotation() throws SecurityException, NoSuchMethodException {
TestBean target = new TestBean();
int realAge = 65;
target.setAge(realAge);
List<Advisor> advisors = new LinkedList<>();
PerTargetAspectWithOrderAnnotation10 aspect1 = new PerTargetAspectWithOrderAnnotation10();
aspect1.count = 100;
advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect1, "someBean1")));
PerTargetAspectWithOrderAnnotation5 aspect2 = new PerTargetAspectWithOrderAnnotation5();
advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect2, "someBean2")));
Collections.sort(advisors, new OrderComparator());
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PerThisAspect method testNamedPointcutFromAspectLibraryWithBinding.
@Test
public void testNamedPointcutFromAspectLibraryWithBinding() {
TestBean target = new TestBean();
ITestBean itb = (ITestBean) createProxy(target, getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new NamedPointcutAspectFromLibraryWithBinding(), "someBean")), ITestBean.class);
itb.setAge(10);
assertEquals("Around advice must apply", 20, itb.getAge());
assertEquals(20, target.getAge());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class NamedPointcutWithArgs method testBindingInPointcutUsedByAdvice.
@Test(expected = IllegalArgumentException.class)
public void testBindingInPointcutUsedByAdvice() {
TestBean tb = new TestBean();
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
proxyFactory.addAspect(NamedPointcutWithArgs.class);
ITestBean proxiedTestBean = proxyFactory.getProxy();
proxiedTestBean.setName("Supercalifragalisticexpialidocious");
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testBeanPostProcessorWithWrappedObjectAndDisposableBean.
@Test
public void testBeanPostProcessorWithWrappedObjectAndDisposableBean() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDisposableBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return new TestBean();
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
return bean;
}
});
BeanWithDisposableBean.closed = false;
lbf.preInstantiateSingletons();
lbf.destroySingletons();
assertTrue("Destroy method invoked", BeanWithDisposableBean.closed);
}
Aggregations