Class 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 java.lang.Object
    implements TestSupport, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
    Test support for logging.
    Author:
    Daniel Sagenschneider
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  LogTestSupport.TestCapture<T extends java.lang.Throwable>
      Test capture interface.
    • Constructor Summary

      Constructors 
      Constructor Description
      LogTestSupport()
      Default instantiate for use as ExtensionContext.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterAll()
      AfterAllCallback logic.
      void afterAll​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void beforeAll()
      BeforeAllCallback logic.
      void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)  
      <T extends java.lang.Throwable>
      java.lang.String
      captureLoggerOutput​(LogTestSupport.TestCapture<T> test)
      Capture Logger output of test logic.
      <T extends java.lang.Throwable>
      java.lang.String
      captureStdOutErr​(LogTestSupport.TestCapture<T> test)
      Capture std out/err of test logic.
      void displayGraph​(java.lang.Object root)
      Displays the graph of objects starting at root.
      void displayGraph​(java.lang.Object root, java.lang.String... ignoreMethodNames)
      Displays the graph of objects starting at root ignoring following verticies by the input method names.
      java.lang.String getDisplayRunTime​(long startTime)
      Obtains run time in human readable form.
      java.lang.String getDisplayRunTime​(long startTime, long endTime)
      Obtains run time in human readable form.
      void init​(org.junit.jupiter.api.extension.ExtensionContext context)
      Intialise.
      protected boolean isPrintMessages()
      Determines if printing messages.
      void printHeapMemoryDiagnostics()
      Prints heap memory details.
      void printMessage​(java.io.InputStream message)
      Prints a message regarding the test.
      void printMessage​(java.io.Reader message)
      Prints a message regarding the test.
      void printMessage​(java.lang.String message)
      Prints a message regarding the test.
      void setDebugVerbose()
      Specifies to provide debug verbose output to aid in debugging.
      void setLogGC()
      Turns on logging of GC as part of test.
      void setVerbose​(boolean isVerbose)
      Specifies to provide verbose output to aid in debugging.
      • Methods inherited from class java.lang.Object

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

      • LogTestSupport

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

      • init

        public void init​(org.junit.jupiter.api.extension.ExtensionContext context)
                  throws java.lang.Exception
        Description copied from interface: TestSupport
        Intialise.
        Specified by:
        init in interface TestSupport
        Parameters:
        context - ExtensionContext.
        Throws:
        java.lang.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 java.lang.Throwable> java.lang.String captureStdOutErr​(LogTestSupport.TestCapture<T> test)
                                                                          throws T extends java.lang.Throwable
        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.
        T extends java.lang.Throwable
      • captureLoggerOutput

        public <T extends java.lang.Throwable> java.lang.String captureLoggerOutput​(LogTestSupport.TestCapture<T> test)
                                                                             throws T extends java.lang.Throwable
        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.
        T extends java.lang.Throwable
      • isPrintMessages

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

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

        public java.lang.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 java.lang.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​(java.lang.String message)
        Prints a message regarding the test.
        Parameters:
        message - Message to be printed.
      • printMessage

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

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

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

        public void displayGraph​(java.lang.Object root,
                                 java.lang.String... ignoreMethodNames)
                          throws java.lang.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:
        java.lang.Exception - If fails.
      • beforeAll

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

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

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

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