Class TestExecutionListenerLambdaAdapter
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.jupiter.env.listen.lambda.TestExecutionListenerLambdaAdapter
-
- All Implemented Interfaces:
TestExecutionListener
public class TestExecutionListenerLambdaAdapter extends java.lang.Object implements TestExecutionListener
An adapter forTestExecutionListenerto be able to register each listener method with a lambada (more suitable for builder style, rather than direct interface implementation).- Since:
- 20.02.2025
-
-
Constructor Summary
Constructors Constructor Description TestExecutionListenerLambdaAdapter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAll(EventContext context)IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so the application is stopped after each method).voidafterEach(EventContext context)Called after each test method execution.voidbeforeAll(EventContext context)IMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so application created before each method).voidbeforeEach(EventContext context)Called before each test method execution.voidlisten(ListenerEvent event, LambdaTestListener listener)Add lambda as an event listener.voidstarted(EventContext context)Called when dropwizard (or guicey) application started.voidstarting(EventContext context)Called before dropwizard (or guicey) application starting.voidstopped(EventContext context)Called when dropwizard (or guicey) application stopped.voidstopping(EventContext context)Called before dropwizard (or guicey) application stopping.
-
-
-
Method Detail
-
listen
public void listen(ListenerEvent event, LambdaTestListener listener)
Add lambda as an event listener.- Parameters:
event- target eventlistener- listener to add
-
starting
public void starting(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled before dropwizard (or guicey) application starting. It could be beforeAll or beforeEach phase (if important, lookExtensionContext.getTestMethod()to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).NOTE: At this stage, injections not yet performed inside test instance.
This method could be used instead of beforeAll because normally extension is created under beforeAll, but for extensions created under beforeEach - it would be impossible to notify about beforeAll anyway.
- Specified by:
startingin interfaceTestExecutionListener- Parameters:
context- context object providing access to all available objects (junit context, test support, etc.)- Throws:
java.lang.Exception- on error
-
started
public void started(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled when dropwizard (or guicey) application started. It could be beforeAll or beforeEach phase (if important, lookExtensionContext.getTestMethod()to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).NOTE: At this stage, injections not yet performed inside test instance.
This method could be used instead of beforeAll because normally extension is created under beforeAll, but for extensions created under beforeEach - it would be impossible to notify about beforeAll anyway.
- Specified by:
startedin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
beforeAll
public void beforeAll(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerIMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so application created before each method). PreferTestExecutionListener.started(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext)instead, which is always called (but not always under beforeAll),Method could be useful if some action must be performed before each test (in case of nested tests or global application when "start" would not be called for each test).
- Specified by:
beforeAllin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
beforeEach
public void beforeEach(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled before each test method execution. Guice injections into test instance already performed. Even if an application is created in beforeEach phase, this method would be called after application creation.- Specified by:
beforeEachin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
afterEach
public void afterEach(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled after each test method execution. Even if an application is closed on afterEach, this method would be called before it.- Specified by:
afterEachin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
afterAll
public void afterAll(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerIMPORTANT: this method MIGHT NOT BE CALLED at all in case if extension is registered under non-static field (and so the application is stopped after each method). PreferTestExecutionListener.stopped(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext)instead, which is always called (but not always under afterAll),Method could be useful if some action must be performed after each test (in case of nested tests or global application when "stop" would not be called for each test).
- Specified by:
afterAllin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
stopping
public void stopping(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled before dropwizard (or guicey) application stopping. It could be afterAll or afterEach phase (if important, lookExtensionContext.getTestMethod()to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).Note that in case of global application usage or for nested tests this method might not be called because application lifecycle would be managed by the top-most test.
This method could be used instead of afterAll because normally extension is stopped under afterAll, but for extensions stopped under afterEach - it would be impossible to notify about afterAll anyway.
- Specified by:
stoppingin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
stopped
public void stopped(EventContext context) throws java.lang.Exception
Description copied from interface:TestExecutionListenerCalled when dropwizard (or guicey) application stopped. It could be afterAll or afterEach phase (if important, lookExtensionContext.getTestMethod()to make sure). Application could start/stop multiple times within one test class (if extension registered in non-static field).Note that in case of global application usage or for nested tests this method might not be called because application lifecycle would be managed by the top-most test.
This method could be used instead of afterAll because normally extension is stopped under afterAll, but for extensions stopped under afterEach - it would be impossible to notify about afterAll anyway.
- Specified by:
stoppedin interfaceTestExecutionListener- Parameters:
context- context object providing access to all required objects (junit context, injector, test support, etc.)- Throws:
java.lang.Exception- on error
-
-