use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXBooleanBidirectionalWithConverter.
@Test
public void testJavaFXBooleanBidirectionalWithConverter() {
Property<String> stringDolphinProperty = new MockedProperty<>();
BooleanProperty booleanJavaFXProperty = new SimpleBooleanProperty();
Converter<Boolean, String> booleanStringConverter = b -> b == null ? null : b.toString();
Converter<String, Boolean> stringBooleanConverter = s -> s == null ? null : Boolean.parseBoolean(s);
BidirectionalConverter<Boolean, String> booleanStringBidirectionalConverter = new DefaultBidirectionalConverter<>(booleanStringConverter, stringBooleanConverter);
stringDolphinProperty.set("true");
assertNotEquals(booleanJavaFXProperty.get(), true);
Binding binding = FXBinder.bind(booleanJavaFXProperty).bidirectionalTo(stringDolphinProperty, booleanStringBidirectionalConverter.invert());
assertEquals(booleanJavaFXProperty.get(), true);
stringDolphinProperty.set("false");
assertEquals(booleanJavaFXProperty.get(), false);
stringDolphinProperty.set(null);
assertEquals(booleanJavaFXProperty.get(), false);
booleanJavaFXProperty.set(true);
assertEquals(stringDolphinProperty.get(), "true");
booleanJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), "false");
binding.unbind();
stringDolphinProperty.set("true");
assertEquals(booleanJavaFXProperty.get(), false);
}
use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXStringBidirectional.
@Test
public void testJavaFXStringBidirectional() {
Property<String> stringDolphinProperty = new MockedProperty<>();
StringProperty stringJavaFXProperty = new SimpleStringProperty();
stringDolphinProperty.set("Hello");
assertNotEquals(stringJavaFXProperty.get(), "Hello");
Binding binding = FXBinder.bind(stringJavaFXProperty).bidirectionalTo(stringDolphinProperty);
assertEquals(stringJavaFXProperty.get(), "Hello");
stringDolphinProperty.set("Hello World");
assertEquals(stringJavaFXProperty.get(), "Hello World");
stringDolphinProperty.set(null);
assertEquals(stringJavaFXProperty.get(), null);
stringJavaFXProperty.set("Hello from JavaFX");
assertEquals(stringDolphinProperty.get(), "Hello from JavaFX");
stringJavaFXProperty.setValue(null);
assertEquals(stringDolphinProperty.get(), null);
binding.unbind();
stringDolphinProperty.set("Hello Dolphin");
assertEquals(stringJavaFXProperty.get(), null);
}
use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.
the class FXBinderTest method testUnidirectionalChain.
@Test
public void testUnidirectionalChain() {
Property<String> stringDolphinProperty1 = new MockedProperty<>();
StringProperty stringJavaFXProperty1 = new SimpleStringProperty();
Property<String> stringDolphinProperty2 = new MockedProperty<>();
StringProperty stringJavaFXProperty2 = new SimpleStringProperty();
Binding binding1 = FXBinder.bind(stringDolphinProperty1).to(stringJavaFXProperty1);
Binding binding2 = FXBinder.bind(stringJavaFXProperty2).to(stringDolphinProperty1);
Binding binding3 = FXBinder.bind(stringDolphinProperty2).to(stringJavaFXProperty2);
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
binding2.unbind();
stringJavaFXProperty1.setValue("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello");
binding1.unbind();
binding3.unbind();
}
use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.
the class FXBinderTest method testBidirectionalChain.
@Test
public void testBidirectionalChain() {
Property<String> stringDolphinProperty1 = new MockedProperty<>();
StringProperty stringJavaFXProperty1 = new SimpleStringProperty();
Property<String> stringDolphinProperty2 = new MockedProperty<>();
StringProperty stringJavaFXProperty2 = new SimpleStringProperty();
Binding binding1 = FXBinder.bind(stringDolphinProperty1).bidirectionalTo(stringJavaFXProperty1);
Binding binding2 = FXBinder.bind(stringJavaFXProperty2).bidirectionalTo(stringDolphinProperty1);
Binding binding3 = FXBinder.bind(stringDolphinProperty2).bidirectionalTo(stringJavaFXProperty2);
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
stringDolphinProperty1.set("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
stringJavaFXProperty2.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello");
stringDolphinProperty2.set("Hello World");
assertEquals(stringDolphinProperty1.get(), "Hello World");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello World");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
binding2.unbind();
stringJavaFXProperty1.setValue("Hello");
assertEquals(stringDolphinProperty1.get(), "Hello");
assertEquals(stringDolphinProperty2.get(), "Hello World");
assertEquals(stringJavaFXProperty1.get(), "Hello");
assertEquals(stringJavaFXProperty2.get(), "Hello World");
binding1.unbind();
binding3.unbind();
}
use of com.canoo.dp.impl.remoting.MockedProperty in project dolphin-platform by canoo.
the class FXBinderTest method testJavaFXStringBidirectionalWithConverter.
@Test
public void testJavaFXStringBidirectionalWithConverter() {
Property<Double> doubleDolphinProperty = new MockedProperty<>();
StringProperty stringJavaFXProperty = new SimpleStringProperty();
Converter<String, Double> doubleStringConverter = s -> s == null ? null : Double.parseDouble(s);
Converter<Double, String> stringDoubleConverter = d -> d == null ? null : d.toString();
BidirectionalConverter<Double, String> doubleStringBidirectionalConverter = new DefaultBidirectionalConverter<>(stringDoubleConverter, doubleStringConverter);
doubleDolphinProperty.set(0.1);
assertNotEquals(stringJavaFXProperty.get(), "0.1");
Binding binding = FXBinder.bind(stringJavaFXProperty).bidirectionalTo(doubleDolphinProperty, doubleStringBidirectionalConverter);
assertEquals(stringJavaFXProperty.get(), "0.1");
doubleDolphinProperty.set(0.2);
assertEquals(stringJavaFXProperty.get(), "0.2");
doubleDolphinProperty.set(null);
assertEquals(stringJavaFXProperty.get(), null);
stringJavaFXProperty.set("0.1");
assertEquals(doubleDolphinProperty.get(), 0.1);
stringJavaFXProperty.setValue("0.2");
assertEquals(doubleDolphinProperty.get(), 0.2);
binding.unbind();
doubleDolphinProperty.set(0.3);
assertEquals(stringJavaFXProperty.get(), "0.2");
}
Aggregations