From 14c792ee5e5f29a4b91e5f92028668fe75ce3882 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 8 Sep 2017 13:18:20 +0300 Subject: [PATCH] Add node properties type checking test --- app/build.gradle | 1 + .../objects/NodePropertiesTypeTest.java | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java diff --git a/app/build.gradle b/app/build.gradle index bacf7ae..c0dfe1a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,5 +16,6 @@ dependencies { testRuntime 'org.junit.platform:junit-platform-launcher:1.0.0-RC2' testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.0.0-RC2' testRuntime 'org.junit.vintage:junit-vintage-engine:4.12.0-RC2' + testRuntime 'org.junit.jupiter:junit-jupiter-params:5.0.0-RC2' testImplementation 'org.hamcrest:hamcrest-library:1.3' } diff --git a/app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java b/app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java new file mode 100644 index 0000000..93aa47b --- /dev/null +++ b/app/src/test/java/com/annimon/hotarufx/visual/objects/NodePropertiesTypeTest.java @@ -0,0 +1,94 @@ +package com.annimon.hotarufx.visual.objects; + +import com.annimon.hotarufx.visual.Property; +import java.util.Arrays; +import java.util.Collections; +import java.util.stream.Stream; +import javafx.beans.value.WritableValue; +import javafx.scene.Node; +import javafx.scene.paint.Color; +import javafx.scene.paint.Paint; +import javafx.scene.text.Font; +import javafx.scene.text.Text; +import lombok.val; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +class NodePropertiesTypeTest { + + static Stream nodeProvider() { + return Stream.of( + new ArcNode(), + new CircleNode(), + new EllipseNode(), + new GroupNode(Collections.singletonList(new TextNode())), + new LineNode(), + new PolygonNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d)), + new PolylineNode(Arrays.asList(0d, 0d, 20d, 20d, 30d, 30d, 0d, 0d)), + new RectangleNode(), + new SVGPathNode(), + new TextNode() + ).flatMap(node -> node.propertyBindings() + .entrySet() + .stream() + .map(entry -> Arguments.of( + node, + entry.getKey(), + entry.getValue(), + node.getClass().getSimpleName() + )) + ); + } + + @DisplayName("Node properties type checking") + @ParameterizedTest(name = "{3}: {1}") + @MethodSource("nodeProvider") + @SuppressWarnings("unchecked") + void testNode(ObjectNode node, String name, Property property, String nodeName) { + try { + val value = property.getProperty().get().getProperty(); + switch (property.getType()) { + case BOOLEAN: + val booleanValue = (WritableValue) value; + booleanValue.setValue(true); + assertTrue(booleanValue.getValue()); + break; + case NUMBER: + val numberValue = (WritableValue) value; + numberValue.setValue(2); + assertThat(numberValue.getValue().intValue(), is(2)); + break; + case STRING: + val stringValue = (WritableValue) value; + stringValue.setValue("0"); + assertThat(stringValue.getValue(), is("0")); + break; + case NODE: + case CLIP_NODE: + val nodeValue = (WritableValue) value; + nodeValue.setValue(new Text("test")); + assertThat(((Text) nodeValue.getValue()).getText(), is("test")); + break; + case PAINT: + val paintValue = (WritableValue) value; + paintValue.setValue(Color.BLUE); + assertThat(paintValue.getValue(), is(Color.BLUE)); + break; + case FONT: + val fontValue = (WritableValue) value; + fontValue.setValue(Font.getDefault()); + assertThat(fontValue.getValue().getFamily(), is(Font.getDefault().getFamily())); + break; + } + } catch (Exception e) { + fail(node.getClass().getSimpleName() + ", " + name, e); + } + } + +} \ No newline at end of file