Class LogTestSupport

java.lang.Object
net.officefloor.frame.test.LogTestSupport
All Implemented Interfaces:
TestSupport, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension

public class LogTestSupport extends Object implements TestSupport, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
Test support for logging.
Author:
Daniel Sagenschneider
  • Constructor Details

    • LogTestSupport

      public LogTestSupport()
      Default instantiate for use as ExtensionContext.
  • Method Details

    • init

      public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Description copied from interface: TestSupport
      Intialise.
      Specified by:
      init in interface TestSupport
      Parameters:
      context - ExtensionContext.
      Throws:
      Exception - If fails to init.
    • setVerbose

      public void setVerbose(boolean isVerbose)
      Specifies to provide verbose output to aid in debugging.
      Parameters:
      isVerbose - true to turn on verbose output.
    • setDebugVerbose

      public void setDebugVerbose()
      Specifies to provide debug verbose output to aid in debugging.
    • setLogGC

      public void setLogGC()
      Turns on logging of GC as part of test.
    • captureStdOutErr

      public <T extends Throwable> String captureStdOutErr(LogTestSupport.TestCapture<T> test) throws T
      Capture std out/err of test logic.
      Type Parameters:
      T - Possible Exception type.
      Parameters:
      test - Test logic to capture std err.
      Returns:
      std out/err output.
      Throws:
      T - Possible Throwable.
    • captureLoggerOutput

      public <T extends Throwable> String captureLoggerOutput(LogTestSupport.TestCapture<T> test) throws T
      Capture Logger output of test logic.
      Type Parameters:
      T - Possible Exception type.
      Parameters:
      test - Test logic to capture std err.
      Returns:
      Logger output.
      Throws:
      T - Possible Throwable.
    • isPrintMessages

      protected boolean isPrintMessages()
      Determines if printing messages.
      Returns:
      true to print messages.
    • printHeapMemoryDiagnostics

      public void printHeapMemoryDiagnostics()
      Prints heap memory details.
    • getDisplayRunTime

      public String getDisplayRunTime(long startTime)
      Obtains run time in human readable form.
      Parameters:
      startTime - Start time of running.
      Returns:
      Run time in human readable form.
    • getDisplayRunTime

      public String getDisplayRunTime(long startTime, long endTime)
      Obtains run time in human readable form.
      Parameters:
      startTime - Start time of running.
      endTime - End time of running.
      Returns:
      Run time in human readable form.
    • printMessage

      public void printMessage(String message)
      Prints a message regarding the test.
      Parameters:
      message - Message to be printed.
    • printMessage

      public void printMessage(InputStream message) throws IOException
      Prints a message regarding the test.
      Parameters:
      message - Message to be printed.
      Throws:
      IOException - If fails to print message.
    • printMessage

      public void printMessage(Reader message) throws IOException
      Prints a message regarding the test.
      Parameters:
      message - Message to be printed.
      Throws:
      IOException - If fails to print message.
    • displayGraph

      public void displayGraph(Object root) throws Exception
      Displays the graph of objects starting at root.
      Parameters:
      root - Root of graph to display.
      Throws:
      Exception - If fails.
    • displayGraph

      public void displayGraph(Object root, String... ignoreMethodNames) throws Exception
      Displays the graph of objects starting at root ignoring following verticies by the input method names.
      Parameters:
      root - Root of graph to display.
      ignoreMethodNames - Method names to ignore.
      Throws:
      Exception - If fails.
    • beforeAll

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • beforeAll

      public void beforeAll() throws Exception
      BeforeAllCallback logic.
      Throws:
      Exception - If fails.
    • afterAll

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • afterAll

      public void afterAll() throws Exception
      AfterAllCallback logic.
      Throws:
      Exception - If fails.