I use JavaFX for a GUI that waits for some user's input and tries to process that input. In case of any exception a javafx.scene.control.Alert is opened to present the exception to the user. The call for that Alert is done in the method that handles the exception.
This method is supposed to be tested: For a special input, check if the right exception is thrown. The right exception is actually thrown and the handling method is called, but now here's the problem: In the test case there is no real Application running and no Stage created. Apparently because of that the creation of the Alert-dialog throws the exception:
java.lang.IllegalStateException: Toolkit not initialized
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
... 46 more
That causes the test to fail because now another incorrect exception is thrown.
So: Is there any way to show the Alert without having a Stage?