Package org.jboss.weld.junit5
Class WeldJunit5Extension
- java.lang.Object
-
- org.jboss.weld.junit5.WeldJunit5Extension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.AfterEachCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
- Direct Known Subclasses:
WeldJunit5AutoExtension
public class WeldJunit5Extension extends Object implements org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.ParameterResolver
JUnit 5 extension allowing to bootstrap Weld SE container for each @Test method (or per once per test class if runningTestInstance.Lifecycle.PER_CLASS
) and tear it down afterwards. Also allows to inject CDI beans as parameters to @Test methods and resolves all @Inject fields in test class.If no
WeldInitiator
field annotated withWeldSetup
is present on a test class, all service providers ofWeldJunitEnricher
interface are used to enrich the default test environment.@ExtendWith(WeldJunit5Extension.class) public class SimpleTest { // Injected automatically @Inject Foo foo; @Test public void testFoo() { // Weld container is started automatically assertEquals("baz", foo.getBaz()); } }
- Author:
- Matej Novotny
- See Also:
EnableWeld
,WeldJunitEnricher
-
-
Field Summary
Fields Modifier and Type Field Description static String
GLOBAL_EXPLICIT_PARAM_INJECTION
-
Constructor Summary
Constructors Constructor Description WeldJunit5Extension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
void
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
void
beforeEach(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Object
resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
boolean
supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
protected void
weldInit(org.junit.jupiter.api.extension.ExtensionContext context, org.jboss.weld.environment.se.Weld weld, WeldInitiator.Builder weldInitiatorBuilder)
-
-
-
Field Detail
-
GLOBAL_EXPLICIT_PARAM_INJECTION
public static final String GLOBAL_EXPLICIT_PARAM_INJECTION
- See Also:
- Constant Field Values
-
-
Method Detail
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
- Specified by:
afterAll
in interfaceorg.junit.jupiter.api.extension.AfterAllCallback
- Throws:
Exception
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
- Specified by:
afterEach
in interfaceorg.junit.jupiter.api.extension.AfterEachCallback
- Throws:
Exception
-
weldInit
protected void weldInit(org.junit.jupiter.api.extension.ExtensionContext context, org.jboss.weld.environment.se.Weld weld, WeldInitiator.Builder weldInitiatorBuilder)
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
- Specified by:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException
- Specified by:
supportsParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
-