@Test
public void conflictingBinding() throws Exception {
//binding an enum and a number
Property<TestEnum> enumProperty = new SimpleObjectProperty<>(TestEnum.NEGATIVE);
Property<Number> integerProperty = new SimpleIntegerProperty(10);
//the usual transfomers
Function<Number, TestEnum> toEnum = number -> number.intValue() >= 0 ? TestEnum.POSITIVE : TestEnum.NEGATIVE;
Function<TestEnum, Number> toNumber = testEnum -> testEnum.equals(TestEnum.POSITIVE) ? 1 : -1;
//the inverse transformers: take a positive and call it negative
Function<Number, TestEnum> toEnum2 = number -> number.intValue() < 0 ? TestEnum.POSITIVE : TestEnum.NEGATIVE;
Function<TestEnum, Number> toNumber2 = testEnum -> testEnum.equals(TestEnum.NEGATIVE) ? 1 : -1;
//create the binding
HeterogeneousBidirectionalBinder<TestEnum, Number> binder =
new HeterogeneousBidirectionalBinder<>(enumProperty, integerProperty, toNumber, toEnum);
//like the original double-binding, when binder is created the property1 is set to property 2
Assert.assertEquals(TestEnum.POSITIVE, enumProperty.getValue());
//if i change the integer property, i will see enum property change
integerProperty.setValue(-5);
Assert.assertEquals(TestEnum.NEGATIVE, enumProperty.getValue());
integerProperty.setValue(5);
Assert.assertEquals(TestEnum.POSITIVE, enumProperty.getValue());
integerProperty.setValue(-5);
Assert.assertEquals(TestEnum.NEGATIVE, enumProperty.getValue());
binder.unbind();
HeterogeneousBidirectionalBinder<TestEnum, Number> binder2 =
new HeterogeneousBidirectionalBinder<>(enumProperty, integerProperty, toNumber2, toEnum2);
integerProperty.setValue(5);
Assert.assertEquals(TestEnum.NEGATIVE, enumProperty.getValue());
integerProperty.setValue(-5);
Assert.assertEquals(TestEnum.POSITIVE, enumProperty.getValue());
HeterogeneousBidirectionalBinder<TestEnum, Number> binder3 =
new HeterogeneousBidirectionalBinder<>(enumProperty, integerProperty, toNumber, toEnum);
binder2.unbind();
binder.unbind(); //this is ignored. Notice that this is the big difference with the Bindings class since that uses
//statics all over the place and is forced to use deep equals to unbind correctly.
integerProperty.setValue(5);
Assert.assertEquals(TestEnum.POSITIVE, enumProperty.getValue());
integerProperty.setValue(-5);
Assert.assertEquals(TestEnum.NEGATIVE, enumProperty.getValue());
binder3.unbind();