import de.neitzel.fx.view.ViewDependencies; import de.neitzel.fx.view.ViewObject; import de.neitzel.fxdesigner.preview.ExampleDescriptor; import de.neitzel.fxdesigner.preview.PreviewProvider; import de.neitzel.fxdesigner.preview.PreviewSession; import java.util.Optional; import de.neitzel.fxdesigner.target.PreviewFailure; import de.neitzel.fxdesigner.target.TargetPreview; import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import javafx.application.Platform; /** Runs against FX 1.0.6 without linking the newer adapter types in the launcher. */ public final class CapabilityCheck { public static void main(String[] args) throws Exception { Platform.startup(() -> Platform.setImplicitExit(false)); try { var descriptor = new ExampleDescriptor("book", "Missing adapter", "java.lang.String", "CapabilityCheck$Provider", "Book.fxml", "fixture"); try (var target = TargetPreview.open(descriptor, CapabilityCheck.class.getClassLoader(), Duration.ofSeconds(20))) { try { target.ready().toCompletableFuture().get(20, TimeUnit.SECONDS); throw new AssertionError("Expected missing FX adapter API"); } catch (ExecutionException failure) { var diagnostic = (PreviewFailure) failure.getCause(); if (diagnostic.code() != PreviewFailure.Code.CONTEXT_TYPE || !diagnostic.getMessage().contains("1.0.7")) throw new AssertionError(diagnostic); } target.cleanup().toCompletableFuture().get(5, TimeUnit.SECONDS); System.out.println("PASS missing-capability 1"); } } finally { Platform.exit(); } } // Linking this Provider itself needs the new interface, before opening any preview session. public static final class Provider implements PreviewProvider, ViewDependencies { public Class modelType() { return String.class; } public PreviewSession open(String id) { throw new AssertionError("Provider unexpectedly loaded with the old FX runtime"); } public boolean isComponent(Class type) { return false; } public Optional findService(Class type) { return Optional.empty(); } public ViewObject createViewObject(Class type) { throw new UnsupportedOperationException(); } } }