diff --git a/CHANGELOG.md b/CHANGELOG.md index 7643ae7f74..da8d9144f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed * [Cdi2] Correctly cast the UnmanagedInstance values ([#2242](https://github.com/cucumber/cucumber-jvm/pull/2242), [#2244](https://github.com/cucumber/cucumber-jvm/pull/2244) Daniel Beland) + * [Jakarta Cdi] Correctly cast the UnmanagedInstance values ([#2242](https://github.com/cucumber/cucumber-jvm/pull/2242), [#2248](https://github.com/cucumber/cucumber-jvm/pull/2248) Daniel Beland) ## [6.10.0] (2021-02-14) diff --git a/jakarta-cdi/README.md b/jakarta-cdi/README.md index 0fac628bab..6ed6920a1a 100644 --- a/jakarta-cdi/README.md +++ b/jakarta-cdi/README.md @@ -73,7 +73,7 @@ And for Weld it is: org.jboss.weld.se weld-se-core - 4.0.0.Alpha2 + 4.0.0 test ``` @@ -85,13 +85,13 @@ If you don't know which one to use, you can import the following one but if you jakarta.enterprise jakarta.enterprise.cdi-api - 3.0.0-M3 + 3.0.0 provided jakarta.activation jakarta.activation-api - 2.0.0-RC3 + 2.0.0 provided ``` diff --git a/jakarta-cdi/pom.xml b/jakarta-cdi/pom.xml index 6776697452..b53eb2d12a 100644 --- a/jakarta-cdi/pom.xml +++ b/jakarta-cdi/pom.xml @@ -4,9 +4,9 @@ io.cucumber.cdi.jakarta 2.0.21 - 3.0.0-M3 + 3.0.0 2.0.0 - 4.18 + 4.0.0.Final @@ -41,58 +41,6 @@ ${jakarta.activation-api.version} provided - - - org.apache.xbean - xbean-finder-shaded - ${xbean.version} - test - - - org.apache.xbean - xbean-asm9-shaded - ${xbean.version} - test - - - org.apache.openwebbeans - openwebbeans-impl - ${openwebbeans.version} - test - jakarta - - - * - * - - - - - org.apache.openwebbeans - openwebbeans-spi - ${openwebbeans.version} - test - jakarta - - - * - * - - - - - org.apache.openwebbeans - openwebbeans-se - ${openwebbeans.version} - jakarta - test - - - * - * - - - io.cucumber cucumber-java @@ -100,7 +48,7 @@ io.cucumber - cucumber-junit + cucumber-junit-platform-engine test @@ -109,9 +57,92 @@ test - org.junit.vintage - junit-vintage-engine + org.hamcrest + hamcrest-core test + + + + jakarta-cdi-openwebbeans + + true + + + 4.18 + + + + org.apache.openwebbeans + openwebbeans-se + ${openwebbeans.version} + jakarta + test + + + * + * + + + + + org.apache.openwebbeans + openwebbeans-impl + ${openwebbeans.version} + test + jakarta + + + * + * + + + + + org.apache.openwebbeans + openwebbeans-spi + ${openwebbeans.version} + test + jakarta + + + * + * + + + + + org.apache.xbean + xbean-finder-shaded + ${xbean.version} + test + + + org.apache.xbean + xbean-asm9-shaded + ${xbean.version} + test + + + + + + jakarta-cdi-weld + + + org.jboss.weld.se + weld-se-core + ${weld.version} + test + + + org.jboss.weld + weld-core-impl + ${weld.version} + test + + + + diff --git a/jakarta-cdi/src/main/java/io/cucumber/jakarta/cdi/CdiJakartaFactory.java b/jakarta-cdi/src/main/java/io/cucumber/jakarta/cdi/CdiJakartaFactory.java index 772612d2a9..47e426369d 100644 --- a/jakarta-cdi/src/main/java/io/cucumber/jakarta/cdi/CdiJakartaFactory.java +++ b/jakarta-cdi/src/main/java/io/cucumber/jakarta/cdi/CdiJakartaFactory.java @@ -52,9 +52,9 @@ public boolean addClass(final Class clazz) { @Override public T getInstance(final Class type) { - final Object instance = standaloneInstances.get(type); + final Unmanaged.UnmanagedInstance instance = standaloneInstances.get(type); if (instance != null) { - return type.cast(instance); + return type.cast(instance.get()); } final Instance selected = container.select(type); if (selected.isUnsatisfied()) { @@ -69,5 +69,4 @@ public T getInstance(final Class type) { } return selected.get(); } - } diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/BellyStepDefinitions.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/BellyStepDefinitions.java deleted file mode 100644 index fbfc3b233a..0000000000 --- a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/BellyStepDefinitions.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.cucumber.jakarta.cdi; - -import io.cucumber.java.en.Given; -import jakarta.enterprise.inject.Vetoed; -import jakarta.inject.Inject; - -@Vetoed -public class BellyStepDefinitions { - - @Inject - private Belly belly; - - @Given("I have {int} cukes in my belly") - public void haveCukes(int n) { - belly.setCukes(n); - } - -} diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiBellyStepDefinitions.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiBellyStepDefinitions.java deleted file mode 100644 index 5af96bddd7..0000000000 --- a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiBellyStepDefinitions.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.cucumber.jakarta.cdi; - -import io.cucumber.java.en.Then; -import jakarta.enterprise.context.ApplicationScoped; -import jakarta.inject.Inject; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@ApplicationScoped -public class CdiBellyStepDefinitions { - - @Inject - private Belly belly; - - @Then("there are {int} cukes in my belly") - public void checkCukes(int n) { - assertEquals(n, belly.getCukes()); - } - -} diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiJakartaFactoryTest.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiJakartaFactoryTest.java index 11b9206b90..4d85870210 100644 --- a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiJakartaFactoryTest.java +++ b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/CdiJakartaFactoryTest.java @@ -1,6 +1,8 @@ package io.cucumber.jakarta.cdi; import io.cucumber.core.backend.ObjectFactory; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Vetoed; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -9,35 +11,69 @@ import static org.hamcrest.core.IsNot.not; import static org.hamcrest.core.IsNull.notNullValue; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertNotNull; class CdiJakartaFactoryTest { - @Test - void shouldGiveUsNewInstancesForEachScenario() { + final ObjectFactory factory = new CdiJakartaFactory(); + + @Vetoed + static class VetoedBean { + + } - final ObjectFactory factory = new CdiJakartaFactory(); - factory.addClass(BellyStepDefinitions.class); - factory.addClass(CdiBellyStepDefinitions.class); + @Test + void shouldCreateNewInstancesForEachScenario() { + factory.addClass(VetoedBean.class); // Scenario 1 factory.start(); - final BellyStepDefinitions o1 = factory.getInstance(BellyStepDefinitions.class); - final CdiBellyStepDefinitions cdiStep = factory.getInstance(CdiBellyStepDefinitions.class); - assertAll( - // assert that it is is a CDI proxy - () -> assertThat(cdiStep.getClass(), not(is(CdiBellyStepDefinitions.class))), - () -> assertThat(cdiStep.getClass().getSuperclass(), is(CdiBellyStepDefinitions.class))); + VetoedBean a1 = factory.getInstance(VetoedBean.class); + VetoedBean a2 = factory.getInstance(VetoedBean.class); + assertThat(a1, is(equalTo(a2))); factory.stop(); // Scenario 2 factory.start(); - final BellyStepDefinitions o2 = factory.getInstance(BellyStepDefinitions.class); + VetoedBean b1 = factory.getInstance(VetoedBean.class); factory.stop(); + // VetoedBean makes it possible to compare the object outside the + // scenario/application scope + assertAll( + () -> assertThat(a1, is(notNullValue())), + () -> assertThat(a1, is(not(equalTo(b1)))), + () -> assertThat(b1, is(not(equalTo(a1))))); + } + + @ApplicationScoped + static class ApplicationScopedBean { + + } + + @Test + void shouldCreateApplicationScopedInstance() { + factory.addClass(ApplicationScopedBean.class); + factory.start(); + ApplicationScopedBean cdiStep = factory.getInstance(ApplicationScopedBean.class); assertAll( - () -> assertThat(o1, is(notNullValue())), - () -> assertThat(o1, is(not(equalTo(o2)))), - () -> assertThat(o2, is(not(equalTo(o1))))); + // assert that it is is a CDI proxy + () -> assertThat(cdiStep.getClass(), not(is(ApplicationScopedBean.class))), + () -> assertThat(cdiStep.getClass().getSuperclass(), is(ApplicationScopedBean.class))); + factory.stop(); } + @Test + void shouldCreateUnmanagedInstance() { + factory.addClass(UnmanagedBean.class); + factory.start(); + assertNotNull(factory.getInstance(UnmanagedBean.class)); + UnmanagedBean cdiStep = factory.getInstance(UnmanagedBean.class); + assertThat(cdiStep.getClass(), is(UnmanagedBean.class)); + factory.stop(); + } + + static class UnmanagedBean { + + } } diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/RunCucumberTest.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/RunCucumberTest.java deleted file mode 100644 index 4380de705e..0000000000 --- a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/RunCucumberTest.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.cucumber.jakarta.cdi; - -import io.cucumber.junit.Cucumber; -import org.junit.runner.RunWith; - -@RunWith(Cucumber.class) -public class RunCucumberTest { - -} diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/Belly.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/Belly.java similarity index 86% rename from jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/Belly.java rename to jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/Belly.java index d9198ba9bc..bcacc0dc79 100644 --- a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/Belly.java +++ b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/Belly.java @@ -1,4 +1,4 @@ -package io.cucumber.jakarta.cdi; +package io.cucumber.jakarta.cdi.example; import jakarta.enterprise.context.ApplicationScoped; diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/BellyStepDefinitions.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/BellyStepDefinitions.java new file mode 100644 index 0000000000..a723019520 --- /dev/null +++ b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/BellyStepDefinitions.java @@ -0,0 +1,31 @@ +package io.cucumber.jakarta.cdi.example; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import jakarta.enterprise.inject.Vetoed; +import jakarta.inject.Inject; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@Vetoed +public class BellyStepDefinitions { + + @Inject + private Belly belly; + + @Given("I have {int} cukes in my belly") + public void haveCukes(int n) { + belly.setCukes(n); + } + + @Given("I eat {int} more cukes") + public void addCukes(int n) { + belly.setCukes(belly.getCukes() + n); + } + + @Then("there are {int} cukes in my belly") + public void checkCukes(int n) { + assertEquals(n, belly.getCukes()); + } + +} diff --git a/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/RunCucumberTest.java b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/RunCucumberTest.java new file mode 100644 index 0000000000..45af5192cc --- /dev/null +++ b/jakarta-cdi/src/test/java/io/cucumber/jakarta/cdi/example/RunCucumberTest.java @@ -0,0 +1,8 @@ +package io.cucumber.jakarta.cdi.example; + +import io.cucumber.junit.platform.engine.Cucumber; + +@Cucumber +public class RunCucumberTest { + +} diff --git a/jakarta-cdi/src/test/resources/META-INF/beans.xml b/jakarta-cdi/src/test/resources/META-INF/beans.xml index 8b70ee6426..ea3cf1c048 100644 --- a/jakarta-cdi/src/test/resources/META-INF/beans.xml +++ b/jakarta-cdi/src/test/resources/META-INF/beans.xml @@ -3,5 +3,9 @@ xsi:schemaLocation=" http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> - + + + + diff --git a/jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/cukes.feature b/jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/example/cukes.feature similarity index 74% rename from jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/cukes.feature rename to jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/example/cukes.feature index 385e001c89..a065e7eaed 100644 --- a/jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/cukes.feature +++ b/jakarta-cdi/src/test/resources/io/cucumber/jakarta/cdi/example/cukes.feature @@ -6,4 +6,5 @@ Feature: Cukes Scenario: Eat some more cukes Given I have 6 cukes in my belly - Then there are 6 cukes in my belly \ No newline at end of file + And I eat 2 more cukes + Then there are 8 cukes in my belly