mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-25 07:27:18 +01:00
Fix broken tests and app exceptions due to ViewLoader changes
This commit is contained in:
parent
87fb4390c4
commit
2705e80ef1
3 changed files with 32 additions and 10 deletions
|
@ -28,9 +28,13 @@ import io.bitsquare.gui.util.validation.BtcValidator;
|
|||
import io.bitsquare.gui.util.validation.FiatValidator;
|
||||
import io.bitsquare.gui.util.validation.InputValidator;
|
||||
import io.bitsquare.gui.util.validation.PasswordValidator;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.name.Names;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import viewfx.view.ViewFactory;
|
||||
import viewfx.view.support.ViewLoader;
|
||||
import viewfx.view.support.guice.GuiceViewFactory;
|
||||
|
@ -50,7 +54,10 @@ public class GuiModule extends BitsquareModule {
|
|||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(ViewFactory.class).to(GuiceViewFactory.class).asEagerSingleton();
|
||||
bind(GuiceViewFactory.class).in(Singleton.class);
|
||||
bind(ViewFactory.class).to(GuiceViewFactory.class);
|
||||
|
||||
bind(ResourceBundle.class).toInstance(BSResources.getResourceBundle());
|
||||
bind(ViewLoader.class).asEagerSingleton();
|
||||
|
||||
bind(OfferBook.class).asEagerSingleton();
|
||||
|
|
|
@ -17,10 +17,13 @@
|
|||
|
||||
package viewfx.view.support;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -33,10 +36,12 @@ public class ViewLoader {
|
|||
|
||||
private final Map<URL, View> cache = new HashMap<>();
|
||||
private final ViewFactory viewFactory;
|
||||
private final ResourceBundle resourceBundle;
|
||||
|
||||
@Inject
|
||||
public ViewLoader(ViewFactory viewFactory) {
|
||||
public ViewLoader(ViewFactory viewFactory, ResourceBundle resourceBundle) {
|
||||
this.viewFactory = viewFactory;
|
||||
this.resourceBundle = resourceBundle;
|
||||
}
|
||||
|
||||
public View load(URL url) {
|
||||
|
@ -47,12 +52,16 @@ public class ViewLoader {
|
|||
if (useCaching && cache.containsKey(url))
|
||||
return cache.get(url);
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(url);
|
||||
try {
|
||||
FXMLLoader loader = new FXMLLoader(url, resourceBundle);
|
||||
loader.setControllerFactory(viewFactory);
|
||||
|
||||
loader.load();
|
||||
View view = loader.getController();
|
||||
cache.put(url, view);
|
||||
return view;
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException("Failed to load View at location " + url, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,15 @@ package io.bitsquare.app.gui;
|
|||
import io.bitsquare.BitsquareException;
|
||||
import io.bitsquare.app.BitsquareEnvironment;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import viewfx.view.support.ViewLoader;
|
||||
import viewfx.view.support.guice.GuiceViewFactory;
|
||||
|
||||
|
@ -63,6 +66,7 @@ public class ViewLoaderTests {
|
|||
}
|
||||
|
||||
private GuiceViewFactory viewFactory;
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
@ -71,15 +75,17 @@ public class ViewLoaderTests {
|
|||
Injector injector = Guice.createInjector(new BitsquareAppModule(env, TestApp.primaryStage));
|
||||
viewFactory = injector.getInstance(GuiceViewFactory.class);
|
||||
viewFactory.setInjector(injector);
|
||||
|
||||
resourceBundle = BSResources.getResourceBundle();
|
||||
}
|
||||
|
||||
@Test(expected = BitsquareException.class)
|
||||
public void loadingBogusFxmlResourceShouldThrow() throws MalformedURLException {
|
||||
new ViewLoader(viewFactory).load(Navigation.Item.BOGUS.getFxmlUrl(), false);
|
||||
new ViewLoader(viewFactory, resourceBundle).load(Navigation.Item.BOGUS.getFxmlUrl(), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadingValidFxmlResourceShouldNotThrow() {
|
||||
new ViewLoader(viewFactory).load(Navigation.Item.ACCOUNT.getFxmlUrl(), false);
|
||||
new ViewLoader(viewFactory, resourceBundle).load(Navigation.Item.ACCOUNT.getFxmlUrl(), false);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue