When one of the properties is bound with bind(), and you then apply a bindBidirectional between that property and another, the direction in which you do this (a.bindBidirectional(b) or b.bindBidirectional(a)) matters. One will throw an exception -- the other will not.
package hs.mediasystem.screens.collection.detail;
import static org.junit.Assert.assertEquals;
import hs.mediasystem.test.JavaFXRunningRule;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.junit.Rule;
import org.junit.Test;
public class BoundBidirectionalPropertyTest {
@Rule
public final JavaFXRunningRule jfxRunningRule = new JavaFXRunningRule();
@Test(expected = RuntimeException.class)
public void shouldThrowException() {
StringProperty a = new SimpleStringProperty("a");
StringProperty b = new SimpleStringProperty("b");
StringProperty c = new SimpleStringProperty("c");
b.bind(a);
b.bindBidirectional(c); // Throws exception "A bound value cannot be set"
assertEquals("a", a.get());
assertEquals("a", b.get());
assertEquals("a", c.get());
}
@Test(expected = RuntimeException.class)
public void shouldAlsoThrowException() {
StringProperty a = new SimpleStringProperty("a");
StringProperty b = new SimpleStringProperty("b");
StringProperty c = new SimpleStringProperty("c");
b.bind(a);
c.bindBidirectional(b); // Does not throw exception...
assertEquals("a", a.get());
assertEquals("a", b.get());
assertEquals("a", c.get());
}
}
package hs.mediasystem.screens.collection.detail;
import static org.junit.Assert.assertEquals;
import hs.mediasystem.test.JavaFXRunningRule;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import org.junit.Rule;
import org.junit.Test;
public class BoundBidirectionalPropertyTest {
@Rule
public final JavaFXRunningRule jfxRunningRule = new JavaFXRunningRule();
@Test(expected = RuntimeException.class)
public void shouldThrowException() {
StringProperty a = new SimpleStringProperty("a");
StringProperty b = new SimpleStringProperty("b");
StringProperty c = new SimpleStringProperty("c");
b.bind(a);
b.bindBidirectional(c); // Throws exception "A bound value cannot be set"
assertEquals("a", a.get());
assertEquals("a", b.get());
assertEquals("a", c.get());
}
@Test(expected = RuntimeException.class)
public void shouldAlsoThrowException() {
StringProperty a = new SimpleStringProperty("a");
StringProperty b = new SimpleStringProperty("b");
StringProperty c = new SimpleStringProperty("c");
b.bind(a);
c.bindBidirectional(b); // Does not throw exception...
assertEquals("a", a.get());
assertEquals("a", b.get());
assertEquals("a", c.get());
}
}