From ffa1f823d9e03157325e03f7a45d02cb0ff533c6 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Fri, 10 Nov 2023 14:54:28 +0100 Subject: [PATCH] Add coverage for case where alternative bean contains non-alternative producer declaring its own priority --- ...eanProducingPrioritizedNonAlternative.java | 24 +++++++++++++++++++ .../alternative/selection/priority/Delta.java | 14 +++++++++++ .../NonAltBeanProducingAlternative.java | 14 +++++++++++ .../ProducerExplicitPriorityTest.java | 12 ++++++++++ .../priority/RegularBeanProducer.java | 10 ++++++++ 5 files changed, 74 insertions(+) create mode 100644 impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/AltBeanProducingPrioritizedNonAlternative.java create mode 100644 impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/Delta.java diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/AltBeanProducingPrioritizedNonAlternative.java b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/AltBeanProducingPrioritizedNonAlternative.java new file mode 100644 index 000000000..11e1a8bef --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/AltBeanProducingPrioritizedNonAlternative.java @@ -0,0 +1,24 @@ +package org.jboss.cdi.tck.tests.alternative.selection.priority; + +import jakarta.annotation.Priority; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Alternative; +import jakarta.enterprise.inject.Produces; + +@ApplicationScoped +@Alternative +@Priority(1) +public class AltBeanProducingPrioritizedNonAlternative { + + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByMethod + Delta producer1() { + return new Delta(ProducerExplicitPriorityTest.ALT2); + } + + @Priority(20) // should override class-level priority value and hence end up having the highest priority + @Produces + @ProducedByField + Delta producer2 = new Delta(ProducerExplicitPriorityTest.ALT2); +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/Delta.java b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/Delta.java new file mode 100644 index 000000000..27dcedc32 --- /dev/null +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/Delta.java @@ -0,0 +1,14 @@ +package org.jboss.cdi.tck.tests.alternative.selection.priority; + +public class Delta { + + private String s; + + public Delta(String s) { + this.s = s; + } + + public String ping() { + return s; + } +} diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/NonAltBeanProducingAlternative.java b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/NonAltBeanProducingAlternative.java index c6f539e9c..c15fbae9a 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/NonAltBeanProducingAlternative.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/NonAltBeanProducingAlternative.java @@ -50,4 +50,18 @@ Gamma producer5() { @Priority(10) Gamma producer6 = new Gamma(ProducerExplicitPriorityTest.ALT); + @Produces + @ProducedByMethod + @Alternative + @Priority(10) + Delta producer7() { + return new Delta(ProducerExplicitPriorityTest.ALT); + } + + @Produces + @ProducedByField + @Alternative + @Priority(10) + Delta producer8 = new Delta(ProducerExplicitPriorityTest.ALT); + } diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/ProducerExplicitPriorityTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/ProducerExplicitPriorityTest.java index 4c0aefbf1..8fe48b9a6 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/ProducerExplicitPriorityTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/ProducerExplicitPriorityTest.java @@ -50,6 +50,14 @@ public static WebArchive createTestArchive() { @ProducedByField Gamma gammaFieldProducer; + @Inject + @ProducedByMethod + Delta deltaMethodProducer; + + @Inject + @ProducedByField + Delta deltaFieldProducer; + @Test @SpecAssertions({@SpecAssertion(section = DECLARING_SELECTED_ALTERNATIVES_APPLICATION, id = "ca"), @@ -69,10 +77,14 @@ public void testPriorityOnProducerOverPriorityOnClass() { assertNotNull(betaFieldProducer); assertNotNull(gammaFieldProducer); assertNotNull(gammaMethodProducer); + assertNotNull(deltaFieldProducer); + assertNotNull(deltaMethodProducer); assertEquals(betaMethodProducer.ping(), ALT2); assertEquals(betaFieldProducer.ping(), ALT2); assertEquals(gammaFieldProducer.ping(), ALT2); assertEquals(gammaMethodProducer.ping(), ALT2); + assertEquals(deltaFieldProducer.ping(), ALT2); + assertEquals(deltaMethodProducer.ping(), ALT2); } } diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/RegularBeanProducer.java b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/RegularBeanProducer.java index cec48e271..ed3f2d92e 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/RegularBeanProducer.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/alternative/selection/priority/RegularBeanProducer.java @@ -36,4 +36,14 @@ Gamma producer5() { @Produces @ProducedByField Gamma producer6 = new Gamma(ProducerExplicitPriorityTest.DEFAULT); + + @Produces + @ProducedByMethod + Delta producer7() { + return new Delta(ProducerExplicitPriorityTest.DEFAULT); + } + + @Produces + @ProducedByField + Delta producer8 = new Delta(ProducerExplicitPriorityTest.DEFAULT); }