Class TestExecutionListenerLambdaAdapter

java.lang.Object
ru.vyarus.dropwizard.guice.test.jupiter.env.listen.lambda.TestExecutionListenerLambdaAdapter
All Implemented Interfaces:
TestExecutionListener

public class TestExecutionListenerLambdaAdapter extends Object implements TestExecutionListener
An adapter for TestExecutionListener to 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 Details

    • TestExecutionListenerLambdaAdapter

      public TestExecutionListenerLambdaAdapter()
  • Method Details

    • listen

      public void listen(ListenerEvent event, LambdaTestListener listener)
      Add lambda as an event listener.
      Parameters:
      event - target event
      listener - listener to add
    • starting

      public void starting(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called before dropwizard (or guicey) application starting. It could be beforeAll or beforeEach phase (if important, look ExtensionContext.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:
      starting in interface TestExecutionListener
      Parameters:
      context - context object providing access to all available objects (junit context, test support, etc.)
      Throws:
      Exception - on error
    • started

      public void started(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called when dropwizard (or guicey) application started. It could be beforeAll or beforeEach phase (if important, look ExtensionContext.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:
      started in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • beforeAll

      public void beforeAll(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      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). Prefer TestExecutionListener.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:
      beforeAll in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • beforeEach

      public void beforeEach(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called 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:
      beforeEach in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • afterEach

      public void afterEach(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called after each test method execution. Even if an application is closed on afterEach, this method would be called before it.
      Specified by:
      afterEach in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • afterAll

      public void afterAll(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      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). Prefer TestExecutionListener.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:
      afterAll in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • stopping

      public void stopping(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called before dropwizard (or guicey) application stopping. It could be afterAll or afterEach phase (if important, look ExtensionContext.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:
      stopping in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error
    • stopped

      public void stopped(EventContext context) throws Exception
      Description copied from interface: TestExecutionListener
      Called when dropwizard (or guicey) application stopped. It could be afterAll or afterEach phase (if important, look ExtensionContext.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:
      stopped in interface TestExecutionListener
      Parameters:
      context - context object providing access to all required objects (junit context, injector, test support, etc.)
      Throws:
      Exception - on error