Class WireMockTestExecutionListener

java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.wiremock.spring.internal.WireMockTestExecutionListener
All Implemented Interfaces:
org.springframework.core.Ordered, org.springframework.test.context.TestExecutionListener

public class WireMockTestExecutionListener extends org.springframework.test.context.support.AbstractTestExecutionListener
Drives the same per-test WireMock behavior as WireMockSpringJunitExtension - injecting InjectWireMock fields, resetting servers between tests and configuring the default WireMock client - through the Spring TestContext framework instead of JUnit Jupiter extension callbacks.

Spring invokes TestExecutionListener regardless of which test engine drives TestContextManager (JUnit Jupiter's SpringExtension, JUnit 4's SpringJUnit4ClassRunner, TestNG's AbstractTestNGSpringContextTests, or Cucumber's cucumber-spring), so this listener, registered in META-INF/spring.factories, is what makes @InjectWireMock and automatic resets work outside of JUnit Jupiter tests too.

@InjectWireMock on a constructor or method parameter has no Spring TestContext equivalent and remains handled by WireMockSpringJunitExtension, which is a JUnit Jupiter ParameterResolver.

  • Field Summary

    Fields inherited from interface org.springframework.core.Ordered

    HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    afterTestClass(org.springframework.test.context.TestContext testContext)
     
    void
    afterTestMethod(org.springframework.test.context.TestContext testContext)
     
    void
    beforeTestMethod(org.springframework.test.context.TestContext testContext)
     
    static void
     
    void
    prepareTestInstance(org.springframework.test.context.TestContext testContext)
     

    Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

    afterTestExecution, beforeTestClass, beforeTestExecution, getOrder

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WireMockTestExecutionListener

      public WireMockTestExecutionListener()
  • Method Details

    • markContextAsDirty

      public static void markContextAsDirty()
    • prepareTestInstance

      public void prepareTestInstance(org.springframework.test.context.TestContext testContext) throws Exception
      Specified by:
      prepareTestInstance in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      prepareTestInstance in class org.springframework.test.context.support.AbstractTestExecutionListener
      Throws:
      Exception
    • beforeTestMethod

      public void beforeTestMethod(org.springframework.test.context.TestContext testContext)
      Specified by:
      beforeTestMethod in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      beforeTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListener
    • afterTestMethod

      public void afterTestMethod(org.springframework.test.context.TestContext testContext)
      Specified by:
      afterTestMethod in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      afterTestMethod in class org.springframework.test.context.support.AbstractTestExecutionListener
    • afterTestClass

      public void afterTestClass(org.springframework.test.context.TestContext testContext)
      Specified by:
      afterTestClass in interface org.springframework.test.context.TestExecutionListener
      Overrides:
      afterTestClass in class org.springframework.test.context.support.AbstractTestExecutionListener