|
5 | 5 |
|
6 | 6 | import javax.enterprise.context.ApplicationScoped;
|
7 | 7 | import javax.enterprise.inject.Vetoed;
|
| 8 | +import javax.inject.Inject; |
8 | 9 |
|
9 | 10 | import static org.hamcrest.MatcherAssert.assertThat;
|
10 | 11 | import static org.hamcrest.core.Is.is;
|
11 | 12 | import static org.hamcrest.core.IsEqual.equalTo;
|
12 | 13 | import static org.hamcrest.core.IsNot.not;
|
13 | 14 | import static org.hamcrest.core.IsNull.notNullValue;
|
14 | 15 | import static org.junit.jupiter.api.Assertions.assertAll;
|
15 |
| -import static org.junit.jupiter.api.Assertions.assertNotNull; |
16 | 16 |
|
17 | 17 | class Cdi2FactoryTest {
|
18 | 18 |
|
@@ -56,26 +56,45 @@ static class ApplicationScopedBean {
|
56 | 56 | void shouldCreateApplicationScopedInstance() {
|
57 | 57 | factory.addClass(ApplicationScopedBean.class);
|
58 | 58 | factory.start();
|
59 |
| - ApplicationScopedBean cdiStep = factory.getInstance(ApplicationScopedBean.class); |
| 59 | + ApplicationScopedBean bean = factory.getInstance(ApplicationScopedBean.class); |
60 | 60 | assertAll(
|
61 | 61 | // assert that it is is a CDI proxy
|
62 |
| - () -> assertThat(cdiStep.getClass(), not(is(ApplicationScopedBean.class))), |
63 |
| - () -> assertThat(cdiStep.getClass().getSuperclass(), is(ApplicationScopedBean.class))); |
| 62 | + () -> assertThat(bean.getClass(), not(is(ApplicationScopedBean.class))), |
| 63 | + () -> assertThat(bean.getClass().getSuperclass(), is(ApplicationScopedBean.class))); |
64 | 64 | factory.stop();
|
65 | 65 | }
|
66 | 66 |
|
| 67 | + static class UnmanagedBean { |
| 68 | + |
| 69 | + } |
| 70 | + |
67 | 71 | @Test
|
68 | 72 | void shouldCreateUnmanagedInstance() {
|
69 | 73 | factory.addClass(UnmanagedBean.class);
|
70 | 74 | factory.start();
|
71 |
| - assertNotNull(factory.getInstance(UnmanagedBean.class)); |
72 |
| - UnmanagedBean cdiStep = factory.getInstance(UnmanagedBean.class); |
73 |
| - assertThat(cdiStep.getClass(), is(UnmanagedBean.class)); |
| 75 | + UnmanagedBean bean = factory.getInstance(UnmanagedBean.class); |
| 76 | + assertThat(bean.getClass(), is(UnmanagedBean.class)); |
74 | 77 | factory.stop();
|
75 | 78 | }
|
76 | 79 |
|
77 |
| - static class UnmanagedBean { |
| 80 | + static class OtherStepDefinitions { |
| 81 | + |
| 82 | + } |
78 | 83 |
|
| 84 | + static class StepDefinitions { |
| 85 | + |
| 86 | + @Inject |
| 87 | + OtherStepDefinitions injected; |
| 88 | + |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + void shouldInjectUnmanagedInstance() { |
| 93 | + factory.addClass(StepDefinitions.class); |
| 94 | + factory.start(); |
| 95 | + StepDefinitions stepDefinitions = factory.getInstance(StepDefinitions.class); |
| 96 | + assertThat(stepDefinitions.injected, is(notNullValue())); |
| 97 | + factory.stop(); |
79 | 98 | }
|
80 | 99 |
|
81 | 100 | }
|
0 commit comments