-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Find Bean Classes In Inherited '@Inject'-ed Field
Fixes #114
- Loading branch information
1 parent
4160f46
commit 96f3dbe
Showing
6 changed files
with
275 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
214 changes: 107 additions & 107 deletions
214
...oss/weld/junit5/auto/InheritanceTest.java → ...nit5/auto/AnnotationsInheritanceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,107 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.weld.junit5.auto.beans.Engine; | ||
import org.jboss.weld.junit5.auto.beans.V8; | ||
import org.jboss.weld.junit5.auto.extension.AddedExtension; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.DecoratedBean; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.InterceptedBean; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.TestDecorator; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.TestInterceptor; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests the inheritance of Annotations. | ||
*/ | ||
public class InheritanceTest { | ||
|
||
@EnableAutoWeld | ||
@AddBeanClasses(V8.class) | ||
class BaseAddBeanClassesTest { | ||
} | ||
|
||
@Nested | ||
class AddBeanClassesTest extends BaseAddBeanClassesTest { | ||
@Inject | ||
private Engine engine; | ||
|
||
@Test | ||
@DisplayName("Test that @AddBeanClasses pulls in V8 to fulfill the injected Engine interface") | ||
void test() { | ||
assertNotNull(engine); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddEnabledDecorators(TestDecorator.class) | ||
class BaseAddDecoratorTest { | ||
} | ||
|
||
@Nested | ||
class AddDecoratorTest extends BaseAddDecoratorTest { | ||
@Inject | ||
DecoratedBean bean; | ||
|
||
@Test | ||
public void testBeanIsDecorated() { | ||
Assertions.assertNotNull(bean); | ||
Assertions.assertEquals(TestDecorator.class.toString() + DecoratedBean.class.toString(), bean.ping()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddExtensions(AddedExtension.class) | ||
class BaseAddExtensionsTest { | ||
} | ||
|
||
@Nested | ||
class AddExtensionsTest extends BaseAddExtensionsTest { | ||
@Test | ||
@DisplayName("Test that @AddExtensions adds the specified extensions") | ||
void test() { | ||
assertTrue(AddedExtension.isEnabled()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddEnabledInterceptors(TestInterceptor.class) | ||
class BaseAddInterceptorTest { | ||
} | ||
|
||
@Nested | ||
class AddInterceptorTest extends BaseAddInterceptorTest { | ||
@Inject | ||
InterceptedBean bean; | ||
|
||
@Test | ||
public void testBeanIsIntercepted() { | ||
Assertions.assertNotNull(bean); | ||
Assertions.assertEquals(TestInterceptor.class.toString() + InterceptedBean.class.toString(), bean.ping()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddPackages(Engine.class) | ||
class BaseAddPackagesTest { | ||
} | ||
|
||
@Nested | ||
class AddPackagesTest extends BaseAddPackagesTest { | ||
@Inject | ||
private V8 engine; | ||
|
||
@Test | ||
@DisplayName("Test that @AddPackages pulls in V8 (without bean defining annotation) to fulfill the injected Engine interface") | ||
void test() { | ||
assertNotNull(engine); | ||
} | ||
} | ||
|
||
} | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.weld.junit5.auto.beans.Engine; | ||
import org.jboss.weld.junit5.auto.beans.V8; | ||
import org.jboss.weld.junit5.auto.extension.AddedExtension; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.DecoratedBean; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.InterceptedBean; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.TestDecorator; | ||
import org.jboss.weld.junit5.auto.interceptorAndDecorator.TestInterceptor; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Tests the inheritance of "Weld-JUnit" annotations from test parent classes. | ||
*/ | ||
public class AnnotationsInheritanceTest { | ||
|
||
@EnableAutoWeld | ||
@AddBeanClasses(V8.class) | ||
class BaseAddBeanClassesTest { | ||
} | ||
|
||
@Nested | ||
class AddBeanClassesTest extends BaseAddBeanClassesTest { | ||
@Inject | ||
private Engine engine; | ||
|
||
@Test | ||
@DisplayName("Test that @AddBeanClasses pulls in V8 to fulfill the injected Engine interface") | ||
void test() { | ||
assertNotNull(engine); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddEnabledDecorators(TestDecorator.class) | ||
class BaseAddDecoratorTest { | ||
} | ||
|
||
@Nested | ||
class AddDecoratorTest extends BaseAddDecoratorTest { | ||
@Inject | ||
DecoratedBean bean; | ||
|
||
@Test | ||
public void testBeanIsDecorated() { | ||
Assertions.assertNotNull(bean); | ||
Assertions.assertEquals(TestDecorator.class.toString() + DecoratedBean.class.toString(), bean.ping()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddExtensions(AddedExtension.class) | ||
class BaseAddExtensionsTest { | ||
} | ||
|
||
@Nested | ||
class AddExtensionsTest extends BaseAddExtensionsTest { | ||
@Test | ||
@DisplayName("Test that @AddExtensions adds the specified extensions") | ||
void test() { | ||
assertTrue(AddedExtension.isEnabled()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddEnabledInterceptors(TestInterceptor.class) | ||
class BaseAddInterceptorTest { | ||
} | ||
|
||
@Nested | ||
class AddInterceptorTest extends BaseAddInterceptorTest { | ||
@Inject | ||
InterceptedBean bean; | ||
|
||
@Test | ||
public void testBeanIsIntercepted() { | ||
Assertions.assertNotNull(bean); | ||
Assertions.assertEquals(TestInterceptor.class.toString() + InterceptedBean.class.toString(), bean.ping()); | ||
} | ||
} | ||
|
||
@EnableAutoWeld | ||
@AddPackages(Engine.class) | ||
class BaseAddPackagesTest { | ||
} | ||
|
||
@Nested | ||
class AddPackagesTest extends BaseAddPackagesTest { | ||
@Inject | ||
private V8 engine; | ||
|
||
@Test | ||
@DisplayName("Test that @AddPackages pulls in V8 (without bean defining annotation) to fulfill the injected Engine interface") | ||
void test() { | ||
assertNotNull(engine); | ||
} | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedInjectedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@EnableAutoWeld | ||
public class InheritedInjectedTest { | ||
|
||
@Dependent | ||
static class Foo { | ||
} | ||
|
||
static class BaseClass { | ||
@Inject | ||
Foo foo; | ||
} | ||
|
||
@Nested | ||
class InjectIntoInheritedFieldsFromTestBaseClassTest extends BaseClass { | ||
|
||
@Test | ||
@DisplayName("Test injected fields a test class inherits from a base class") | ||
void test() { | ||
assertNotNull(foo); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class SubClass extends BaseClass { | ||
} | ||
|
||
@Nested | ||
class InjectIntoInheritedFieldsFromBeanBaseClassTest { | ||
|
||
@Inject | ||
SubClass inheritsInjected; | ||
|
||
/** | ||
* Injection of {@link #inheritsInjected} requires {@link InheritedInjectedTest.Foo} having been identified and added as a bean class to Weld. | ||
*/ | ||
@Test | ||
@DisplayName("Test inherited injected fields") | ||
void test() { | ||
assertNotNull(inheritsInjected.foo); | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
junit5/src/test/java/org/jboss/weld/junit5/auto/InheritedProducerFieldTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.BeanManager; | ||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@EnableAutoWeld | ||
public class InheritedProducerFieldTest { | ||
|
||
@Dependent | ||
static class Foo { | ||
} | ||
|
||
static class BaseClass { | ||
@Produces | ||
Foo baseFooProducer = new Foo(); | ||
} | ||
|
||
@Nested | ||
class DontAddBeanClassesInheritedFromTestBaseClassTest extends BaseClass { | ||
@Test | ||
void test(BeanManager beanManager) { | ||
assertEquals(0, beanManager.getBeans(Foo.class).size()); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class SubClass extends BaseClass { | ||
} | ||
|
||
@Nested | ||
class DontAddBeanClassesInheritedFromBeanBaseClassTest { | ||
@Inject | ||
SubClass subClass; | ||
|
||
@Test | ||
void test(BeanManager beanManager) { | ||
assertEquals(0, beanManager.getBeans(Foo.class).size()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.