1717package org .springframework .resilience ;
1818
1919import java .io .IOException ;
20+ import java .lang .reflect .InvocationTargetException ;
2021import java .lang .reflect .Method ;
2122import java .nio .file .AccessDeniedException ;
2223import java .time .Duration ;
2324import java .util .Properties ;
2425import java .util .concurrent .atomic .AtomicInteger ;
2526
27+ import org .aopalliance .intercept .MethodInterceptor ;
2628import org .junit .jupiter .api .Test ;
2729
2830import org .springframework .aop .framework .AopProxyUtils ;
2931import org .springframework .aop .framework .ProxyConfig ;
3032import org .springframework .aop .framework .ProxyFactory ;
3133import org .springframework .aop .framework .autoproxy .AutoProxyUtils ;
34+ import org .springframework .aop .interceptor .SimpleTraceInterceptor ;
3235import org .springframework .aop .support .AopUtils ;
3336import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
3437import org .springframework .beans .factory .support .RootBeanDefinition ;
@@ -59,7 +62,30 @@ void withSimpleInterceptor() {
5962 pf .setTarget (target );
6063 pf .addAdvice (new SimpleRetryInterceptor (
6164 new MethodRetrySpec ((m , t ) -> true , 5 , Duration .ofMillis (10 ))));
62- NonAnnotatedBean proxy = (NonAnnotatedBean ) pf .getProxy ();
65+ pf .addAdvice (new SimpleTraceInterceptor ());
66+ PlainInterface proxy = (PlainInterface ) pf .getProxy ();
67+
68+ assertThatIOException ().isThrownBy (proxy ::retryOperation ).withMessage ("6" );
69+ assertThat (target .counter ).isEqualTo (6 );
70+ }
71+
72+ @ Test
73+ void withSimpleInterceptorAndNoTarget () {
74+ NonAnnotatedBean target = new NonAnnotatedBean ();
75+ ProxyFactory pf = new ProxyFactory ();
76+ pf .addAdvice (new SimpleRetryInterceptor (
77+ new MethodRetrySpec ((m , t ) -> true , 5 , Duration .ofMillis (10 ))));
78+ pf .addAdvice (new SimpleTraceInterceptor ());
79+ pf .addAdvice ((MethodInterceptor ) invocation -> {
80+ try {
81+ return invocation .getMethod ().invoke (target , invocation .getArguments ());
82+ }
83+ catch (InvocationTargetException ex ) {
84+ throw ex .getTargetException ();
85+ }
86+ });
87+ pf .addInterface (PlainInterface .class );
88+ PlainInterface proxy = (PlainInterface ) pf .getProxy ();
6389
6490 assertThatIOException ().isThrownBy (proxy ::retryOperation ).withMessage ("6" );
6591 assertThat (target .counter ).isEqualTo (6 );
@@ -237,7 +263,7 @@ void withEnableAnnotation() throws Exception {
237263 }
238264
239265
240- static class NonAnnotatedBean {
266+ static class NonAnnotatedBean implements PlainInterface {
241267
242268 int counter = 0 ;
243269
@@ -248,6 +274,12 @@ public void retryOperation() throws IOException {
248274 }
249275
250276
277+ public interface PlainInterface {
278+
279+ void retryOperation () throws IOException ;
280+ }
281+
282+
251283 static class AnnotatedMethodBean {
252284
253285 int counter = 0 ;
0 commit comments