Search in sources :

Example 1 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXIntegerBidirectional.

@Test
public void testJavaFXIntegerBidirectional() {
    Property<Integer> integerDolphinProperty = new MockedProperty<>();
    Property<Number> numberDolphinProperty = new MockedProperty<>();
    IntegerProperty integerJavaFXProperty = new SimpleIntegerProperty();
    integerDolphinProperty.set(47);
    assertNotEquals(integerJavaFXProperty.get(), 47);
    Binding binding = FXBinder.bind(integerJavaFXProperty).bidirectionalToNumeric(integerDolphinProperty);
    assertEquals(integerJavaFXProperty.get(), 47);
    integerDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 100);
    integerDolphinProperty.set(null);
    assertEquals(integerJavaFXProperty.get(), 0);
    integerJavaFXProperty.set(12);
    assertEquals(integerDolphinProperty.get().intValue(), 12);
    integerJavaFXProperty.setValue(null);
    assertEquals(integerDolphinProperty.get().intValue(), 0);
    binding.unbind();
    integerDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 0);
    numberDolphinProperty.set(12);
    binding = FXBinder.bind(integerJavaFXProperty).bidirectionalTo(numberDolphinProperty);
    assertEquals(integerJavaFXProperty.get(), 12);
    numberDolphinProperty.set(null);
    assertEquals(integerJavaFXProperty.get(), 0);
    integerJavaFXProperty.set(12);
    assertEquals(numberDolphinProperty.get().intValue(), 12);
    integerJavaFXProperty.setValue(null);
    assertEquals(numberDolphinProperty.get().intValue(), 0);
    binding.unbind();
    numberDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 0);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) IntegerProperty(javafx.beans.property.IntegerProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Test(org.testng.annotations.Test)

Example 2 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXBooleanUnidirectionalWithConverter.

@Test
public void testJavaFXBooleanUnidirectionalWithConverter() {
    Property<String> stringDolphinProperty = new MockedProperty<>();
    BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
    WritableBooleanValue writableBooleanValue = new SimpleBooleanProperty();
    Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
    stringDolphinProperty.set("Hello");
    assertEquals(booleanJavaFXProperty.get(), false);
    Binding binding = FXBinder.bind(booleanJavaFXProperty).to(stringDolphinProperty, stringBooleanConverter);
    assertEquals(booleanJavaFXProperty.get(), false);
    stringDolphinProperty.set("true");
    assertEquals(booleanJavaFXProperty.get(), true);
    stringDolphinProperty.set(null);
    assertEquals(booleanJavaFXProperty.get(), false);
    binding.unbind();
    stringDolphinProperty.set("true");
    assertEquals(booleanJavaFXProperty.get(), false);
    stringDolphinProperty.set("false");
    binding = FXBinder.bind(writableBooleanValue).to(stringDolphinProperty, stringBooleanConverter);
    assertEquals(writableBooleanValue.get(), false);
    stringDolphinProperty.set("true");
    assertEquals(writableBooleanValue.get(), true);
    stringDolphinProperty.set(null);
    assertEquals(writableBooleanValue.get(), false);
    binding.unbind();
    stringDolphinProperty.set("true");
    assertEquals(writableBooleanValue.get(), false);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Arrays(java.util.Arrays) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) Assert.assertEquals(org.testng.Assert.assertEquals) DoubleProperty(javafx.beans.property.DoubleProperty) Test(org.testng.annotations.Test) FXBinder(com.canoo.platform.remoting.client.javafx.FXBinder) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) Property(com.canoo.platform.remoting.Property) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) WritableStringValue(javafx.beans.value.WritableStringValue) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ObservableList(com.canoo.platform.remoting.ObservableList) Converter(com.canoo.platform.remoting.client.javafx.Converter) BidirectionalConverter(com.canoo.platform.remoting.client.javafx.BidirectionalConverter) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) WritableIntegerValue(javafx.beans.value.WritableIntegerValue) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Assert.assertTrue(org.testng.Assert.assertTrue) StringProperty(javafx.beans.property.StringProperty) WritableDoubleValue(javafx.beans.value.WritableDoubleValue) Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) Test(org.testng.annotations.Test)

Example 3 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXStringUnidirectional.

@Test
public void testJavaFXStringUnidirectional() {
    Property<String> stringDolphinProperty = new MockedProperty<>();
    StringProperty stringJavaFXProperty = new SimpleStringProperty();
    WritableStringValue writableStringValue = new SimpleStringProperty();
    stringDolphinProperty.set("Hello");
    assertNotEquals(stringJavaFXProperty.get(), "Hello");
    Binding binding = FXBinder.bind(stringJavaFXProperty).to(stringDolphinProperty);
    assertEquals(stringJavaFXProperty.get(), "Hello");
    stringDolphinProperty.set("Hello JavaFX");
    assertEquals(stringJavaFXProperty.get(), "Hello JavaFX");
    stringDolphinProperty.set(null);
    assertEquals(stringJavaFXProperty.get(), null);
    binding.unbind();
    stringDolphinProperty.set("Hello JavaFX");
    assertEquals(stringJavaFXProperty.get(), null);
    binding = FXBinder.bind(writableStringValue).to(stringDolphinProperty);
    assertEquals(writableStringValue.get(), "Hello JavaFX");
    stringDolphinProperty.set("Dolphin Platform");
    assertEquals(writableStringValue.get(), "Dolphin Platform");
    stringDolphinProperty.set(null);
    assertEquals(writableStringValue.get(), null);
    binding.unbind();
    stringDolphinProperty.set("Dolphin Platform");
    assertEquals(writableStringValue.get(), null);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) WritableStringValue(javafx.beans.value.WritableStringValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) StringProperty(javafx.beans.property.StringProperty) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Test(org.testng.annotations.Test)

Example 4 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXIntegerUnidirectional.

@Test
public void testJavaFXIntegerUnidirectional() {
    Property<Integer> integerDolphinProperty = new MockedProperty<>();
    Property<Number> numberDolphinProperty = new MockedProperty<>();
    IntegerProperty integerJavaFXProperty = new SimpleIntegerProperty();
    WritableIntegerValue writableIntegerValue = new SimpleIntegerProperty();
    integerDolphinProperty.set(47);
    assertNotEquals(integerJavaFXProperty.doubleValue(), 47);
    Binding binding = FXBinder.bind(integerJavaFXProperty).to(integerDolphinProperty);
    assertEquals(integerJavaFXProperty.get(), 47);
    integerDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 100);
    integerDolphinProperty.set(null);
    assertEquals(integerJavaFXProperty.get(), 0);
    binding.unbind();
    integerDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 0);
    numberDolphinProperty.set(12);
    binding = FXBinder.bind(integerJavaFXProperty).to(numberDolphinProperty);
    assertEquals(integerJavaFXProperty.get(), 12);
    numberDolphinProperty.set(null);
    assertEquals(integerJavaFXProperty.get(), 0);
    binding.unbind();
    numberDolphinProperty.set(100);
    assertEquals(integerJavaFXProperty.get(), 0);
    integerDolphinProperty.set(47);
    binding = FXBinder.bind(writableIntegerValue).to(integerDolphinProperty);
    assertEquals(writableIntegerValue.get(), 47);
    integerDolphinProperty.set(100);
    assertEquals(writableIntegerValue.get(), 100);
    integerDolphinProperty.set(null);
    assertEquals(writableIntegerValue.get(), 0);
    binding.unbind();
    integerDolphinProperty.set(100);
    assertEquals(writableIntegerValue.get(), 0);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) IntegerProperty(javafx.beans.property.IntegerProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) WritableIntegerValue(javafx.beans.value.WritableIntegerValue) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Test(org.testng.annotations.Test)

Example 5 with MockedProperty

use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.

the class FXBinderTest method testJavaFXDoubleBidirectionalWithConverter.

@Test
public void testJavaFXDoubleBidirectionalWithConverter() {
    Property<String> stringDolphinProperty = new MockedProperty<>();
    DoubleProperty doubleJavaFXProperty = new SimpleDoubleProperty();
    Converter<String, Double> stringDoubleConverter = s -> s == null ? null : Double.parseDouble(s);
    Converter<Double, String> doubleStringConverter = d -> d == null ? null : d.toString();
    BidirectionalConverter<String, Double> doubleBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
    stringDolphinProperty.set("47.0");
    assertNotEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
    Binding binding = FXBinder.bind(doubleJavaFXProperty).bidirectionalToNumeric(stringDolphinProperty, doubleBidirectionalConverter);
    assertEquals(doubleJavaFXProperty.doubleValue(), 47.0, EPSILON);
    stringDolphinProperty.set("100.0");
    assertEquals(doubleJavaFXProperty.doubleValue(), 100.0, EPSILON);
    stringDolphinProperty.set(null);
    assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
    doubleJavaFXProperty.set(12.0);
    assertEquals(stringDolphinProperty.get(), "12.0");
    doubleJavaFXProperty.setValue(null);
    assertEquals(stringDolphinProperty.get(), "0.0");
    binding.unbind();
    stringDolphinProperty.set("100.0");
    assertEquals(doubleJavaFXProperty.doubleValue(), 0.0, EPSILON);
}
Also used : Binding(com.canoo.platform.core.functional.Binding) Arrays(java.util.Arrays) WritableBooleanValue(javafx.beans.value.WritableBooleanValue) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) Assert.assertEquals(org.testng.Assert.assertEquals) DoubleProperty(javafx.beans.property.DoubleProperty) Test(org.testng.annotations.Test) FXBinder(com.canoo.platform.remoting.client.javafx.FXBinder) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) Property(com.canoo.platform.remoting.Property) IntegerProperty(javafx.beans.property.IntegerProperty) ArrayList(java.util.ArrayList) WritableStringValue(javafx.beans.value.WritableStringValue) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) ObservableArrayList(com.canoo.dp.impl.remoting.collections.ObservableArrayList) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) ObservableList(com.canoo.platform.remoting.ObservableList) Converter(com.canoo.platform.remoting.client.javafx.Converter) BidirectionalConverter(com.canoo.platform.remoting.client.javafx.BidirectionalConverter) BooleanProperty(javafx.beans.property.BooleanProperty) List(java.util.List) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) WritableIntegerValue(javafx.beans.value.WritableIntegerValue) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Assert.assertTrue(org.testng.Assert.assertTrue) StringProperty(javafx.beans.property.StringProperty) WritableDoubleValue(javafx.beans.value.WritableDoubleValue) Binding(com.canoo.platform.core.functional.Binding) MockedProperty(com.canoo.dp.impl.remoting.MockedProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) DefaultBidirectionalConverter(com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter) DoubleProperty(javafx.beans.property.DoubleProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) Test(org.testng.annotations.Test)

Aggregations

MockedProperty (com.canoo.dp.impl.remoting.MockedProperty)15 Binding (com.canoo.platform.core.functional.Binding)15 Test (org.testng.annotations.Test)15 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)9 StringProperty (javafx.beans.property.StringProperty)9 BooleanProperty (javafx.beans.property.BooleanProperty)7 DoubleProperty (javafx.beans.property.DoubleProperty)7 IntegerProperty (javafx.beans.property.IntegerProperty)7 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)7 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)7 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)7 WritableBooleanValue (javafx.beans.value.WritableBooleanValue)6 WritableDoubleValue (javafx.beans.value.WritableDoubleValue)6 WritableIntegerValue (javafx.beans.value.WritableIntegerValue)6 WritableStringValue (javafx.beans.value.WritableStringValue)6 DefaultBidirectionalConverter (com.canoo.dp.impl.client.javafx.DefaultBidirectionalConverter)5 ObservableArrayList (com.canoo.dp.impl.remoting.collections.ObservableArrayList)5 ObservableList (com.canoo.platform.remoting.ObservableList)5 Property (com.canoo.platform.remoting.Property)5 BidirectionalConverter (com.canoo.platform.remoting.client.javafx.BidirectionalConverter)5