SimpleIrdListener implements AutoCloseable, DataTreeChangeListener<IrdInstanceConfiguration> { @Override public synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdInstanceConfiguration>> changes) { WriteTransaction wx = mDataBroker.newWriteOnlyTransaction(); for (DataTreeModification<IrdInstanceConfiguration> change: changes) { final DataObjectModification<IrdInstanceConfiguration> rootNode = change.getRootNode(); switch (rootNode.getModificationType()) { case WRITE: case SUBTREE_MODIFIED: final IrdInstanceConfiguration original = rootNode.getDataBefore(); final IrdInstanceConfiguration updated = rootNode.getDataAfter(); handleSubtreeModefication(original, updated, wx); break; case DELETE: removeIrd(rootNode.getDataBefore(), wx); break; default: break; } } wx.submit(); } SimpleIrdListener(Uuid context); void register(DataBroker dataBroker, InstanceIdentifier<IrdInstanceConfiguration> iid); @Override synchronized void onDataTreeChanged(Collection<DataTreeModification<IrdInstanceConfiguration>> changes); @Override synchronized void close();  }
@SuppressWarnings("unchecked") @Test public void onDataChanged() throws Exception { DataTreeModification<IrdInstanceConfiguration> mockDataTreeModification = mock(DataTreeModification.class); DataObjectModification<IrdInstanceConfiguration> mockModification = mock(DataObjectModification.class); doReturn(mockModification).when(mockDataTreeModification).getRootNode(); IrdInstanceConfiguration iicb = new IrdInstanceConfigurationBuilder() .setKey(new IrdInstanceConfigurationKey(new ResourceId("ORIGINAL_CONFIG"))).build(); doReturn(iicb).when(mockModification).getDataAfter(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); when(m_dataBroker.newWriteOnlyTransaction()).thenReturn(wx); simpleIrdListener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); }