mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-24 15:35:34 -04:00
Change signature of ViewLoader#load to accept Class
This commit is contained in:
parent
4ebc0c0e41
commit
9041ff3d82
5 changed files with 14 additions and 143 deletions
|
@ -1,100 +0,0 @@
|
|||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.app.gui;
|
||||
|
||||
import io.bitsquare.app.BitsquareEnvironment;
|
||||
import io.bitsquare.gui.main.funds.FundsView;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import viewfx.ViewfxException;
|
||||
import viewfx.view.support.fxml.FxmlViewLoader;
|
||||
import viewfx.view.support.guice.GuiceViewFactory;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import joptsimple.OptionParser;
|
||||
|
||||
public class ViewLoaderTests {
|
||||
|
||||
public static class TestApp extends Application {
|
||||
static Stage primaryStage;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
TestApp.primaryStage = primaryStage;
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initJavaFX() throws InterruptedException {
|
||||
Thread t = new Thread("JavaFX Init Thread") {
|
||||
public void run() {
|
||||
Application.launch(TestApp.class);
|
||||
}
|
||||
};
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
while (TestApp.primaryStage == null)
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
private GuiceViewFactory viewFactory;
|
||||
private ResourceBundle resourceBundle;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
OptionParser parser = new OptionParser();
|
||||
BitsquareEnvironment env = new BitsquareEnvironment(parser.parse(new String[]{}));
|
||||
Injector injector = Guice.createInjector(new BitsquareAppModule(env, TestApp.primaryStage));
|
||||
viewFactory = injector.getInstance(GuiceViewFactory.class);
|
||||
viewFactory.setInjector(injector);
|
||||
|
||||
resourceBundle = BSResources.getResourceBundle();
|
||||
}
|
||||
|
||||
@Test(expected = ViewfxException.class)
|
||||
public void loadingBogusFxmlResourceShouldThrow() throws MalformedURLException {
|
||||
URL uri = new File("/tmp/bogus1234").toURI().toURL();
|
||||
new FxmlViewLoader(viewFactory, resourceBundle).load(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadingFromValidFxmlViewClassShouldNotThrow() {
|
||||
new FxmlViewLoader(viewFactory, resourceBundle).load(FundsView.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void loadingFromNonViewClassShouldThrow() {
|
||||
new FxmlViewLoader(viewFactory, resourceBundle).load(File.class);
|
||||
}
|
||||
}
|
|
@ -36,7 +36,6 @@ import org.junit.rules.ExpectedException;
|
|||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Matchers.contains;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public class FxmlViewLoaderTests {
|
||||
|
@ -90,17 +89,6 @@ public class FxmlViewLoaderTests {
|
|||
}
|
||||
|
||||
|
||||
static class NonView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonViewClassShouldThrow() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Class must be of generic type");
|
||||
viewLoader.load(NonView.class);
|
||||
}
|
||||
|
||||
|
||||
@FxmlView
|
||||
static class Malformed extends AbstractView {
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue