Skip to content

Commit

Permalink
Add coverage for case where alternative bean contains non-alternative…
Browse files Browse the repository at this point in the history
… producer declaring its own priority
  • Loading branch information
manovotn committed Nov 28, 2023
1 parent 434fe89 commit a643b16
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions impl/src/main/resources/tck-audit-cdi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2242,8 +2242,8 @@
</group>

<group>
<text>To determine the priority of a producer method or field, the |@Priority| annotation on the producer method or field is considered first.
If the producer method or field does not declare the |@Priority| annotation, the |@Priority| annotation declared on the bean class is used.</text>
<text>For the purpose of determining the priority of any producer method or field during ambiguity resolution, the priority of the producer method or field is considered first.
If the producer method or field does not have a priority, the priority of the managed bean that declares the producer method or field is used.</text>
<assertion id="dd">
<text>Test |@Priority| declared directly on producer is considered first.</text>
</assertion>
Expand Down
4 changes: 2 additions & 2 deletions web/src/main/resources/tck-audit-cdi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2228,8 +2228,8 @@
</group>

<group>
<text>To determine the priority of a producer method or field, the |@Priority| annotation on the producer method or field is considered first.
If the producer method or field does not declare the |@Priority| annotation, the |@Priority| annotation declared on the bean class is used.</text>
<text>For the purpose of determining the priority of any producer method or field during ambiguity resolution, the priority of the producer method or field is considered first.
If the producer method or field does not have a priority, the priority of the managed bean that declares the producer method or field is used.</text>
<assertion id="dd">
<text>Test |@Priority| declared directly on producer is considered first.</text>
</assertion>
Expand Down

0 comments on commit a643b16

Please sign in to comment.