Resolve generic JavaFX binding targets and verify them in IntelliJ
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
package de.neitzel.fxdesigner.target;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.*;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.control.ComboBoxBase;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class GenericPropertyTypeTest {
|
||||
static class Base<T> {
|
||||
@FXML private ComboBox<T> inherited;
|
||||
@FXML private ComboBoxBase<Long> baseControl;
|
||||
@FXML private ComboBox<? extends Number> bounded;
|
||||
@FXML private ComboBox<List<String>> nested;
|
||||
private ComboBox<String> uninjected;
|
||||
@FXML private List<String> wrongControl;
|
||||
}
|
||||
|
||||
static class Controller extends Base<Integer> {}
|
||||
|
||||
private GenericPropertyType signature(String id, String property) throws Exception {
|
||||
var field = GenericPropertyType.controlBindings(Controller.class, id, ComboBox.class);
|
||||
return GenericPropertyType.of(
|
||||
ComboBox.class, ComboBox.class.getMethod(property + "Property"), field);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesInheritedControllerAndControlArgumentsWithoutStartingJavaFx() throws Exception {
|
||||
assertEquals(Integer.class, signature("inherited", "value").value());
|
||||
assertEquals(Integer.class, signature("inherited", "items").listElement());
|
||||
assertEquals(Long.class, signature("baseControl", "value").value());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unknownOrIncompatibleFieldsDoNotCertifyListElementTypes() throws Exception {
|
||||
for (String id : List.of("bounded", "nested", "uninjected", "missing", "wrongControl"))
|
||||
assertNull(signature(id, "items").listElement(), id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user