@@ -189,25 +189,22 @@ public int compareTo(Object arg0) {
189
189
}
190
190
}
191
191
TestBeanSubclass raw = new TestBeanSubclass ();
192
- ProxyFactory factory = new ProxyFactory (raw );
193
- //System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
194
- assertThat (factory .getProxiedInterfaces ()).as ("Found correct number of interfaces" ).hasSize (5 );
195
- ITestBean tb = (ITestBean ) factory .getProxy ();
192
+ ProxyFactory pf = new ProxyFactory (raw );
193
+ assertThat (pf .getProxiedInterfaces ()).as ("Found correct number of interfaces" ).hasSize (5 );
194
+ ITestBean tb = (ITestBean ) pf .getProxy ();
196
195
assertThat (tb ).as ("Picked up secondary interface" ).isInstanceOf (IOther .class );
197
196
raw .setAge (25 );
198
197
assertThat (tb .getAge ()).isEqualTo (raw .getAge ());
199
198
199
+ Class <?>[] oldProxiedInterfaces = pf .getProxiedInterfaces ();
200
200
long t = 555555L ;
201
201
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor (t );
202
+ pf .addAdvisor (0 , new DefaultIntroductionAdvisor (ti , TimeStamped .class ));
202
203
203
- Class <?>[] oldProxiedInterfaces = factory .getProxiedInterfaces ();
204
-
205
- factory .addAdvisor (0 , new DefaultIntroductionAdvisor (ti , TimeStamped .class ));
206
-
207
- Class <?>[] newProxiedInterfaces = factory .getProxiedInterfaces ();
204
+ Class <?>[] newProxiedInterfaces = pf .getProxiedInterfaces ();
208
205
assertThat (newProxiedInterfaces ).as ("Advisor proxies one more interface after introduction" ).hasSize (oldProxiedInterfaces .length + 1 );
209
206
210
- TimeStamped ts = (TimeStamped ) factory .getProxy ();
207
+ TimeStamped ts = (TimeStamped ) pf .getProxy ();
211
208
assertThat (ts .getTimeStamp ()).isEqualTo (t );
212
209
// Shouldn't fail;
213
210
((IOther ) ts ).absquatulate ();
@@ -224,26 +221,26 @@ public Object invoke(MethodInvocation invocation) {
224
221
225
222
NopInterceptor di = new NopInterceptor ();
226
223
NopInterceptor diUnused = new NopInterceptor ();
227
- ProxyFactory factory = new ProxyFactory (new TestBean ());
228
- factory .addAdvice (0 , di );
229
- assertThat (factory .getProxy ()).isInstanceOf (ITestBean .class );
230
- assertThat (factory .adviceIncluded (di )).isTrue ();
231
- assertThat (factory .adviceIncluded (diUnused )).isFalse ();
232
- assertThat (factory .countAdvicesOfType (NopInterceptor .class )).isEqualTo (1 );
233
- assertThat (factory .countAdvicesOfType (MyInterceptor .class )).isEqualTo (0 );
234
-
235
- factory .addAdvice (0 , diUnused );
236
- assertThat (factory .adviceIncluded (diUnused )).isTrue ();
237
- assertThat (factory .countAdvicesOfType (NopInterceptor .class )).isEqualTo (2 );
224
+ ProxyFactory pf = new ProxyFactory (new TestBean ());
225
+ pf .addAdvice (0 , di );
226
+ assertThat (pf .getProxy ()).isInstanceOf (ITestBean .class );
227
+ assertThat (pf .adviceIncluded (di )).isTrue ();
228
+ assertThat (pf .adviceIncluded (diUnused )).isFalse ();
229
+ assertThat (pf .countAdvicesOfType (NopInterceptor .class )).isEqualTo (1 );
230
+ assertThat (pf .countAdvicesOfType (MyInterceptor .class )).isEqualTo (0 );
231
+
232
+ pf .addAdvice (0 , diUnused );
233
+ assertThat (pf .adviceIncluded (diUnused )).isTrue ();
234
+ assertThat (pf .countAdvicesOfType (NopInterceptor .class )).isEqualTo (2 );
238
235
}
239
236
240
237
@ Test
241
238
void sealedInterfaceExclusion () {
242
239
// String implements ConstantDesc on JDK 12+, sealed as of JDK 17
243
- ProxyFactory factory = new ProxyFactory ("" );
240
+ ProxyFactory pf = new ProxyFactory ("" );
244
241
NopInterceptor di = new NopInterceptor ();
245
- factory .addAdvice (0 , di );
246
- Object proxy = factory .getProxy ();
242
+ pf .addAdvice (0 , di );
243
+ Object proxy = pf .getProxy ();
247
244
assertThat (proxy ).isInstanceOf (CharSequence .class );
248
245
}
249
246
@@ -330,6 +327,19 @@ void proxyTargetClassWithConcreteClassAsTarget() {
330
327
assertThat (AopProxyUtils .ultimateTargetClass (proxy2 )).isEqualTo (TestBean .class );
331
328
}
332
329
330
+ @ Test
331
+ void proxyTargetClassWithIntroducedInterface () {
332
+ ProxyFactory pf = new ProxyFactory ();
333
+ pf .setTargetClass (MyDate .class );
334
+ TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor (0L );
335
+ pf .addAdvisor (0 , new DefaultIntroductionAdvisor (ti , TimeStamped .class ));
336
+ Object proxy = pf .getProxy ();
337
+ assertThat (AopUtils .isCglibProxy (proxy )).as ("Proxy is a CGLIB proxy" ).isTrue ();
338
+ assertThat (proxy ).isInstanceOf (MyDate .class );
339
+ assertThat (proxy ).isInstanceOf (TimeStamped .class );
340
+ assertThat (AopProxyUtils .ultimateTargetClass (proxy )).isEqualTo (MyDate .class );
341
+ }
342
+
333
343
@ Test
334
344
void interfaceProxiesCanBeOrderedThroughAnnotations () {
335
345
Object proxy1 = new ProxyFactory (new A ()).getProxy ();
0 commit comments