Separate JavaFX loading from the Neitzel injection container
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package de.neitzel.fx.test;
|
||||
|
||||
import de.neitzel.fx.view.LoadedView;
|
||||
import de.neitzel.fx.view.ViewDependencies;
|
||||
import de.neitzel.fx.view.ViewLoader;
|
||||
import de.neitzel.fx.view.ViewModelContext;
|
||||
import de.neitzel.injection.ApplicationContext;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -105,15 +105,15 @@ public final class FxFixture {
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads production FXML on the FX thread in the test's automatically closed model context.
|
||||
* Loads managed FXML with application-supplied dependencies on the FX thread.
|
||||
* @param fxml view resource
|
||||
* @param model model for the view
|
||||
* @param services controller and service container
|
||||
* @param dependencies adapter for View objects and services
|
||||
* @return managed view
|
||||
* @throws Exception if the view cannot be loaded or the wait is interrupted or times out
|
||||
*/
|
||||
public LoadedView load(URL fxml, Object model, ApplicationContext services) throws Exception {
|
||||
return call(() -> ViewLoader.load(fxml, model, services, models));
|
||||
public LoadedView loadWithDependencies(URL fxml, Object model, ViewDependencies dependencies) throws Exception {
|
||||
return call(() -> ViewLoader.loadWithDependencies(fxml, model, dependencies, models));
|
||||
}
|
||||
|
||||
void finish() throws Exception {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.neitzel.fx.test;
|
||||
|
||||
import de.neitzel.injection.ApplicationContext;
|
||||
import de.neitzel.fx.view.ViewDependencies;
|
||||
import de.neitzel.fx.view.ViewObject;
|
||||
import java.util.Optional;
|
||||
import java.io.IOException;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.Scene;
|
||||
@@ -24,7 +26,13 @@ public class FxFixtureTest {
|
||||
var nested = new FxFixture();
|
||||
var problem = new IllegalStateException("callback failed");
|
||||
nested.start();
|
||||
var view = nested.load(getClass().getResource("name.fxml"), person, new ApplicationContext(Person.class));
|
||||
var view = nested.loadWithDependencies(getClass().getResource("name.fxml"), person, new ViewDependencies() {
|
||||
public boolean isComponent(Class<?> type) { return false; }
|
||||
public <T> Optional<T> findService(Class<T> type) { return Optional.empty(); }
|
||||
public <T> ViewObject<T> createViewObject(Class<T> type) {
|
||||
throw new AssertionError("Unexpected view type: " + type);
|
||||
}
|
||||
});
|
||||
var field = nested.call(() -> (TextField) view.getRoot());
|
||||
var stage = nested.call(() -> {
|
||||
assertEquals("Ada", field.getText());
|
||||
|
||||
Reference in New Issue
Block a user