Skip to content

Commit

Permalink
[Cdi2] Do not add step definitions to the synthetic bean archive
Browse files Browse the repository at this point in the history
Fixes: #2241
  • Loading branch information
mpkorstanje committed Feb 27, 2021
1 parent 13d4fbc commit 524837e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
run: mvn install -DskipTests=true -DskipITs=true -Darchetype.test.skip=true -Dmaven.javadoc.skip=true -B -V --toolchains .github/workflows/.toolchains.xml
- name: test
run: mvn verify -P-spotless-apply --toolchains .github/workflows/.toolchains.xml
- name: test cdi2-weld
run: cd cdi2 && mvn verify -Pcdi2-weld --toolchains ../.github/workflows/.toolchains.xml

javadoc:
name: 'Javadoc'
Expand Down
1 change: 0 additions & 1 deletion cdi2/src/main/java/io/cucumber/cdi2/Cdi2Factory.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private SeContainerInitializer getInitializer() {

@Override
public boolean addClass(final Class<?> clazz) {
getInitializer().addBeanClasses(clazz);
return true;
}

Expand Down
35 changes: 27 additions & 8 deletions cdi2/src/test/java/io/cucumber/cdi2/Cdi2FactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Vetoed;
import javax.inject.Inject;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
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 Cdi2FactoryTest {

Expand Down Expand Up @@ -56,26 +56,45 @@ static class ApplicationScopedBean {
void shouldCreateApplicationScopedInstance() {
factory.addClass(ApplicationScopedBean.class);
factory.start();
ApplicationScopedBean cdiStep = factory.getInstance(ApplicationScopedBean.class);
ApplicationScopedBean bean = factory.getInstance(ApplicationScopedBean.class);
assertAll(
// assert that it is is a CDI proxy
() -> assertThat(cdiStep.getClass(), not(is(ApplicationScopedBean.class))),
() -> assertThat(cdiStep.getClass().getSuperclass(), is(ApplicationScopedBean.class)));
() -> assertThat(bean.getClass(), not(is(ApplicationScopedBean.class))),
() -> assertThat(bean.getClass().getSuperclass(), is(ApplicationScopedBean.class)));
factory.stop();
}

static class UnmanagedBean {

}

@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));
UnmanagedBean bean = factory.getInstance(UnmanagedBean.class);
assertThat(bean.getClass(), is(UnmanagedBean.class));
factory.stop();
}

static class UnmanagedBean {
static class OtherStepDefinitions {

}

static class StepDefinitions {

@Inject
OtherStepDefinitions injected;

}

@Test
void shouldInjectUnmanagedInstance() {
factory.addClass(StepDefinitions.class);
factory.start();
StepDefinitions stepDefinitions = factory.getInstance(StepDefinitions.class);
assertThat(stepDefinitions.injected, is(notNullValue()));
factory.stop();
}

}

0 comments on commit 524837e

Please sign in to comment.