Package org.testfx.framework.junit5
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
- 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>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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 java.lang.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
-
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 interfaceorg.junit.jupiter.api.extension.InvocationInterceptor
- Throws:
Throwable
-