|
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 |
|
@@ -631,20 +631,50 @@ public void testFrozenFactoryBean() {
|
631 | 631 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
632 | 632 | new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
|
633 | 633 |
|
634 |
| - Advised advised = (Advised)bf.getBean("frozen"); |
| 634 | + Advised advised = (Advised) bf.getBean("frozen"); |
635 | 635 | assertThat(advised.isFrozen()).as("The proxy should be frozen").isTrue();
|
636 | 636 | }
|
637 | 637 |
|
638 | 638 | @Test
|
639 |
| - public void testDetectsInterfaces() throws Exception { |
| 639 | + public void testDetectsInterfaces() { |
640 | 640 | ProxyFactoryBean fb = new ProxyFactoryBean();
|
641 | 641 | fb.setTarget(new TestBean());
|
642 | 642 | fb.addAdvice(new DebugInterceptor());
|
643 | 643 | fb.setBeanFactory(new DefaultListableBeanFactory());
|
| 644 | + |
644 | 645 | ITestBean proxy = (ITestBean) fb.getObject();
|
645 | 646 | assertThat(AopUtils.isJdkDynamicProxy(proxy)).isTrue();
|
646 | 647 | }
|
647 | 648 |
|
| 649 | + @Test |
| 650 | + public void testWithInterceptorNames() { |
| 651 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 652 | + bf.registerSingleton("debug", new DebugInterceptor()); |
| 653 | + |
| 654 | + ProxyFactoryBean fb = new ProxyFactoryBean(); |
| 655 | + fb.setTarget(new TestBean()); |
| 656 | + fb.setInterceptorNames("debug"); |
| 657 | + fb.setBeanFactory(bf); |
| 658 | + |
| 659 | + Advised proxy = (Advised) fb.getObject(); |
| 660 | + assertThat(proxy.getAdvisors().length).isEqualTo(1); |
| 661 | + } |
| 662 | + |
| 663 | + @Test |
| 664 | + public void testWithLateInterceptorNames() { |
| 665 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 666 | + bf.registerSingleton("debug", new DebugInterceptor()); |
| 667 | + |
| 668 | + ProxyFactoryBean fb = new ProxyFactoryBean(); |
| 669 | + fb.setTarget(new TestBean()); |
| 670 | + fb.setBeanFactory(bf); |
| 671 | + fb.getObject(); |
| 672 | + |
| 673 | + fb.setInterceptorNames("debug"); |
| 674 | + Advised proxy = (Advised) fb.getObject(); |
| 675 | + assertThat(proxy.getAdvisors().length).isEqualTo(1); |
| 676 | + } |
| 677 | + |
648 | 678 |
|
649 | 679 | /**
|
650 | 680 | * Fires only on void methods. Saves list of methods intercepted.
|
|
0 commit comments