|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
65 | 65 | import static org.assertj.core.api.Assertions.assertThatIOException;
|
66 | 66 |
|
67 | 67 | /**
|
68 |
| - * @since 13.03.2003 |
69 | 68 | * @author Rod Johnson
|
70 | 69 | * @author Juergen Hoeller
|
71 | 70 | * @author Chris Beams
|
| 71 | + * @since 13.03.2003 |
72 | 72 | */
|
73 | 73 | public class ProxyFactoryBeanTests {
|
74 | 74 |
|
@@ -633,20 +633,50 @@ public void testFrozenFactoryBean() {
|
633 | 633 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
634 | 634 | new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
|
635 | 635 |
|
636 |
| - Advised advised = (Advised)bf.getBean("frozen"); |
| 636 | + Advised advised = (Advised) bf.getBean("frozen"); |
637 | 637 | assertThat(advised.isFrozen()).as("The proxy should be frozen").isTrue();
|
638 | 638 | }
|
639 | 639 |
|
640 | 640 | @Test
|
641 |
| - public void testDetectsInterfaces() throws Exception { |
| 641 | + public void testDetectsInterfaces() { |
642 | 642 | ProxyFactoryBean fb = new ProxyFactoryBean();
|
643 | 643 | fb.setTarget(new TestBean());
|
644 | 644 | fb.addAdvice(new DebugInterceptor());
|
645 | 645 | fb.setBeanFactory(new DefaultListableBeanFactory());
|
| 646 | + |
646 | 647 | ITestBean proxy = (ITestBean) fb.getObject();
|
647 | 648 | assertThat(AopUtils.isJdkDynamicProxy(proxy)).isTrue();
|
648 | 649 | }
|
649 | 650 |
|
| 651 | + @Test |
| 652 | + public void testWithInterceptorNames() { |
| 653 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 654 | + bf.registerSingleton("debug", new DebugInterceptor()); |
| 655 | + |
| 656 | + ProxyFactoryBean fb = new ProxyFactoryBean(); |
| 657 | + fb.setTarget(new TestBean()); |
| 658 | + fb.setInterceptorNames("debug"); |
| 659 | + fb.setBeanFactory(bf); |
| 660 | + |
| 661 | + Advised proxy = (Advised) fb.getObject(); |
| 662 | + assertThat(proxy.getAdvisorCount()).isEqualTo(1); |
| 663 | + } |
| 664 | + |
| 665 | + @Test |
| 666 | + public void testWithLateInterceptorNames() { |
| 667 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 668 | + bf.registerSingleton("debug", new DebugInterceptor()); |
| 669 | + |
| 670 | + ProxyFactoryBean fb = new ProxyFactoryBean(); |
| 671 | + fb.setTarget(new TestBean()); |
| 672 | + fb.setBeanFactory(bf); |
| 673 | + fb.getObject(); |
| 674 | + |
| 675 | + fb.setInterceptorNames("debug"); |
| 676 | + Advised proxy = (Advised) fb.getObject(); |
| 677 | + assertThat(proxy.getAdvisorCount()).isEqualTo(1); |
| 678 | + } |
| 679 | + |
650 | 680 |
|
651 | 681 | /**
|
652 | 682 | * Fires only on void methods. Saves list of methods intercepted.
|
|
0 commit comments