AbstractField extends Component implements HasValueAndElement<ComponentValueChangeEvent<C, T>, T> { @Override public void setValue(T value) { fieldSupport.setValue(value); } AbstractField(T defaultValue);  AbstractField(Element element, T defaultValue); @Override Registration addValueChangeListener(
            HasValue.ValueChangeListener<? super ComponentValueChangeEvent<C, T>> listener); @Override void setValue(T value); @Override boolean isEmpty(); @Override T getValue(); @Override T getEmptyValue();  }
@Test public void setValue_differentValue_firesOneEvent() { TestAbstractField<String> field = new TestAbstractField<>(); ValueChangeMonitor<String> eventMonitor = new ValueChangeMonitor<>( field); field.setValue("Foo"); eventMonitor.assertEvent(false, null, "Foo"); Assert.assertEquals("Foo", field.presentationValue); }
@Test public void customEquals() { TestAbstractField<Integer> field = new TestAbstractField<>(); field.valueEquals = (value1, value2) -> value1 == value2; Integer value1 = new Integer(0); Integer value2 = new Integer(0); field.setValue(value1); ValueChangeMonitor<Integer> eventMonitor = new ValueChangeMonitor<>( field); field.setValue(value1); eventMonitor.assertNoEvent(); field.setValue(value2); eventMonitor.assertEvent(false, value1, value2); field.updatePresentationValue(value2, true); eventMonitor.assertNoEvent(); field.updatePresentationValue(value1, true); eventMonitor.assertEvent(true, value2, value1); }
@Test public void setPresentation_setSameValue_notRunAgain() { TestAbstractField<String> field = new TestAbstractField<>(); AtomicReference<String> lastWriteValue = new AtomicReference<>(); field.setPresentationValue = value -> { Assert.assertNull("Unexpected update", lastWriteValue.getAndSet(value)); field.presentationValue = value; }; field.setValue("foo"); Assert.assertEquals("foo", lastWriteValue.get()); lastWriteValue.set(null); field.setValue("foo"); Assert.assertNull(lastWriteValue.get()); }