Class MockitoCleanupListener

java.lang.Object
org.apache.pulsar.tests.MockitoCleanupListener
All Implemented Interfaces:
org.testng.IClassListener, org.testng.ITestListener, org.testng.ITestNGListener

public class MockitoCleanupListener extends Object
Cleanup Mockito's Thread Local state that leaks memory Mockito.reset method should be called at the end of a test in the same thread where the methods were mocked/stubbed. There are some tests which mock methods in the ForkJoinPool thread and these leak memory. This listener doesn't support parallel execution at TestNG level. This is not thread safe. Separate forks testForkCount > 1 controlled with Maven Surefire is the recommended solution for parallel test execution and that is fine.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    onBeforeClass(org.testng.ITestClass testClass)
     
    protected void
    onBetweenTestClasses(Class<?> endedTestClass, Class<?> startedTestClass)
    Call back hook for adding logic when test execution moves from test class to another.
    void
    onFinish(org.testng.ITestContext context)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.testng.IClassListener

    onAfterClass

    Methods inherited from interface org.testng.ITestListener

    onStart, onTestFailedButWithinSuccessPercentage, onTestFailedWithTimeout, onTestFailure, onTestSkipped, onTestStart, onTestSuccess
  • Constructor Details

    • MockitoCleanupListener

      public MockitoCleanupListener()
  • Method Details

    • onBetweenTestClasses

      protected void onBetweenTestClasses(Class<?> endedTestClass, Class<?> startedTestClass)
      Call back hook for adding logic when test execution moves from test class to another.
      Parameters:
      endedTestClass - the test class which has finished execution. null if the started test class is the first
      startedTestClass - the test class which has started execution. null if the ended test class is the last
    • onBeforeClass

      public void onBeforeClass(org.testng.ITestClass testClass)
      Specified by:
      onBeforeClass in interface org.testng.IClassListener
    • onFinish

      public void onFinish(org.testng.ITestContext context)
      Specified by:
      onFinish in interface org.testng.ITestListener