title: Providing sample data to test JavaFX GUI
body: <p>I have a JavaFX program that connects to external web API to download some data. I test parts of the logic using mocks in unit tests but now I would like to test the GUI, that is run the program and see how the downloaded data looks like when put in TableView or ListView.</p>
  
  <pre><code>public class Main extends Application {
      private MainController mainController;
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/main.fxml"));
          Parent root = fxmlLoader.load();
          mainController = fxmlLoader.getController();
          primaryStage.setTitle("Title");
          primaryStage.setScene(new Scene(root, 600, 550));
          primaryStage.show();
      }
  
      @Override
      public void stop() {
          mainController.close();
      }
  }
  </code></pre>
  
  <p>What I tried to do is to have a test method that launches the application using <code>Aplication.launch</code> and then calls a <code>MainController</code>'s method <code>setApi</code> to replace the default API manager object with a mockup. Unfortunately I don't know how to get access to the <code>mainController</code> object. So, my question is - can it be done? If yes - how? If not - what is an other way to test the GUI with sample data?</p>