Edit and exercise Archiver CommandBindings in the IntelliJ designer
This commit is contained in:
+61
@@ -112,6 +112,67 @@ class BindingDiscoveryTest {
|
||||
() -> BindingDiscovery.inspect(fxml(), "", "wrong", getClass().getClassLoader()));
|
||||
}
|
||||
|
||||
@de.neitzel.fx.view.ViewModelClass(Commands.class)
|
||||
public static class Controller {}
|
||||
|
||||
public static class Commands {
|
||||
public Commands(Model model) {
|
||||
throw new AssertionError("Discovery constructed the ViewModel");
|
||||
}
|
||||
|
||||
public de.neitzel.fx.view.Command getOpen() {
|
||||
throw new AssertionError("Discovery executed the Command getter");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void commandDiscoveryResolvesTargetsAndLocatesConflictsInEitherOrder() throws Exception {
|
||||
String command = "<CommandBinding control='menu' path='open'/>";
|
||||
String xml =
|
||||
"<?neitzel-model "
|
||||
+ Model.class.getName()
|
||||
+ "?><?import javafx.scene.layout.*?>"
|
||||
+ "<?import javafx.scene.control.*?><?import de.neitzel.fx.view.*?>"
|
||||
+ "<VBox xmlns:fx='http://javafx.com/fxml/1' fx:controller='"
|
||||
+ Controller.class.getName()
|
||||
+ "'>"
|
||||
+ "<fx:define><BindingList>"
|
||||
+ command
|
||||
+ "<CommandBinding control='go'"
|
||||
+ " path='open'/></BindingList></fx:define><MenuButton><items><MenuItem"
|
||||
+ " fx:id='menu'/></items></MenuButton><Button fx:id='go'/><Label"
|
||||
+ " fx:id='label'/></VBox>";
|
||||
var valid = BindingDiscovery.inspect(xml, "", "view", getClass().getClassLoader());
|
||||
assertEquals(List.of("open"), valid.commandPaths());
|
||||
assertEquals(List.of("go", "menu"), valid.commandTargets());
|
||||
assertTrue(
|
||||
valid.problems().stream().noneMatch(p -> p.severity().equals("ERROR")),
|
||||
valid.problems().toString());
|
||||
for (var invalid :
|
||||
List.of(
|
||||
xml.replace(
|
||||
command,
|
||||
command
|
||||
+ "<DirectBinding control='menu' property='disable' path='name'"
|
||||
+ " direction='view'/>"),
|
||||
xml.replace(
|
||||
command,
|
||||
"<ComputedBinding control='menu' property='onAction' method='#existing'/>"
|
||||
+ command),
|
||||
xml.replace(command, command + command),
|
||||
xml.replace("fx:id='menu'", "fx:id='menu' onAction='#existing'"),
|
||||
xml.replace("control='menu'", "control='missing'"),
|
||||
xml.replace("control='menu'", "control='label'"),
|
||||
xml.replace("path='open'", "path='sub.open'"),
|
||||
xml.replace("path='open'", "path='missing'"))) {
|
||||
var report = BindingDiscovery.inspect(invalid, "", "view", getClass().getClassLoader());
|
||||
assertTrue(
|
||||
report.problems().stream()
|
||||
.anyMatch(p -> p.severity().equals("ERROR") && p.property().equals("command")),
|
||||
report.problems().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class NumberModel {
|
||||
public Number getAmount() {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user