Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix InvocationContextTest and InterceptorBindingInheritanceTest #497

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testGetTargetMethod() {
SimpleBean instance = getContextualReference(SimpleBean.class);
instance.setId(10);
assertEquals(instance.getId(), 10);
assertSame(Interceptor1.getTarget(), instance);
assertEquals(Interceptor1.getTarget().getId(), 10);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,48 +52,54 @@ public static WebArchive createTestArchive() {
@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertions({ @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "ad"), @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "ada") })
public void testInterceptorBindingDirectlyInheritedFromManagedBean(Larch larch) throws Exception {
Plant.clearInspections();
larch.pong();
assertTrue(Plant.inspectedBy(larch, squirrel));
assertFalse(Plant.inspectedBy(larch, woodpecker));
assertTrue(Plant.inspectedBy(squirrel));
assertFalse(Plant.inspectedBy(woodpecker));
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertions({ @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "aj"), @SpecAssertion(section = TYPE_LEVEL_INHERITANCE, id = "aja") })
public void testInterceptorBindingIndirectlyInheritedFromManagedBean(@European Larch europeanLarch) throws Exception {
Plant.clearInspections();
europeanLarch.pong();
assertTrue(europeanLarch instanceof EuropeanLarch);
assertTrue(Plant.inspectedBy(europeanLarch, squirrel));
assertFalse(Plant.inspectedBy(europeanLarch, woodpecker));
assertTrue(Plant.inspectedBy(squirrel));
assertFalse(Plant.inspectedBy(woodpecker));
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "ka")
public void testMethodInterceptorBindingDirectlyInheritedFromManagedBean(Herb herb) {
Plant.clearInspections();
herb.pong();
assertTrue(Plant.inspectedBy(herb, squirrel));
assertTrue(Plant.inspectedBy(squirrel));
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "kc")
public void testMethodInterceptorBindingIndirectlyInheritedFromManagedBean(@Culinary Herb thyme) {
Plant.clearInspections();
thyme.pong();
assertTrue(thyme instanceof Thyme);
assertTrue(Plant.inspectedBy(thyme, squirrel));
assertTrue(Plant.inspectedBy(squirrel));
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "ka")
public void testMethodInterceptorBindingDirectlyNotInheritedFromManagedBean(Shrub shrub) {
Plant.clearInspections();
shrub.pong();
assertFalse(Plant.inspectedBy(shrub, squirrel));
assertFalse(Plant.inspectedBy(squirrel));
}

@Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)
@SpecAssertion(section = MEMBER_LEVEL_INHERITANCE, id = "kc")
public void testMethodInterceptorBindingIndirectlyNotInheritedFromManagedBean(@Culinary Shrub rosehip) {
Plant.clearInspections();
rosehip.pong();
assertTrue(rosehip instanceof Rosehip);
assertFalse(Plant.inspectedBy(rosehip, squirrel));
assertFalse(Plant.inspectedBy(squirrel));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@

public abstract class Plant implements Ping {

private List<String> inspections = new ArrayList<String>();
private static List<String> inspections = new ArrayList<String>();

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

public static void inspect(Plant plant, String id) {
plant.inspections.add(id);
public static void inspect(String id) {
inspections.add(id);
}

public static boolean inspectedBy(Plant plant, String id) {
return plant.inspections.contains(id);
public static boolean inspectedBy(String id) {
return inspections.contains(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Object intercept(InvocationContext ctx) throws Exception {
Object target = ctx.getTarget();

if (target instanceof Plant) {
Plant.inspect((Plant) target, SquirrelInterceptor.class.getName());
Plant.inspect(SquirrelInterceptor.class.getName());
}
return ctx.proceed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Object intercept(InvocationContext ctx) throws Exception {
Object target = ctx.getTarget();

if (target instanceof Plant) {
Plant.inspect((Plant) target, WoodpeckerInterceptor.class.getName());
Plant.inspect(WoodpeckerInterceptor.class.getName());
}
return ctx.proceed();
}
Expand Down
Loading