Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d78bfc7

Browse files
Ladicekmanovotn
authored andcommittedNov 28, 2023
fix InvocationContextTest and InterceptorBindingInheritanceTest
This is to cater for implementations that implement interception by proxying, in which case the contextual instance of a bean is an interception proxy, while `InvocationContext.getTarget()` returns the proxied object (an "actual" instance of the bean).
1 parent 652830b commit d78bfc7

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed
 

‎impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/InvocationContextTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void testGetTargetMethod() {
5656
SimpleBean instance = getContextualReference(SimpleBean.class);
5757
instance.setId(10);
5858
assertEquals(instance.getId(), 10);
59-
assertSame(Interceptor1.getTarget(), instance);
59+
assertEquals(Interceptor1.getTarget().getId(), 10);
6060
}
6161

6262
@Test

‎impl/src/main/java/org/jboss/cdi/tck/tests/interceptors/definition/inheritance/InterceptorBindingInheritanceTest.java

+14-8
Original file line numberDiff line numberDiff line change
@@ -52,48 +52,54 @@ public static WebArchive createTestArchive() {
5252
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
5353
@SpecAssertions({ @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "ad"), @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "ada") })
5454
public void testInterceptorBindingDirectlyInheritedFromManagedBean(Larch larch) throws Exception {
55+
Plant.clearInspections();
5556
larch.pong();
56-
assertTrue(Plant.inspectedBy(larch, squirrel));
57-
assertFalse(Plant.inspectedBy(larch, woodpecker));
57+
assertTrue(Plant.inspectedBy(squirrel));
58+
assertFalse(Plant.inspectedBy(woodpecker));
5859
}
5960

6061
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
6162
@SpecAssertions({ @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "aj"), @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "aja") })
6263
public void testInterceptorBindingIndirectlyInheritedFromManagedBean(@European Larch europeanLarch) throws Exception {
64+
Plant.clearInspections();
6365
europeanLarch.pong();
6466
assertTrue(europeanLarch instanceof EuropeanLarch);
65-
assertTrue(Plant.inspectedBy(europeanLarch, squirrel));
66-
assertFalse(Plant.inspectedBy(europeanLarch, woodpecker));
67+
assertTrue(Plant.inspectedBy(squirrel));
68+
assertFalse(Plant.inspectedBy(woodpecker));
6769
}
6870

6971
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
7072
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "ka")
7173
public void testMethodInterceptorBindingDirectlyInheritedFromManagedBean(Herb herb) {
74+
Plant.clearInspections();
7275
herb.pong();
73-
assertTrue(Plant.inspectedBy(herb, squirrel));
76+
assertTrue(Plant.inspectedBy(squirrel));
7477
}
7578

7679
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
7780
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "kc")
7881
public void testMethodInterceptorBindingIndirectlyInheritedFromManagedBean(@Culinary Herb thyme) {
82+
Plant.clearInspections();
7983
thyme.pong();
8084
assertTrue(thyme instanceof Thyme);
81-
assertTrue(Plant.inspectedBy(thyme, squirrel));
85+
assertTrue(Plant.inspectedBy(squirrel));
8286
}
8387

8488
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
8589
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "ka")
8690
public void testMethodInterceptorBindingDirectlyNotInheritedFromManagedBean(Shrub shrub) {
91+
Plant.clearInspections();
8792
shrub.pong();
88-
assertFalse(Plant.inspectedBy(shrub, squirrel));
93+
assertFalse(Plant.inspectedBy(squirrel));
8994
}
9095

9196
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
9297
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "kc")
9398
public void testMethodInterceptorBindingIndirectlyNotInheritedFromManagedBean(@Culinary Shrub rosehip) {
99+
Plant.clearInspections();
94100
rosehip.pong();
95101
assertTrue(rosehip instanceof Rosehip);
96-
assertFalse(Plant.inspectedBy(rosehip, squirrel));
102+
assertFalse(Plant.inspectedBy(squirrel));
97103
}
98104

99105
}

‎impl/src/main/java/org/jboss/cdi/tck/tests/interceptors/definition/inheritance/Plant.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@
2121

2222
public abstract class Plant implements Ping {
2323

24-
private List<String> inspections = new ArrayList<String>();
24+
private static List<String> inspections = new ArrayList<String>();
2525

26-
// all beans of type `Plant` are `@Dependent`, so accessing the field is OK
26+
public static void clearInspections() {
27+
inspections.clear();
28+
}
2729

28-
public static void inspect(Plant plant, String id) {
29-
plant.inspections.add(id);
30+
public static void inspect(String id) {
31+
inspections.add(id);
3032
}
3133

32-
public static boolean inspectedBy(Plant plant, String id) {
33-
return plant.inspections.contains(id);
34+
public static boolean inspectedBy(String id) {
35+
return inspections.contains(id);
3436
}
3537

3638
}

‎impl/src/main/java/org/jboss/cdi/tck/tests/interceptors/definition/inheritance/SquirrelInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Object intercept(InvocationContext ctx) throws Exception {
3232
Object target = ctx.getTarget();
3333

3434
if (target instanceof Plant) {
35-
Plant.inspect((Plant) target, SquirrelInterceptor.class.getName());
35+
Plant.inspect(SquirrelInterceptor.class.getName());
3636
}
3737
return ctx.proceed();
3838
}

‎impl/src/main/java/org/jboss/cdi/tck/tests/interceptors/definition/inheritance/WoodpeckerInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Object intercept(InvocationContext ctx) throws Exception {
3232
Object target = ctx.getTarget();
3333

3434
if (target instanceof Plant) {
35-
Plant.inspect((Plant) target, WoodpeckerInterceptor.class.getName());
35+
Plant.inspect(WoodpeckerInterceptor.class.getName());
3636
}
3737
return ctx.proceed();
3838
}

0 commit comments

Comments
 (0)
Failed to load comments.