OFLinkListener implements DataTreeChangeListener<Link> { @Override public void onDataTreeChanged(Collection<DataTreeModification<Link>> changes) { for (DataTreeModification<Link> change: changes) { DataObjectModification<Link> rootNode = change.getRootNode(); switch (rootNode.getModificationType()) { case WRITE: case SUBTREE_MODIFIED: final Link updatedLink = rootNode.getDataAfter(); log.debug("OF link updated:{}", updatedLink.getKey()); pnConverter.ofLinkAdded(updatedLink); break; case DELETE: final Link deletedLink = rootNode.getDataBefore(); log.debug("OF link removed:{}", deletedLink.getKey()); pnConverter.ofLinkRemoved(deletedLink); break; default: break; } } } protected  OFLinkListener(PhysicalNetworkAdapter pnConverter); @Override void onDataTreeChanged(Collection<DataTreeModification<Link>> changes);  }
@SuppressWarnings("unchecked") @Test public void testOnDataTreeChanged() throws Exception { DataTreeModification<Link> mockDataTreeModification = mock(DataTreeModification.class); DataObjectModification<Link> mockModification = mock(DataObjectModification.class); doReturn(mockModification).when(mockDataTreeModification).getRootNode(); Link mockLink = mock(Link.class); doReturn(mockLink).when(mockModification).getDataAfter(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); listener.onDataTreeChanged(Collections.singletonList(mockDataTreeModification)); verify(mockAdapter).ofLinkAdded(mockLink); }