Skip to content

Commit

Permalink
add more tests for InvocationContext.getInterceptorBindings()
Browse files Browse the repository at this point in the history
- interceptor binding inherited from a superclass
- method-level interceptor binding "overriding" a class-level
  interceptor binding of the same type
  • Loading branch information
Ladicek authored and manovotn committed Jan 11, 2024
1 parent b36995b commit 09bf860
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.enterprise.util.Nonbinding;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface Binding16 {
String value();

class Literal extends AnnotationLiteral<Binding16> implements Binding16 {
private final String value;

public Literal(String value) {
this.value = value;
}

@Override
public String value() {
return value;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,17 @@ public void testGetInterceptorBindings() {
assertTrue(getContextualReference(SimpleBean.class).bindings());
assertEquals(AroundConstructInterceptor1.getAllBindings(), Set.of(new SimplePCBinding.Literal(),
new PseudoBinding.Literal(), new AroundConstructBinding1.Literal(),
new AroundConstructBinding2.Literal()));
new AroundConstructBinding2.Literal(), new Binding16.Literal("class-level"),
new SuperBinding.Literal()));
assertEquals(AroundConstructInterceptor1.getAllBindings(), AroundConstructInterceptor2.getAllBindings());
assertEquals(PostConstructInterceptor.getAllBindings(), Set.of(new SimplePCBinding.Literal(),
new PseudoBinding.Literal(), new AroundConstructBinding1.Literal()));
new PseudoBinding.Literal(), new AroundConstructBinding1.Literal(),
new Binding16.Literal("class-level"), new SuperBinding.Literal()));
assertEquals(Interceptor12.getAllBindings(), Set.of(new SimplePCBinding.Literal(), new PseudoBinding.Literal(),
new AroundConstructBinding1.Literal(), new Binding11.Literal(), new Binding12.Literal(),
new Binding13.Literal("ko"), new Binding14.Literal("foobar"),
new Binding15.Literal(), new Binding15Additional.Literal("AdditionalBinding")));
new Binding15.Literal(), new Binding15Additional.Literal("AdditionalBinding"),
new Binding16.Literal("method-level"), new SuperBinding.Literal()));
assertEquals(Interceptor12.getBinding12s(), Set.of(new Binding12.Literal()));
assertEquals(Interceptor12.getBinding12(), new Binding12.Literal());
assertEquals(Interceptor12.getBinding5s(), Set.of());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
@SimplePCBinding
@PseudoBinding
@AroundConstructBinding1
@Binding16("class-level")
@Dependent
class SimpleBean {
class SimpleBean extends SuperClass {
private int id = 0;
private static boolean echoCalled = false;

Expand Down Expand Up @@ -83,6 +84,7 @@ public String echo(String s) {
@Binding13("ko") // does not associate `Interceptor13` with this bean due to different annotation member
@Binding14("foobar")
@Binding15 // Associates both @Binding15 and @Binding15Additional("AdditionalBinding")
@Binding16("method-level")
public boolean bindings() {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

import jakarta.enterprise.util.AnnotationLiteral;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@InterceptorBinding
@Inherited
@Target({ TYPE, METHOD })
@Retention(RUNTIME)
public @interface SuperBinding {
class Literal extends AnnotationLiteral<SuperBinding> implements SuperBinding {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext;

@SuperBinding
public class SuperClass {
}

0 comments on commit 09bf860

Please sign in to comment.