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 10, 2023
1 parent 434fe89 commit ffa1f82
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 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);
}

0 comments on commit ffa1f82

Please sign in to comment.