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