Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2020 Martin Koster
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
package com.github.actionfx.testing.junit5;
import static org.junit.platform.commons.util.ReflectionUtils.newInstance;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import org.junit.jupiter.api.extension.TestInstanceFactory;
import org.junit.jupiter.api.extension.TestInstanceFactoryContext;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
import org.junit.jupiter.api.extension.TestInstantiationException;
import org.testfx.api.FxRobot;
import org.testfx.api.FxToolkit;
import org.testfx.framework.junit5.ApplicationAdapter;
import org.testfx.framework.junit5.ApplicationExtension;
import org.testfx.framework.junit5.ApplicationFixture;
import org.testfx.framework.junit5.Init;
import org.testfx.framework.junit5.Start;
import org.testfx.framework.junit5.Stop;
import org.testfx.util.WaitForAsyncUtils;
import com.github.actionfx.testing.annotation.TestInFxThread;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.input.KeyCode;
import javafx.scene.input.MouseButton;
import javafx.stage.Stage;
/**
* Extension to TestFX's {@link 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
* {@link 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 {@link 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
*/
public abstract class AbstractHeadlessMonocleExtension extends FxRobot implements BeforeAllCallback, AfterEachCallback,
TestInstancePostProcessor, ParameterResolver, TestInstanceFactory, InvocationInterceptor {
private boolean executeAllMethodsInFxThread = false;
private ApplicationFixture applicationFixture;
@Override
public Object createTestInstance(final TestInstanceFactoryContext factoryContext,
final ExtensionContext extensionContext) {
// initialize toolkit here! we need the JavaFX toolkit in case the construction
// of the instance instantiates Nodes!
try {
FxToolkit.registerPrimaryStage();
} catch (final TimeoutException e) {
throw new TestInstantiationException("Can not initialize JavaFX toolkit!", e);
}
try {
final Optional