### Question:
ObservableDataSet extends AbstractDataSet { @Override public void propertyChanged() { DataSetObservable oldDataSet = getDataSet(); updateDataSet(); DataSetObservable newDataSet = getDataSet(); if(oldDataSet != newDataSet) { if (oldDataSet != null) { oldDataSet.removeListener(dispatcherListener); } if(newDataSet != null) { newDataSet.addListener(dispatcherListener); } } } ObservableDataSet(RefreshableItemPresentationModelFactory factory, AbstractGetSet<?> getSet); @Override int size(); @Override Object get(int index); @Override void propertyChanged(); @Override void addListener(DataSetChangeListener listener); @Override void removeListener(DataSetChangeListener listener);  }### Answer:
@Test public void whenChangeToObservable2_thenObservable1ListenerRemovedAndObservable2ListenerRegistered() { DataSetObservableUnderTest observable1 = new DataSetObservableUnderTest(); GetSet getSet = new GetSet(observable1); ObservableDataSet dataSet = new ObservableDataSet(null, getSet); DataSetObservableUnderTest observable2 = new DataSetObservableUnderTest(); getSet.setValue(observable2); dataSet.propertyChanged(); assertThat(observable1.listener, nullValue()); assertThat(observable2.listener, notNullValue()); }
@Test public void whenUpdateDataSet_thenDataSetPropertyReflectsChanges() { GetSet getSet = new GetSet(); DataSet dataSetProperty = new DataSet(getSet); DataSetObservable newValue = new DataSetObservableUnderTest(); getSet.setValue(newValue); dataSetProperty.propertyChanged(); assertSame(newValue, dataSetProperty.getDataSet()); }