1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2018 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.
@@ -82,22 +82,24 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
82
82
@ Test
83
83
public void testRejectsPerCflowAspect () {
84
84
try {
85
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new PerCflowAspect (),"someBean" ));
85
+ getFixture ().getAdvisors (
86
+ new SingletonMetadataAwareAspectInstanceFactory (new PerCflowAspect (), "someBean" ));
86
87
fail ("Cannot accept cflow" );
87
88
}
88
89
catch (AopConfigException ex ) {
89
- assertTrue (ex .getMessage ().indexOf ("PERCFLOW" ) != - 1 );
90
+ assertTrue (ex .getMessage ().contains ("PERCFLOW" ));
90
91
}
91
92
}
92
93
93
94
@ Test
94
95
public void testRejectsPerCflowBelowAspect () {
95
96
try {
96
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new PerCflowBelowAspect (),"someBean" ));
97
+ getFixture ().getAdvisors (
98
+ new SingletonMetadataAwareAspectInstanceFactory (new PerCflowBelowAspect (), "someBean" ));
97
99
fail ("Cannot accept cflowbelow" );
98
100
}
99
101
catch (AopConfigException ex ) {
100
- assertTrue (ex .getMessage ().indexOf ("PERCFLOWBELOW" ) != - 1 );
102
+ assertTrue (ex .getMessage ().contains ("PERCFLOWBELOW" ));
101
103
}
102
104
}
103
105
@@ -227,9 +229,7 @@ public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodExce
227
229
int realAge = 65 ;
228
230
target .setAge (realAge );
229
231
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory ();
230
- TestBean itb = (TestBean ) createProxy (target ,
231
- getFixture ().getAdvisors (aif ),
232
- TestBean .class );
232
+ TestBean itb = (TestBean ) createProxy (target , getFixture ().getAdvisors (aif ), TestBean .class );
233
233
assertEquals ("No method calls" , 0 , aif .getInstantiationCount ());
234
234
assertEquals ("Around advice must now apply" , 0 , itb .getAge ());
235
235
@@ -257,9 +257,7 @@ public void testPerTypeWithinAspect() throws SecurityException, NoSuchMethodExce
257
257
assertEquals ("Around advice must still apply" , 1 , itb .getAge ());
258
258
assertEquals ("Around advice must still apply" , 2 , itb .getAge ());
259
259
260
- TestBean itb2 = (TestBean ) createProxy (target ,
261
- getFixture ().getAdvisors (aif ),
262
- TestBean .class );
260
+ TestBean itb2 = (TestBean ) createProxy (target , getFixture ().getAdvisors (aif ), TestBean .class );
263
261
assertEquals (1 , aif .getInstantiationCount ());
264
262
assertEquals ("Around advice be independent for second instance" , 0 , itb2 .getAge ());
265
263
assertEquals (2 , aif .getInstantiationCount ());
@@ -284,7 +282,8 @@ public void testNamedPointcutFromAspectLibrary() {
284
282
public void testNamedPointcutFromAspectLibraryWithBinding () {
285
283
TestBean target = new TestBean ();
286
284
ITestBean itb = (ITestBean ) createProxy (target ,
287
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new NamedPointcutAspectFromLibraryWithBinding (),"someBean" )),
285
+ getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (
286
+ new NamedPointcutAspectFromLibraryWithBinding (), "someBean" )),
288
287
ITestBean .class );
289
288
itb .setAge (10 );
290
289
assertEquals ("Around advice must apply" , 20 , itb .getAge ());
@@ -296,7 +295,7 @@ private void testNamedPointcuts(Object aspectInstance) {
296
295
int realAge = 65 ;
297
296
target .setAge (realAge );
298
297
ITestBean itb = (ITestBean ) createProxy (target ,
299
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (aspectInstance ,"someBean" )),
298
+ getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (aspectInstance , "someBean" )),
300
299
ITestBean .class );
301
300
assertEquals ("Around advice must apply" , -1 , itb .getAge ());
302
301
assertEquals (realAge , target .getAge ());
@@ -306,7 +305,8 @@ private void testNamedPointcuts(Object aspectInstance) {
306
305
public void testBindingWithSingleArg () {
307
306
TestBean target = new TestBean ();
308
307
ITestBean itb = (ITestBean ) createProxy (target ,
309
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new BindingAspectWithSingleArg (),"someBean" )),
308
+ getFixture ().getAdvisors (
309
+ new SingletonMetadataAwareAspectInstanceFactory (new BindingAspectWithSingleArg (), "someBean" )),
310
310
ITestBean .class );
311
311
itb .setAge (10 );
312
312
assertEquals ("Around advice must apply" , 20 , itb .getAge ());
@@ -317,7 +317,8 @@ public void testBindingWithSingleArg() {
317
317
public void testBindingWithMultipleArgsDifferentlyOrdered () {
318
318
ManyValuedArgs target = new ManyValuedArgs ();
319
319
ManyValuedArgs mva = (ManyValuedArgs ) createProxy (target ,
320
- getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new ManyValuedArgs (),"someBean" )),
320
+ getFixture ().getAdvisors (
321
+ new SingletonMetadataAwareAspectInstanceFactory (new ManyValuedArgs (), "someBean" )),
321
322
ManyValuedArgs .class );
322
323
323
324
String a = "a" ;
@@ -338,7 +339,7 @@ public void testIntroductionOnTargetNotImplementingInterface() {
338
339
assertFalse (notLockableTarget instanceof Lockable );
339
340
NotLockable notLockable1 = (NotLockable ) createProxy (notLockableTarget ,
340
341
getFixture ().getAdvisors (
341
- new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (),"someBean" )),
342
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (), "someBean" )),
342
343
NotLockable .class );
343
344
assertTrue (notLockable1 instanceof Lockable );
344
345
Lockable lockable = (Lockable ) notLockable1 ;
@@ -349,7 +350,7 @@ public void testIntroductionOnTargetNotImplementingInterface() {
349
350
NotLockable notLockable2Target = new NotLockable ();
350
351
NotLockable notLockable2 = (NotLockable ) createProxy (notLockable2Target ,
351
352
getFixture ().getAdvisors (
352
- new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (),"someBean" )),
353
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (), "someBean" )),
353
354
NotLockable .class );
354
355
assertTrue (notLockable2 instanceof Lockable );
355
356
Lockable lockable2 = (Lockable ) notLockable2 ;
@@ -369,10 +370,10 @@ public void testIntroductionOnTargetNotImplementingInterface() {
369
370
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface () {
370
371
assertTrue (AopUtils .findAdvisorsThatCanApply (
371
372
getFixture ().getAdvisors (
372
- new SingletonMetadataAwareAspectInstanceFactory (
373
- new MakeLockable (),"someBean" )),
373
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (), "someBean" )),
374
374
CannotBeUnlocked .class ).isEmpty ());
375
- assertEquals (2 , AopUtils .findAdvisorsThatCanApply (getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (),"someBean" )), NotLockable .class ).size ());
375
+ assertEquals (2 , AopUtils .findAdvisorsThatCanApply (getFixture ().getAdvisors (
376
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (),"someBean" )), NotLockable .class ).size ());
376
377
}
377
378
378
379
@ Test
@@ -408,42 +409,34 @@ public void testIntroductionOnTargetExcludedByTypePattern() {
408
409
getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (), "someBean" )),
409
410
List .class
410
411
),
411
- CannotBeUnlocked .class );
412
+ List .class );
412
413
assertFalse ("Type pattern must have excluded mixin" , proxy instanceof Lockable );
413
414
}
414
415
415
- /* prereq AspectJ 1.6.7
416
416
@ Test
417
- public void testIntroductionBasedOnAnnotationMatch_Spr5307 () {
417
+ public void testIntroductionBasedOnAnnotationMatch_SPR5307 () {
418
418
AnnotatedTarget target = new AnnotatedTargetImpl ();
419
-
420
419
List <Advisor > advisors = getFixture ().getAdvisors (
421
- new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(),"someBean"));
422
- Object proxy = createProxy(target,
423
- advisors,
424
- AnnotatedTarget.class);
420
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeAnnotatedTypeModifiable (), "someBean" ));
421
+ Object proxy = createProxy (target , advisors , AnnotatedTarget .class );
425
422
System .out .println (advisors .get (1 ));
426
423
assertTrue (proxy instanceof Lockable );
427
424
Lockable lockable = (Lockable )proxy ;
428
425
lockable .locked ();
429
426
}
430
- */
431
427
432
428
// TODO: Why does this test fail? It hasn't been run before, so it maybe never actually passed...
433
-
434
429
@ Test
435
430
@ Ignore
436
431
public void testIntroductionWithArgumentBinding () {
437
432
TestBean target = new TestBean ();
438
433
439
434
List <Advisor > advisors = getFixture ().getAdvisors (
440
- new SingletonMetadataAwareAspectInstanceFactory (new MakeITestBeanModifiable (),"someBean" ));
435
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeITestBeanModifiable (), "someBean" ));
441
436
advisors .addAll (getFixture ().getAdvisors (
442
- new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (),"someBean" )));
437
+ new SingletonMetadataAwareAspectInstanceFactory (new MakeLockable (), "someBean" )));
443
438
444
- Modifiable modifiable = (Modifiable ) createProxy (target ,
445
- advisors ,
446
- ITestBean .class );
439
+ Modifiable modifiable = (Modifiable ) createProxy (target , advisors , ITestBean .class );
447
440
assertThat (modifiable , instanceOf (Modifiable .class ));
448
441
Lockable lockable = (Lockable ) modifiable ;
449
442
assertFalse (lockable .locked ());
@@ -477,11 +470,11 @@ public void testIntroductionWithArgumentBinding() {
477
470
public void testAspectMethodThrowsExceptionLegalOnSignature () {
478
471
TestBean target = new TestBean ();
479
472
UnsupportedOperationException expectedException = new UnsupportedOperationException ();
480
- List <Advisor > advisors = getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new ExceptionAspect (expectedException ),"someBean" ));
473
+ List <Advisor > advisors = getFixture ().getAdvisors (
474
+ new SingletonMetadataAwareAspectInstanceFactory (new ExceptionAspect (expectedException ), "someBean" ));
481
475
assertEquals ("One advice method was found" , 1 , advisors .size ());
482
- ITestBean itb = (ITestBean ) createProxy (target ,
483
- advisors ,
484
- ITestBean .class );
476
+ ITestBean itb = (ITestBean ) createProxy (target , advisors , ITestBean .class );
477
+
485
478
try {
486
479
itb .getAge ();
487
480
fail ();
@@ -497,11 +490,11 @@ public void testAspectMethodThrowsExceptionLegalOnSignature() {
497
490
public void testAspectMethodThrowsExceptionIllegalOnSignature () {
498
491
TestBean target = new TestBean ();
499
492
RemoteException expectedException = new RemoteException ();
500
- List <Advisor > advisors = getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (new ExceptionAspect (expectedException ),"someBean" ));
493
+ List <Advisor > advisors = getFixture ().getAdvisors (
494
+ new SingletonMetadataAwareAspectInstanceFactory (new ExceptionAspect (expectedException ), "someBean" ));
501
495
assertEquals ("One advice method was found" , 1 , advisors .size ());
502
- ITestBean itb = (ITestBean ) createProxy (target ,
503
- advisors ,
504
- ITestBean .class );
496
+ ITestBean itb = (ITestBean ) createProxy (target , advisors , ITestBean .class );
497
+
505
498
try {
506
499
itb .getAge ();
507
500
fail ();
@@ -522,10 +515,7 @@ protected Object createProxy(Object target, List<Advisor> advisors, Class<?>...
522
515
523
516
// Required everywhere we use AspectJ proxies
524
517
pf .addAdvice (ExposeInvocationInterceptor .INSTANCE );
525
-
526
- for (Object a : advisors ) {
527
- pf .addAdvisor ((Advisor ) a );
528
- }
518
+ pf .addAdvisors (advisors );
529
519
530
520
pf .setExposeProxy (true );
531
521
return pf .getProxy ();
@@ -534,13 +524,11 @@ protected Object createProxy(Object target, List<Advisor> advisors, Class<?>...
534
524
@ Test
535
525
public void testTwoAdvicesOnOneAspect () {
536
526
TestBean target = new TestBean ();
537
-
538
527
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect ();
539
- List <Advisor > advisors = getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (twoAdviceAspect ,"someBean" ));
528
+ List <Advisor > advisors = getFixture ().getAdvisors (
529
+ new SingletonMetadataAwareAspectInstanceFactory (twoAdviceAspect , "someBean" ));
540
530
assertEquals ("Two advice methods found" , 2 , advisors .size ());
541
- ITestBean itb = (ITestBean ) createProxy (target ,
542
- advisors ,
543
- ITestBean .class );
531
+ ITestBean itb = (ITestBean ) createProxy (target , advisors , ITestBean .class );
544
532
itb .setName ("" );
545
533
assertEquals (0 , itb .getAge ());
546
534
int newAge = 32 ;
@@ -551,16 +539,15 @@ public void testTwoAdvicesOnOneAspect() {
551
539
@ Test
552
540
public void testAfterAdviceTypes () throws Exception {
553
541
Echo target = new Echo ();
554
-
555
542
ExceptionHandling afterReturningAspect = new ExceptionHandling ();
556
- List <Advisor > advisors = getFixture ().getAdvisors (new SingletonMetadataAwareAspectInstanceFactory (afterReturningAspect ,"someBean" ));
557
- Echo echo = (Echo ) createProxy (target ,
558
- advisors ,
559
- Echo .class );
543
+ List <Advisor > advisors = getFixture ().getAdvisors (
544
+ new SingletonMetadataAwareAspectInstanceFactory (afterReturningAspect , "someBean" ));
545
+ Echo echo = (Echo ) createProxy (target , advisors , Echo .class );
560
546
assertEquals (0 , afterReturningAspect .successCount );
561
547
assertEquals ("" , echo .echo ("" ));
562
548
assertEquals (1 , afterReturningAspect .successCount );
563
549
assertEquals (0 , afterReturningAspect .failureCount );
550
+
564
551
try {
565
552
echo .echo (new FileNotFoundException ());
566
553
fail ();
@@ -580,30 +567,19 @@ public void testAfterAdviceTypes() throws Exception {
580
567
public void testFailureWithoutExplicitDeclarePrecedence () {
581
568
TestBean target = new TestBean ();
582
569
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory (
583
- new NoDeclarePrecedenceShouldFail (), "someBean" );
570
+ new NoDeclarePrecedenceShouldFail (), "someBean" );
584
571
ITestBean itb = (ITestBean ) createProxy (target ,
585
- getFixture ().getAdvisors (aspectInstanceFactory ), ITestBean .class );
572
+ getFixture ().getAdvisors (aspectInstanceFactory ), ITestBean .class );
586
573
itb .getAge ();
587
574
}
588
575
589
576
@ Test (expected = IllegalArgumentException .class )
590
577
public void testDeclarePrecedenceNotSupported () {
591
578
TestBean target = new TestBean ();
592
579
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory (
593
- new DeclarePrecedenceShouldSucceed (), "someBean" );
594
- createProxy (target , getFixture ().getAdvisors (aspectInstanceFactory ),
595
- ITestBean .class );
596
- }
597
-
598
- /** Not supported in 2.0!
599
- public void testExplicitDeclarePrecedencePreventsFailure() {
600
- TestBean target = new TestBean();
601
- ITestBean itb = (ITestBean) createProxy(target,
602
- getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new DeclarePrecedenceShouldSucceed(), "someBean")),
603
- ITestBean.class);
604
- assertEquals(666, itb.getAge());
580
+ new DeclarePrecedenceShouldSucceed (), "someBean" );
581
+ createProxy (target , getFixture ().getAdvisors (aspectInstanceFactory ), ITestBean .class );
605
582
}
606
- */
607
583
608
584
609
585
@ Aspect ("percflow(execution(* *(..)))" )
@@ -1019,9 +995,7 @@ class MakeLockable {
1019
995
public static Lockable mixin ;
1020
996
1021
997
@ Before (value ="execution(void set*(*)) && this(mixin)" , argNames ="mixin" )
1022
- public void checkNotLocked (
1023
- Lockable mixin ) // Bind to arg
1024
- {
998
+ public void checkNotLocked ( Lockable mixin ) {
1025
999
// Can also obtain the mixin (this) this way
1026
1000
//Lockable mixin = (Lockable) jp.getThis();
1027
1001
if (mixin .locked ()) {
0 commit comments