mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-02 19:56:23 -04:00
Refactor viewfx package
This commit is contained in:
parent
bb14db3b8d
commit
c8e79bab58
97 changed files with 260 additions and 238 deletions
|
@ -0,0 +1,20 @@
|
|||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane xmlns:fx="http://javafx.com/fxml">
|
||||
|
||||
</AnchorPane>
|
|
@ -0,0 +1,21 @@
|
|||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.viewfx.view.fxml.FxmlViewLoaderTests$MissingFxmlViewAnnotation"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
</AnchorPane>
|
|
@ -0,0 +1,21 @@
|
|||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<?import javafx.scene.layout.*?>
|
||||
<AnchorPane fx:id="root" fx:controller="io.bitsquare.viewfx.view.fxml.FxmlViewLoaderTests$WellFormed"
|
||||
xmlns:fx="http://javafx.com/fxml">
|
||||
</AnchorPane>
|
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
* 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.viewfx.view.fxml;
|
||||
|
||||
import io.bitsquare.viewfx.ViewfxException;
|
||||
import io.bitsquare.viewfx.view.FxmlView;
|
||||
import io.bitsquare.viewfx.view.View;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import io.bitsquare.viewfx.view.ViewFactory;
|
||||
import io.bitsquare.viewfx.view.ViewLoader;
|
||||
import io.bitsquare.viewfx.view.AbstractView;
|
||||
|
||||
import javafx.fxml.LoadException;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
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.Mockito.mock;
|
||||
|
||||
public class FxmlViewLoaderTests {
|
||||
|
||||
private ViewLoader viewLoader;
|
||||
private ViewFactory viewFactory;
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
viewFactory = mock(ViewFactory.class);
|
||||
ResourceBundle resourceBundle = mock(ResourceBundle.class);
|
||||
viewLoader = new FxmlViewLoader(viewFactory, resourceBundle);
|
||||
}
|
||||
|
||||
|
||||
@FxmlView
|
||||
static class WellFormed extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wellFormedFxmlFileShouldSucceed() {
|
||||
given(viewFactory.call(WellFormed.class)).willReturn(new WellFormed());
|
||||
View view = viewLoader.load(WellFormed.class);
|
||||
assertThat(view, instanceOf(WellFormed.class));
|
||||
}
|
||||
|
||||
|
||||
@FxmlView
|
||||
static class MissingFxController extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fxmlFileMissingFxControllerAttributeShouldThrow() {
|
||||
thrown.expect(ViewfxException.class);
|
||||
thrown.expectMessage("Does it declare an fx:controller attribute?");
|
||||
viewLoader.load(MissingFxController.class);
|
||||
}
|
||||
|
||||
|
||||
static class MissingFxmlViewAnnotation extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fxmlViewAnnotationShouldBeOptional() {
|
||||
given(viewFactory.call(MissingFxmlViewAnnotation.class)).willReturn(new MissingFxmlViewAnnotation());
|
||||
View view = viewLoader.load(MissingFxmlViewAnnotation.class);
|
||||
assertThat(view, instanceOf(MissingFxmlViewAnnotation.class));
|
||||
}
|
||||
|
||||
|
||||
@FxmlView
|
||||
static class Malformed extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void malformedFxmlFileShouldThrow() {
|
||||
thrown.expect(ViewfxException.class);
|
||||
thrown.expectMessage("Failed to load view from FXML file");
|
||||
thrown.expectCause(instanceOf(LoadException.class));
|
||||
viewLoader.load(Malformed.class);
|
||||
}
|
||||
|
||||
|
||||
@FxmlView
|
||||
static class MissingFxmlFile extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingFxmlFileShouldThrow() {
|
||||
thrown.expect(ViewfxException.class);
|
||||
thrown.expectMessage("Does it exist?");
|
||||
viewLoader.load(MissingFxmlFile.class);
|
||||
}
|
||||
|
||||
|
||||
@FxmlView(location = "unconventionally/located.fxml")
|
||||
static class CustomLocation extends AbstractView {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customFxmlFileLocationShouldOverrideDefaultConvention() {
|
||||
thrown.expect(ViewfxException.class);
|
||||
thrown.expectMessage("Failed to load view class");
|
||||
thrown.expectMessage("CustomLocation");
|
||||
thrown.expectMessage("[unconventionally/located.fxml] could not be loaded");
|
||||
viewLoader.load(CustomLocation.class);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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.viewfx.view.support;
|
||||
|
||||
import io.bitsquare.viewfx.view.AbstractView;
|
||||
import io.bitsquare.viewfx.view.CachingViewLoader;
|
||||
import io.bitsquare.viewfx.view.ViewLoader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.mockito.BDDMockito.then;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
public class CachingViewLoaderTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ViewLoader delegateViewLoader = mock(ViewLoader.class);
|
||||
|
||||
ViewLoader cachingViewLoader = new CachingViewLoader(delegateViewLoader);
|
||||
|
||||
cachingViewLoader.load(TestView1.class);
|
||||
cachingViewLoader.load(TestView1.class);
|
||||
cachingViewLoader.load(TestView2.class);
|
||||
|
||||
then(delegateViewLoader).should(times(1)).load(TestView1.class);
|
||||
then(delegateViewLoader).should(times(1)).load(TestView2.class);
|
||||
then(delegateViewLoader).should(times(0)).load(TestView3.class);
|
||||
}
|
||||
|
||||
|
||||
static class TestView1 extends AbstractView {
|
||||
}
|
||||
|
||||
static class TestView2 extends AbstractView {
|
||||
}
|
||||
|
||||
static class TestView3 extends AbstractView {
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue