public void testSetValue_FiresValueChangeEvent() {
    ValueChangeEventTracker targetTracker = ValueChangeEventTracker.observe(target);
    ValueChangeEventTracker delayedTracker = ValueChangeEventTracker.observe(delayed);

    delayed.setValue(newValue);

    assertEquals(1, targetTracker.count);
    assertEquals(oldValue, targetTracker.event.diff.getOldValue());
    assertEquals(newValue, targetTracker.event.diff.getNewValue());

    assertEquals(1, delayedTracker.count);
    assertEquals(oldValue, delayedTracker.event.diff.getOldValue());
    assertEquals(newValue, delayedTracker.event.diff.getNewValue());
  }
  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);
  }
  private void assertFiresPendingValueChange(Runnable runnable) {
    ValueChangeEventTracker tracker = ValueChangeEventTracker.observe(delayed);

    target.setValue(newValue);
    assertTrue(delayed.isStale());
    assertEquals(0, tracker.count);

    runnable.run();

    assertFalse(delayed.isStale());
    assertEquals(1, tracker.count);
    assertEquals(oldValue, tracker.event.diff.getOldValue());
    assertEquals(newValue, tracker.event.diff.getNewValue());
  }
  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);
  }
  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());
  }