Class JavaFXInterceptorUtils.SelectiveJavaFxInterceptor

java.lang.Object
org.testfx.framework.junit5.JavaFXInterceptorUtils.SelectiveJavaFxInterceptor
All Implemented Interfaces:
org.junit.jupiter.api.extension.Extension, org.junit.jupiter.api.extension.InvocationInterceptor, org.junit.jupiter.api.extension.TestInstantiationAwareExtension
Enclosing class:
JavaFXInterceptorUtils

public static class JavaFXInterceptorUtils.SelectiveJavaFxInterceptor extends Object implements org.junit.jupiter.api.extension.InvocationInterceptor
Simple JUnit 5 extension to ensure that @Test statements are executed in the JavaFX UI thread. This is (strictly) necessary when testing setter and/or getter methods of JavaFX classes (ie. Node derived, properties etc).

Example usage:


@ExtendWith(ApplicationExtension.class)
@ExtendWith(SelectiveJavaFxInterceptor.class)
public class SquareButtonTest {
    @Start
    public void start(Stage stage) {
        // usual FX initialisation
        // ...
    }

   @TestFx // forces execution in JavaFX thread
   public void testJavaFxThreadSafety() {
       // verifies that this test is indeed executed in the JavaFX thread
       assertTrue(Platform.isFxApplicationThread());

       // perform the regular JavaFX thread safe assertion tests
       // ...
   }

   @Test // explicitly not executed in JavaFX thread;
   // for different behaviour use:  @ExtendWith(JavaFxInterceptor.class)
   public void testNonJavaFx() {
       // verifies that this test is not executed within the JavaFX thread
       assertFalse(Platform.isFxApplicationThread());

       // perform the regular non-JavaFX thread-related assertion tests
       // ...
   }
}


  • Nested Class Summary

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

    org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<T>

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

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    interceptTestMethod(org.junit.jupiter.api.extension.InvocationInterceptor.Invocation<Void> invocation, org.junit.jupiter.api.extension.ReflectiveInvocationContext<Method> invocationContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
     

    Methods inherited from class Object

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

    Methods inherited from interface org.junit.jupiter.api.extension.InvocationInterceptor

    interceptAfterAllMethod, interceptAfterEachMethod, interceptBeforeAllMethod, interceptBeforeEachMethod, interceptDynamicTest, interceptDynamicTest, interceptTestClassConstructor, interceptTestFactoryMethod, interceptTestTemplateMethod

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension

    getTestInstantiationExtensionContextScope
  • Constructor Details

    • SelectiveJavaFxInterceptor

      public SelectiveJavaFxInterceptor()
  • Method Details

    • interceptTestMethod

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