use of org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class DatabindingContextTest method testValidationError.
/**
* Asserts that IStatus is populated and change events are fired when a
* Binding that is associated with a context is in error.
*
* @throws Exception
*/
@Test
public void testValidationError() throws Exception {
WritableValue<String> targetObservable = WritableValue.withValueType(String.class);
WritableValue<String> modelObservable = WritableValue.withValueType(String.class);
final String errorMessage = "error";
ValueChangeEventTracker<IStatus> errorCounter = new ValueChangeEventTracker<>();
ChangeEventTracker errorsCounter = new ChangeEventTracker();
IObservableValue<IStatus> error = new AggregateValidationStatus(dbc.getBindings(), AggregateValidationStatus.MAX_SEVERITY);
error.addValueChangeListener(errorCounter);
assertTrue(error.getValue().isOK());
IObservableMap<Binding, IStatus> errors = dbc.getValidationStatusMap();
errors.addChangeListener(errorsCounter);
assertEquals(0, errors.size());
IValidator<String> validator = value -> ValidationStatus.error(errorMessage);
dbc.bindValue(targetObservable, modelObservable, new UpdateValueStrategy<String, String>().setAfterGetValidator(validator), null);
targetObservable.setValue("");
assertFalse(error.getValue().isOK());
assertEquals(errorMessage, error.getValue().getMessage());
assertEquals(1, errors.size());
assertEquals(1, errorsCounter.count);
assertEquals(1, errorCounter.count);
error.dispose();
}
use of org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class ObservableValueContractTest method testRemoveValueChangeListener_RemovesListener.
@Test
public void testRemoveValueChangeListener_RemovesListener() throws Exception {
ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
delegate.change(observable);
// precondition
assertEquals(formatFail("Value change listeners should be notified on change."), 1, listener.count);
observable.removeValueChangeListener(listener);
delegate.change(observable);
assertEquals(formatFail("Value change listeners should not be notified after they've been removed from the observable."), 1, listener.count);
}
use of org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class ObservableValueContractTest method testChange_ValueChangeEventDiff.
@Test
public void testChange_ValueChangeEventDiff() throws Exception {
ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
Object oldValue = observable.getValue();
delegate.change(observable);
ValueChangeEvent event = listener.event;
assertTrue(formatFail("Change Listeners were not notified on change."), listener.count > 0);
assertEquals(formatFail("When a value change event is fired the old value should be the previous value of the observable value."), oldValue, event.diff.getOldValue());
assertEquals(formatFail("When a value change event is fired the new value should be the same as the current value of the observable value."), observable.getValue(), event.diff.getNewValue());
}
use of org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class ObservableValueContractTest method testChange_ValueChangeEvent.
@Test
public void testChange_ValueChangeEvent() throws Exception {
ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
delegate.change(observable);
assertEquals(formatFail("On change value change listeners should be notified."), 1, listener.count);
}
use of org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker in project eclipse.platform.ui by eclipse-platform.
the class ValidatedObservableValueTest method testSetValue_SingleValueChangeEvent.
@Test
public void testSetValue_SingleValueChangeEvent() {
ValueChangeEventTracker tracker = ValueChangeEventTracker.observe(validated);
validated.setValue(newValue);
assertEquals(1, tracker.count);
assertEquals(oldValue, tracker.event.diff.getOldValue());
assertEquals(newValue, tracker.event.diff.getNewValue());
}
Aggregations