@Test
  public void whenCheckedItemPositionChanged_thenValueModelUpdatedAccordingly() {
    ValueModel<SparseBooleanArray> valueModel =
        twoWayBindToProperty(SparseBooleanArray.class, new SparseBooleanArray());

    setItemsChecked(SparseBooleanArrayUtils.toSet(checkedItemPositions));

    assertSparseBooleanArrayEquals(checkedItemPositions, valueModel.getValue());
  }
 @Override
 public void performBind(PresentationModelAdapter presentationModelAdapter) {
   final ValueModel<PropertyType> valueModel = getPropertyValueModel(presentationModelAdapter);
   valueModel.addPropertyChangeListener(
       new PresentationModelPropertyChangeListener() {
         @Override
         public void propertyChanged() {
           valueModelUpdated(valueModel.getValue());
         }
       });
 }
 @Override
 public void setValue(PropertyType newValue) {
   viewUpdatePropagationLatch.turnOn();
   try {
     propertyValueModel.setValue(newValue);
   } finally {
     viewUpdatePropagationLatch.turnOff();
   }
 }
 private void observeChangesOnTheValueModel(final ValueModel<PropertyType> valueModel) {
   valueModel.addPropertyChangeListener(
       new PresentationModelPropertyChangeListener() {
         @Override
         public void propertyChanged() {
           if (viewUpdatePropagationLatch.tryToPass()) valueModelUpdated(valueModel.getValue());
         }
       });
 }
  @Test
  public void
      givenAPropertyViewAttributeWithTwoWayBinding_whenValueModelIsUpdated_thenViewShouldReceiveOnlyASingleUpdate() {
    setupAndBindAttribute(TWO_WAY_BINDING, DONT_PRE_INITIALIZE_VIEW);

    valueModel.setValue(A_NEW_VALUE);

    assertThat(attribute.viewUpdateNotificationCount, is(1));
  }
  @Test
  public void
      givenAPropertyViewAttributeWithTwoWayBinding_whenTheViewIsUpdated_thenValueModelShouldBeUpdated() {
    setupAndBindAttribute(TWO_WAY_BINDING, DONT_PRE_INITIALIZE_VIEW);

    attribute.simulateViewUpdate(A_NEW_VALUE);

    assertThat(valueModel.getValue(), is(A_NEW_VALUE));
  }
  @Test
  public void
      givenABoundPropertyViewAttribute_whenValueModelIsUpdated_thenNewValueShouldBePassedToThePropertyViewAttribute() {
    setupAndBindAttribute(ONE_WAY_BINDING, DONT_PRE_INITIALIZE_VIEW);

    valueModel.setValue(A_NEW_VALUE);

    assertThat(attribute.updatedValue, is(A_NEW_VALUE));
  }
 public void preInitializeView(BindingContext presentationModelAdapter) {
   ValueModel<PropertyType> valueModel = getPropertyValueModel(presentationModelAdapter);
   valueModelUpdated(valueModel.getValue());
 }
 @Override
 public void removePropertyChangeListener(PresentationModelPropertyChangeListener listener) {
   propertyValueModel.removePropertyChangeListener(listener);
 }
 @Override
 public PropertyType getValue() {
   return propertyValueModel.getValue();
 }