diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryObserver.java b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryObserver.java index 240d6afb6d..7f97ba12e4 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryObserver.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryObserver.java @@ -74,8 +74,13 @@ public void observeAfterTypeDiscovery(@Observes AfterTypeDiscovery event, BeanMa } // The order of decorators reverted Collections.reverse(event.getDecorators()); - // Remove first alternative - AlphaAlternative - event.getAlternatives().remove(0); + // Remove first alternative based on index - AlphaAlternative + // There can be more alternatives in the deployment, calculate index first + for (int i = 0; i < event.getAlternatives().size(); i++) { + if (event.getAlternatives().get(i).equals(AlphaAlternative.class)) { + event.getAlternatives().remove(i); + } + } // add Baz annotatedType via AnnotatedTypeConfigurator event.addAnnotatedType(Baz.class, AfterTypeDiscoveryObserver.class.getName() + ":" + Baz.class.getName()) diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryTest.java index e5f4b7eebd..ba9e1a0fa1 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/AfterTypeDiscoveryTest.java @@ -22,6 +22,7 @@ import static org.jboss.cdi.tck.cdi.Sections.TYPE_DISCOVERY_STEPS; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import jakarta.enterprise.context.RequestScoped; @@ -44,6 +45,8 @@ import org.jboss.test.audit.annotations.SpecVersion; import org.testng.annotations.Test; +import java.util.List; + /** * @author Martin Kouba */ @@ -78,20 +81,61 @@ public void testInitialInterceptors() { @Test @SpecAssertions({ @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "b"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "ha") }) public void testInitialAlternatives() { - assertEquals(extension.getAlternatives().size(), 3); - assertEquals(extension.getAlternatives().get(0), AlphaAlternative.class); - assertEquals(extension.getAlternatives().get(1), EchoAlternative.class); - assertEquals(extension.getAlternatives().get(2), DeltaAlternative.class); + // frameworks might add their own alternatives, we cannot assert positions in list but rather just ordering + assertTrue(extension.getAlternatives().size() >= 3); + List> alternatives = extension.getAlternatives(); + Integer alphaAltIndex = null; + Integer echoAltIndex = null; + Integer deltaAltIndex = null; + for (int i = 0; i < alternatives.size(); i++) { + if (alternatives.get(i).equals(AlphaAlternative.class)) { + alphaAltIndex = i; + } + if (alternatives.get(i).equals(EchoAlternative.class)) { + echoAltIndex = i; + } + if (alternatives.get(i).equals(DeltaAlternative.class)) { + deltaAltIndex = i; + } + } + assertNotNull(alphaAltIndex); + assertNotNull(echoAltIndex); + assertNotNull(deltaAltIndex); + assertTrue(alphaAltIndex < echoAltIndex); + assertTrue(echoAltIndex < deltaAltIndex); } @Test @SpecAssertions({ @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "d"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "hc") }) public void testInitialDecorators() { - assertEquals(extension.getDecorators().size(), 4); - assertEquals(extension.getDecorators().get(0), AlphaDecorator.class); - assertEquals(extension.getDecorators().get(1), BravoDecorator.class); - assertEquals(extension.getDecorators().get(2), EchoDecorator.class); - assertEquals(extension.getDecorators().get(3), DeltaDecorator.class); + // frameworks might add their own decorators, we cannot assert positions in list but rather just ordering + assertTrue(extension.getDecorators().size() >= 4); + List> decorators = extension.getDecorators(); + Integer alphaDecIndex = null; + Integer bravoDecIndex = null; + Integer echoDecIndex = null; + Integer deltaDecIndex = null; + for (int i = 0; i < decorators.size(); i++) { + if (decorators.get(i).equals(AlphaDecorator.class)) { + alphaDecIndex = i; + } + if (decorators.get(i).equals(BravoDecorator.class)) { + bravoDecIndex = i; + } + if (decorators.get(i).equals(EchoDecorator.class)) { + echoDecIndex = i; + } + if (decorators.get(i).equals(DeltaDecorator.class)) { + deltaDecIndex = i; + } + } + assertNotNull(alphaDecIndex); + assertNotNull(bravoDecIndex); + assertNotNull(echoDecIndex); + assertNotNull(deltaDecIndex); + assertTrue(alphaDecIndex < bravoDecIndex); + assertTrue(bravoDecIndex < echoDecIndex); + assertTrue(echoDecIndex < deltaDecIndex); } @Test(dataProvider = ARQUILLIAN_DATA_PROVIDER) diff --git a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/massOperations/AfterTypeDiscoveryMassOperationsTest.java b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/massOperations/AfterTypeDiscoveryMassOperationsTest.java index 3bfba975ef..e6bf9d7bf9 100644 --- a/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/massOperations/AfterTypeDiscoveryMassOperationsTest.java +++ b/impl/src/main/java/org/jboss/cdi/tck/tests/full/extensions/lifecycle/atd/massOperations/AfterTypeDiscoveryMassOperationsTest.java @@ -19,6 +19,7 @@ import static org.jboss.cdi.tck.TestGroups.CDI_FULL; import static org.jboss.cdi.tck.cdi.Sections.AFTER_TYPE_DISCOVERY; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import jakarta.inject.Inject; @@ -37,6 +38,8 @@ import org.jboss.test.audit.annotations.SpecAssertions; import org.testng.annotations.Test; +import java.util.List; + /** * Complementary test to AfterTypeDiscoveryTest using the same classes but focusing on mass operations on List * @@ -74,10 +77,28 @@ public void testInitialInterceptors() { @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "b"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "ha") }) public void testInitialAlternatives() { - assertEquals(extension.getAlternatives().size(), 3); - assertEquals(extension.getAlternatives().get(0), AlphaAlternative.class); - assertEquals(extension.getAlternatives().get(1), BetaAlternative.class); - assertEquals(extension.getAlternatives().get(2), GammaAlternative.class); + // frameworks might add their own alternatives, we cannot assert positions in list but rather just ordering + assertTrue(extension.getAlternatives().size() >= 3); + List> alternatives = extension.getAlternatives(); + Integer alphaAltIndex = null; + Integer betaLatIndex = null; + Integer gammaAltIndex = null; + for (int i = 0; i < alternatives.size(); i++) { + if (alternatives.get(i).equals(AlphaAlternative.class)) { + alphaAltIndex = i; + } + if (alternatives.get(i).equals(BetaAlternative.class)) { + betaLatIndex = i; + } + if (alternatives.get(i).equals(GammaAlternative.class)) { + gammaAltIndex = i; + } + } + assertNotNull(alphaAltIndex); + assertNotNull(betaLatIndex); + assertNotNull(gammaAltIndex); + assertTrue(alphaAltIndex < betaLatIndex); + assertTrue(betaLatIndex < gammaAltIndex); } @Test @@ -85,10 +106,28 @@ public void testInitialAlternatives() { @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "d"), @SpecAssertion(section = AFTER_TYPE_DISCOVERY, id = "hc") }) public void testInitialDecorators() { - assertEquals(extension.getDecorators().size(), 3); - assertEquals(extension.getDecorators().get(0), AlphaDecorator.class); - assertEquals(extension.getDecorators().get(1), BetaDecorator.class); - assertEquals(extension.getDecorators().get(2), GammaDecorator.class); + // frameworks might add their own decorators, we cannot assert positions in list but rather just ordering + assertTrue(extension.getDecorators().size() >= 3); + List> decorators = extension.getDecorators(); + Integer alphaDecIndex = null; + Integer betaDecIndex = null; + Integer gammaDecIndex = null; + for (int i = 0; i < decorators.size(); i++) { + if (decorators.get(i).equals(AlphaDecorator.class)) { + alphaDecIndex = i; + } + if (decorators.get(i).equals(BetaDecorator.class)) { + betaDecIndex = i; + } + if (decorators.get(i).equals(GammaDecorator.class)) { + gammaDecIndex = i; + } + } + assertNotNull(alphaDecIndex); + assertNotNull(betaDecIndex); + assertNotNull(gammaDecIndex); + assertTrue(alphaDecIndex < betaDecIndex); + assertTrue(betaDecIndex < gammaDecIndex); } @Test(dataProvider = ARQUILLIAN_DATA_PROVIDER)