1
- package org .springframework .aop .framework ;
1
+ /*
2
+ * Copyright 2002-2024 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
2
16
3
- import static java .util .Objects .requireNonNull ;
4
- import static org .mockito .Mockito .doAnswer ;
5
- import static org .mockito .Mockito .doThrow ;
6
- import static org .mockito .Mockito .mock ;
17
+ package org .springframework .aop .framework ;
7
18
19
+ import java .io .Serial ;
8
20
import java .lang .reflect .Proxy ;
9
21
import java .lang .reflect .UndeclaredThrowableException ;
10
- import java .util .Collection ;
11
- import java .util .Set ;
22
+ import java .util .Objects ;
12
23
13
- import org .aopalliance .aop .Advice ;
14
24
import org .aopalliance .intercept .MethodInterceptor ;
15
25
import org .assertj .core .api .WithAssertions ;
16
26
import org .junit .jupiter .api .BeforeEach ;
17
27
import org .junit .jupiter .api .Nested ;
18
28
import org .junit .jupiter .api .Test ;
19
29
import org .mockito .Mockito ;
20
30
import org .mockito .stubbing .Answer ;
31
+
21
32
import org .springframework .cglib .proxy .Enhancer ;
22
33
import org .springframework .lang .Nullable ;
23
34
35
+ import static org .mockito .BDDMockito .doAnswer ;
36
+ import static org .mockito .BDDMockito .doThrow ;
37
+ import static org .mockito .BDDMockito .mock ;
38
+
24
39
abstract class ProxyExceptionHandlingTests implements WithAssertions {
25
40
26
41
private static final RuntimeException uncheckedException = new RuntimeException ();
@@ -35,7 +50,7 @@ abstract class ProxyExceptionHandlingTests implements WithAssertions {
35
50
@ Nullable
36
51
private Throwable throwableSeenByCaller ;
37
52
38
- static class ObjenesisCglibAopProxyTest extends ProxyExceptionHandlingTests {
53
+ static class ObjenesisCglibAopProxyTests extends ProxyExceptionHandlingTests {
39
54
@ BeforeEach
40
55
void beforeEach () {
41
56
proxyFactory .setProxyTargetClass (true );
@@ -47,14 +62,15 @@ protected void assertProxyType(Object proxy) {
47
62
}
48
63
}
49
64
50
- static class JdkAopProxyTest extends ProxyExceptionHandlingTests {
65
+ static class JdkAopProxyTests extends ProxyExceptionHandlingTests {
51
66
@ Override
52
67
protected void assertProxyType (Object proxy ) {
53
68
assertThat (Proxy .isProxyClass (proxy .getClass ())).isTrue ();
54
69
}
55
70
}
56
71
57
- protected void assertProxyType (Object proxy ) {};
72
+ protected void assertProxyType (Object proxy ) {
73
+ }
58
74
59
75
@ BeforeEach
60
76
void beforeEach () {
@@ -112,7 +128,8 @@ private MethodInterceptor captureThrowable() {
112
128
return invocation -> {
113
129
try {
114
130
return invocation .proceed ();
115
- } catch (Exception e ) {
131
+ }
132
+ catch (Exception e ) {
116
133
throwableSeenByInterceptor = e ;
117
134
throw e ;
118
135
}
@@ -161,7 +178,7 @@ void targetThrowsUncheckedException() throws DeclaredCheckedException {
161
178
}
162
179
163
180
private void invokeProxy () {
164
- throwableSeenByCaller = catchThrowable (() -> requireNonNull (proxy ).doSomething ());
181
+ throwableSeenByCaller = catchThrowable (() -> Objects . requireNonNull (proxy ).doSomething ());
165
182
}
166
183
167
184
private Answer <?> sneakyThrow (@ SuppressWarnings ("SameParameterValue" ) Throwable throwable ) {
@@ -182,9 +199,13 @@ protected interface MyInterface {
182
199
}
183
200
184
201
protected static class UndeclaredCheckedException extends Exception {
202
+ @ Serial
203
+ private static final long serialVersionUID = -4199611059122356651L ;
185
204
}
186
205
187
206
protected static class DeclaredCheckedException extends Exception {
207
+ @ Serial
208
+ private static final long serialVersionUID = 8851375818059230518L ;
188
209
}
189
210
190
211
}
0 commit comments