Package net.officefloor.frame.test
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 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 interfaceLogTestSupport.TestCapture<T extends java.lang.Throwable>Test capture interface.
-
Constructor Summary
Constructors Constructor Description LogTestSupport()Default instantiate for use asExtensionContext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterAll()AfterAllCallbacklogic.voidafterAll(org.junit.jupiter.api.extension.ExtensionContext context)voidbeforeAll()BeforeAllCallbacklogic.voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context)<T extends java.lang.Throwable>
java.lang.StringcaptureLoggerOutput(LogTestSupport.TestCapture<T> test)CaptureLoggeroutput of test logic.<T extends java.lang.Throwable>
java.lang.StringcaptureStdOutErr(LogTestSupport.TestCapture<T> test)Capturestd out/errof test logic.voiddisplayGraph(java.lang.Object root)Displays the graph of objects starting at root.voiddisplayGraph(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.StringgetDisplayRunTime(long startTime)Obtains run time in human readable form.java.lang.StringgetDisplayRunTime(long startTime, long endTime)Obtains run time in human readable form.voidinit(org.junit.jupiter.api.extension.ExtensionContext context)Intialise.protected booleanisPrintMessages()Determines if printing messages.voidprintHeapMemoryDiagnostics()Prints heap memory details.voidprintMessage(java.io.InputStream message)Prints a message regarding the test.voidprintMessage(java.io.Reader message)Prints a message regarding the test.voidprintMessage(java.lang.String message)Prints a message regarding the test.voidsetDebugVerbose()Specifies to provide debug verbose output to aid in debugging.voidsetLogGC()Turns on logging of GC as part of test.voidsetVerbose(boolean isVerbose)Specifies to provide verbose output to aid in debugging.
-
-
-
Method Detail
-
init
public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.ExceptionDescription copied from interface:TestSupportIntialise.- Specified by:
initin interfaceTestSupport- 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-trueto 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
Capturestd out/errof test logic.- Type Parameters:
T- PossibleExceptiontype.- Parameters:
test- Test logic to capturestd err.- Returns:
std out/erroutput.- Throws:
T- PossibleThrowable.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
CaptureLoggeroutput of test logic.- Type Parameters:
T- PossibleExceptiontype.- Parameters:
test- Test logic to capturestd err.- Returns:
Loggeroutput.- Throws:
T- PossibleThrowable.T extends java.lang.Throwable
-
isPrintMessages
protected boolean isPrintMessages()
Determines if printing messages.- Returns:
trueto 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.IOExceptionPrints 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.IOExceptionPrints 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.ExceptionDisplays 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.ExceptionDisplays 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:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
java.lang.Exception
-
beforeAll
public void beforeAll() throws java.lang.ExceptionBeforeAllCallbacklogic.- Throws:
java.lang.Exception- If fails.
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback- Throws:
java.lang.Exception
-
afterAll
public void afterAll() throws java.lang.ExceptionAfterAllCallbacklogic.- Throws:
java.lang.Exception- If fails.
-
-