Class AbstractHeadlessMonocleExtension

  • All Implemented Interfaces:
    org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstanceFactory, org.junit.jupiter.api.extension.TestInstancePostProcessor, org.testfx.api.FxRobotInterface
    Direct Known Subclasses:
    FxThreadForAllMonocleExtension, FxThreadForEachMonocleExtension

    public abstract class AbstractHeadlessMonocleExtension
    extends org.testfx.api.FxRobot
    implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterEachCallback, org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.ParameterResolver, org.junit.jupiter.api.extension.TestInstanceFactory, org.junit.jupiter.api.extension.InvocationInterceptor
    Extension to TestFX's ApplicationExtension that sets the test platform "Monocle" to "headless".

    This base class provides routines to control the creation and shutdown of the JavaFX application and thread explicetly.

    This extension is abstract and allows derived classes to explicitly control the lifecycle of the JavaFX application and thread. Originally, TestFX's ApplicationExtension starts the JavaFX application and thread before the test method execution takes place. This behavior however causes issues with test fixtures that require a JavaFX thread and application also outside the test method. When using Spring e.g., Spring might want to instantiate a bean within the JavaFX thread, which would not be possible by plainly using the ApplicationExtesion.

    Additionally, the initialization of the Java toolkit must happen way before the instantiation of the class under test, because it can be that there are nodes instantiated outside of the test method itself. This will fail, if the toolkit is not yet initialized.

    Author:
    MartinKoster
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

        org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T extends java.lang.Object>
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterEach​(org.junit.jupiter.api.extension.ExtensionContext context)  
      void beforeAll​(org.junit.jupiter.api.extension.ExtensionContext context)  
      java.lang.Object createTestInstance​(org.junit.jupiter.api.extension.TestInstanceFactoryContext factoryContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      void interceptTestMethod​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      void postProcessTestInstance​(java.lang.Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context)  
      java.lang.Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      protected void startJavaFxApplication()
      Starts the JavaFX application thread.
      protected void stopJavaFxApplication()
      Stops the JavaFX application thread.
      boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)  
      • Methods inherited from class org.testfx.api.FxRobot

        bounds, bounds, bounds, bounds, bounds, bounds, bounds, bounds, bounds, capture, capture, capture, capture, capture, capture, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, closeCurrentWindow, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, drag, drag, drag, drag, drag, drag, drag, drag, drag, drag, drag, drop, dropBy, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, dropTo, eraseText, from, from, from, fromAll, interact, interact, interactNoWait, interactNoWait, interrupt, interrupt, listTargetWindows, listWindows, lookup, lookup, lookup, moveBy, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, offset, offset, offset, offset, offset, offset, offset, offset, offset, point, point, point, point, point, point, point, point, point, press, press, push, push, release, release, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, robotContext, rootNode, rootNode, rootNode, scroll, scroll, scroll, scroll, scroll, sleep, sleep, targetPos, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, targetWindow, type, type, window, window, window, window, window, window, write, write, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.testfx.api.FxRobotInterface

        clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, clickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, doubleClickOn, moveBy, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, moveTo, offset, offset, offset, offset, offset, offset, offset, offset, offset, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn, rightClickOn
      • Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

        interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestTemplateMethod
    • Constructor Detail

      • AbstractHeadlessMonocleExtension

        public AbstractHeadlessMonocleExtension()
    • Method Detail

      • createTestInstance

        public java.lang.Object createTestInstance​(org.junit.jupiter.api.extension.TestInstanceFactoryContext factoryContext,
                                                   org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Specified by:
        createTestInstance in interface org.junit.jupiter.api.extension.TestInstanceFactory
      • postProcessTestInstance

        public void postProcessTestInstance​(java.lang.Object testInstance,
                                            org.junit.jupiter.api.extension.ExtensionContext context)
                                     throws java.lang.Exception
        Specified by:
        postProcessTestInstance in interface org.junit.jupiter.api.extension.TestInstancePostProcessor
        Throws:
        java.lang.Exception
      • startJavaFxApplication

        protected void startJavaFxApplication()
        Starts the JavaFX application thread. This method must be called AFTER the test instance is internally created.
      • stopJavaFxApplication

        protected void stopJavaFxApplication()
        Stops the JavaFX application thread.
      • 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
      • interceptTestMethod

        public void interceptTestMethod​(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<java.lang.Void> invocation,
                                        org.junit.jupiter.api.extension.ReflectiveInvocationContext<java.lang.reflect.Method> invocationContext,
                                        org.junit.jupiter.api.extension.ExtensionContext extensionContext)
                                 throws java.lang.Throwable
        Specified by:
        interceptTestMethod in interface org.junit.jupiter.api.extension.InvocationInterceptor
        Throws:
        java.lang.Throwable
      • supportsParameter

        public boolean supportsParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                         org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Specified by:
        supportsParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      • resolveParameter

        public java.lang.Object resolveParameter​(org.junit.jupiter.api.extension.ParameterContext parameterContext,
                                                 org.junit.jupiter.api.extension.ExtensionContext extensionContext)
        Specified by:
        resolveParameter in interface org.junit.jupiter.api.extension.ParameterResolver
      • afterEach

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