adam bien's blog

Java FX 2 Data Binding Explained …With A JUnit Test 📎


import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;

public class StringDataBindingTest {
    
    @Test
    public void bindUnidirectionally(){
        String expected = "DukeFX";
        StringProperty from = new SimpleStringProperty();
        StringProperty to = new SimpleStringProperty();
        to.bind(from);
        from.set(expected);
        String actual = to.get();
        assertThat(actual,is(expected));
    }
}

Any questions? :-)