From 4995fc0916345ae3724a752772d1c146262e391a Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Thu, 11 Jan 2024 13:33:43 +0100 Subject: [PATCH] add more tests for InvocationContext.getInterceptorBindings() - interceptor binding inherited from a superclass - method-level interceptor binding "overriding" a class-level interceptor binding of the same type --- .../contract/invocationContext/Binding16.java | 34 +++++++++++++++++++ .../InvocationContextTest.java | 9 +++-- .../invocationContext/SimpleBean.java | 4 ++- .../invocationContext/SuperBinding.java | 20 +++++++++++ .../invocationContext/SuperClass.java | 5 +++ 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/Binding16.java create mode 100644 impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperBinding.java create mode 100644 impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperClass.java diff --git a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/Binding16.java b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/Binding16.java new file mode 100644 index 000000000..3c2a886fc --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/Binding16.java @@ -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 implements Binding16 { + private final String value; + + public Literal(String value) { + this.value = value; + } + + @Override + public String value() { + return value; + } + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/InvocationContextTest.java b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/InvocationContextTest.java index 0f347c72d..c5c82a4ba 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/InvocationContextTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/InvocationContextTest.java @@ -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()); diff --git a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SimpleBean.java b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SimpleBean.java index c2a157d8d..eb1591e78 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SimpleBean.java +++ b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SimpleBean.java @@ -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; @@ -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; } diff --git a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperBinding.java b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperBinding.java new file mode 100644 index 000000000..98d130989 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperBinding.java @@ -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 implements SuperBinding {} +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperClass.java b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperClass.java new file mode 100644 index 000000000..d669947b9 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/interceptors/tests/contract/invocationContext/SuperClass.java @@ -0,0 +1,5 @@ +package org.jboss.cdi.tck.interceptors.tests.contract.invocationContext; + +@SuperBinding +public class SuperClass { +}