Class TestExtension
TestEnvironmentSetup objects.- Since:
- 15.05.2022
-
Field Summary
Fields inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.conf.ExtensionBuilder
cfg -
Constructor Summary
ConstructorsConstructorDescriptionTestExtension(ExtensionConfig cfg, org.junit.jupiter.api.extension.ExtensionContext context, ListenersSupport listeners) Create extension. -
Method Summary
Modifier and TypeMethodDescription<A extends Annotation,T>
List<AnnotatedField<A,T>> findAnnotatedFields(Class<A> annotation, Class<T> requiredFieldType) Search for annotated fields with validation (a field type must be assignable to provided type).org.junit.jupiter.api.extension.ExtensionContextThis might be class or method context ("before all" or "before each"), depending on how guicey extension would be registered: in case of registration with a non-static field "before all" not called.booleanShortcut to simplify detection on what phase extension was created: beforeAll or beforeEach.booleanisDebug()Useful to bind debug options on the extension debug (no need for additional keys).listen(TestExecutionListener listener) Listen for test lifecycle.onAfterAll(LambdaTestListener listener) onAfterEach(LambdaTestListener listener) onApplicationStart(LambdaTestListener listener) onApplicationStarting(LambdaTestListener listener) onApplicationStop(LambdaTestListener listener) onApplicationStopping(LambdaTestListener listener) onBeforeAll(LambdaTestListener listener) onBeforeEach(LambdaTestListener listener) Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.conf.ExtensionBuilder
apacheClient, clientFactory, config, configModifiers, configModifiers, configOverride, configOverride, configOverrideByExtension, configOverrideByExtension, configOverrides, configOverrides, debug, disableDefaultExtensions, hooks, hooks, injectOnce, reuseApplication, with
-
Constructor Details
-
TestExtension
public TestExtension(ExtensionConfig cfg, org.junit.jupiter.api.extension.ExtensionContext context, ListenersSupport listeners) Create extension.- Parameters:
cfg- configcontext- junit contextlisteners- listeners support
-
-
Method Details
-
isDebug
public boolean isDebug()Useful to bind debug options on the extension debug (no need for additional keys).- Returns:
- true if debug is enabled on guicey extension
-
isApplicationStartedForClass
public boolean isApplicationStartedForClass()Shortcut to simplify detection on what phase extension was created: beforeAll or beforeEach.- Returns:
- true if application started once per test class, false if application started for each test method
-
getJunitContext
public org.junit.jupiter.api.extension.ExtensionContext getJunitContext()This might be class or method context ("before all" or "before each"), depending on how guicey extension would be registered: in case of registration with a non-static field "before all" not called.Note that guicey provide static method for accessing objects, stored in context, like:
GuiceyExtensionsSupport.lookupSupport(org.junit.jupiter.api.extension.ExtensionContext)orGuiceyExtensionsSupport.lookupInjector(org.junit.jupiter.api.extension.ExtensionContext).- Returns:
- test extension context
-
listen
Listen for test lifecycle. Useful when not only resource close is required (achievable by returning a closable object from setup), but writing a separate junit extension is not desirable. Moreover, this listener is synchronized with guicey extension lifecycle.Listener could also be registered with lambdas using on* methods like
onApplicationStart(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.lambda.LambdaTestListener). Lambda version might be more convenient in case when setup object is a lambda itself.- Parameters:
listener- listener object- Returns:
- builder instance for chained calls
-
onApplicationStarting
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.starting(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before application start (could be beforeAll (default) or beforeEach phase)- Returns:
- builder instance for chained calls
-
onApplicationStart
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.started(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after application start (could be beforeAll (default) or beforeEach phase)- Returns:
- builder instance for chained calls
-
onBeforeAll
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.beforeAll(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called (might not be called!) before all test methods- Returns:
- builder instance for chained calls
-
onBeforeEach
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.beforeEach(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before each test method- Returns:
- builder instance for chained calls
-
onAfterEach
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.afterEach(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after each test method- Returns:
- builder instance for chained calls
-
onAfterAll
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.afterAll(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called (might not be called!) after all test methods- Returns:
- builder instance for chained calls
-
onApplicationStopping
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.stopping(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before application stop (could be afterAll (default) or afterEach phase)- Returns:
- builder instance for chained calls
-
onApplicationStop
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.stopped(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after application stop (could be afterAll (default) or afterEach phase)- Returns:
- builder instance for chained calls
-
findAnnotatedFields
public <A extends Annotation,T> List<AnnotatedField<A,T>> findAnnotatedFields(Class<A> annotation, Class<T> requiredFieldType) Search for annotated fields with validation (a field type must be assignable to provided type).- Type Parameters:
A- annotation typeT- required filed minimal type- Parameters:
annotation- annotation to searchrequiredFieldType- required field type- Returns:
- annotated test fields (including fields from base test class).
-