package com.agfa.modules.gridpath.fx.properties; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import javafx.beans.binding.IntegerExpression; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import org.easymock.EasyMock; import org.junit.Test; public class TestDivideExpressionAreListenable { @SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testCanListenAnExpression() { SimpleIntegerProperty p = new SimpleIntegerProperty(10); IntegerExpression dividedBy2Expression1 = IntegerProperty.integerExpression(p.divide(2)); IntegerExpression dividedBy2Expression2 = IntegerProperty.integerExpression(p.divide(2)); ChangeListener l1 = EasyMock.createStrictMock(ChangeListener.class); l1.changed((ObservableValue)EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject()); EasyMock.expectLastCall().times(2); ChangeListener l2 = EasyMock.createStrictMock(ChangeListener.class); l2.changed((ObservableValue)EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject()); EasyMock.expectLastCall().times(2); EasyMock.replay(l1, l2); dividedBy2Expression1.addListener(l1); dividedBy2Expression2.addListener(l2); p.set(100); assertThat(dividedBy2Expression1.get(), is(50)); assertThat(dividedBy2Expression2.get(), is(50)); p.set(200); assertThat(dividedBy2Expression1.get(), is(100)); assertThat(dividedBy2Expression2.get(), is(100)); EasyMock.verify(l1, l2); } }