|
17 | 17 | package org.springframework.aop.framework;
|
18 | 18 |
|
19 | 19 | import java.lang.reflect.Proxy;
|
20 |
| -import java.util.Arrays; |
21 |
| -import java.util.List; |
22 | 20 |
|
23 | 21 | import org.junit.jupiter.api.Test;
|
24 | 22 |
|
|
30 | 28 | import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
31 | 29 |
|
32 | 30 | /**
|
| 31 | + * Tests for {@link AopProxyUtils}. |
| 32 | + * |
33 | 33 | * @author Rod Johnson
|
34 | 34 | * @author Chris Beams
|
35 | 35 | * @author Sam Brannen
|
36 | 36 | */
|
37 |
| -public class AopProxyUtilsTests { |
| 37 | +class AopProxyUtilsTests { |
38 | 38 |
|
39 | 39 | @Test
|
40 |
| - public void testCompleteProxiedInterfacesWorksWithNull() { |
| 40 | + void completeProxiedInterfacesWorksWithNull() { |
41 | 41 | AdvisedSupport as = new AdvisedSupport();
|
42 | 42 | Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
43 |
| - assertThat(completedInterfaces.length).isEqualTo(2); |
44 |
| - List<?> ifaces = Arrays.asList(completedInterfaces); |
45 |
| - assertThat(ifaces.contains(Advised.class)).isTrue(); |
46 |
| - assertThat(ifaces.contains(SpringProxy.class)).isTrue(); |
| 43 | + assertThat(completedInterfaces).containsExactly(SpringProxy.class, Advised.class); |
47 | 44 | }
|
48 | 45 |
|
49 | 46 | @Test
|
50 |
| - public void testCompleteProxiedInterfacesWorksWithNullOpaque() { |
| 47 | + void completeProxiedInterfacesWorksWithNullOpaque() { |
51 | 48 | AdvisedSupport as = new AdvisedSupport();
|
52 | 49 | as.setOpaque(true);
|
53 | 50 | Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
54 |
| - assertThat(completedInterfaces.length).isEqualTo(1); |
| 51 | + assertThat(completedInterfaces).containsExactly(SpringProxy.class); |
55 | 52 | }
|
56 | 53 |
|
57 | 54 | @Test
|
58 |
| - public void testCompleteProxiedInterfacesAdvisedNotIncluded() { |
| 55 | + void completeProxiedInterfacesAdvisedNotIncluded() { |
59 | 56 | AdvisedSupport as = new AdvisedSupport();
|
60 | 57 | as.addInterface(ITestBean.class);
|
61 | 58 | as.addInterface(Comparable.class);
|
62 | 59 | Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
63 |
| - assertThat(completedInterfaces.length).isEqualTo(4); |
64 |
| - |
65 |
| - // Can't assume ordering for others, so use a list |
66 |
| - List<?> l = Arrays.asList(completedInterfaces); |
67 |
| - assertThat(l.contains(Advised.class)).isTrue(); |
68 |
| - assertThat(l.contains(ITestBean.class)).isTrue(); |
69 |
| - assertThat(l.contains(Comparable.class)).isTrue(); |
| 60 | + assertThat(completedInterfaces).containsExactly( |
| 61 | + ITestBean.class, Comparable.class, SpringProxy.class, Advised.class); |
70 | 62 | }
|
71 | 63 |
|
72 | 64 | @Test
|
73 |
| - public void testCompleteProxiedInterfacesAdvisedIncluded() { |
| 65 | + void completeProxiedInterfacesAdvisedIncluded() { |
74 | 66 | AdvisedSupport as = new AdvisedSupport();
|
| 67 | + as.addInterface(Advised.class); |
75 | 68 | as.addInterface(ITestBean.class);
|
76 | 69 | as.addInterface(Comparable.class);
|
77 |
| - as.addInterface(Advised.class); |
78 | 70 | Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
79 |
| - assertThat(completedInterfaces.length).isEqualTo(4); |
80 |
| - |
81 |
| - // Can't assume ordering for others, so use a list |
82 |
| - List<?> l = Arrays.asList(completedInterfaces); |
83 |
| - assertThat(l.contains(Advised.class)).isTrue(); |
84 |
| - assertThat(l.contains(ITestBean.class)).isTrue(); |
85 |
| - assertThat(l.contains(Comparable.class)).isTrue(); |
| 71 | + assertThat(completedInterfaces).containsExactly( |
| 72 | + Advised.class, ITestBean.class, Comparable.class, SpringProxy.class); |
86 | 73 | }
|
87 | 74 |
|
88 | 75 | @Test
|
89 |
| - public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() { |
| 76 | + void completeProxiedInterfacesAdvisedNotIncludedOpaque() { |
90 | 77 | AdvisedSupport as = new AdvisedSupport();
|
91 | 78 | as.setOpaque(true);
|
92 | 79 | as.addInterface(ITestBean.class);
|
93 | 80 | as.addInterface(Comparable.class);
|
94 | 81 | Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
95 |
| - assertThat(completedInterfaces.length).isEqualTo(3); |
96 |
| - |
97 |
| - // Can't assume ordering for others, so use a list |
98 |
| - List<?> l = Arrays.asList(completedInterfaces); |
99 |
| - assertThat(l.contains(Advised.class)).isFalse(); |
100 |
| - assertThat(l.contains(ITestBean.class)).isTrue(); |
101 |
| - assertThat(l.contains(Comparable.class)).isTrue(); |
| 82 | + assertThat(completedInterfaces).containsExactly(ITestBean.class, Comparable.class, SpringProxy.class); |
102 | 83 | }
|
103 | 84 |
|
104 | 85 | @Test
|
105 |
| - public void testProxiedUserInterfacesWithSingleInterface() { |
| 86 | + void proxiedUserInterfacesWithSingleInterface() { |
106 | 87 | ProxyFactory pf = new ProxyFactory();
|
107 | 88 | pf.setTarget(new TestBean());
|
108 | 89 | pf.addInterface(ITestBean.class);
|
109 |
| - Object proxy = pf.getProxy(); |
110 |
| - Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy); |
111 |
| - assertThat(userInterfaces.length).isEqualTo(1); |
112 |
| - assertThat(userInterfaces[0]).isEqualTo(ITestBean.class); |
| 90 | + Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(pf.getProxy()); |
| 91 | + assertThat(userInterfaces).containsExactly(ITestBean.class); |
113 | 92 | }
|
114 | 93 |
|
115 | 94 | @Test
|
116 |
| - public void testProxiedUserInterfacesWithMultipleInterfaces() { |
| 95 | + void proxiedUserInterfacesWithMultipleInterfaces() { |
117 | 96 | ProxyFactory pf = new ProxyFactory();
|
118 | 97 | pf.setTarget(new TestBean());
|
119 | 98 | pf.addInterface(ITestBean.class);
|
120 | 99 | pf.addInterface(Comparable.class);
|
121 |
| - Object proxy = pf.getProxy(); |
122 |
| - Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy); |
123 |
| - assertThat(userInterfaces.length).isEqualTo(2); |
124 |
| - assertThat(userInterfaces[0]).isEqualTo(ITestBean.class); |
125 |
| - assertThat(userInterfaces[1]).isEqualTo(Comparable.class); |
| 100 | + Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(pf.getProxy()); |
| 101 | + assertThat(userInterfaces).containsExactly(ITestBean.class, Comparable.class); |
126 | 102 | }
|
127 | 103 |
|
128 | 104 | @Test
|
129 |
| - public void testProxiedUserInterfacesWithNoInterface() { |
| 105 | + void proxiedUserInterfacesWithNoInterface() { |
130 | 106 | Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0],
|
131 | 107 | (proxy1, method, args) -> null);
|
132 |
| - assertThatIllegalArgumentException().isThrownBy(() -> |
133 |
| - AopProxyUtils.proxiedUserInterfaces(proxy)); |
| 108 | + assertThatIllegalArgumentException().isThrownBy(() -> AopProxyUtils.proxiedUserInterfaces(proxy)); |
134 | 109 | }
|
135 | 110 |
|
136 | 111 | }
|
0 commit comments