### Question:
FlowCapableNodeListener implements DataTreeChangeListener<FlowCapableNode>, AutoCloseable { @Override public void onDataTreeChanged(Collection<DataTreeModification<FlowCapableNode>> changes) { for (DataTreeModification<FlowCapableNode> change: changes) { DataObjectModification<FlowCapableNode> rootNode = change.getRootNode(); NodeId nodeId = change.getRootPath().getRootIdentifier().firstKeyOf(Node.class, NodeKey.class).getId(); switch (rootNode.getModificationType()) { case SUBTREE_MODIFIED: case WRITE: FlowCapableNode fcNode = rootNode.getDataAfter(); LOG.trace("FlowCapableNode updated. NodeId: {} FlowCapableNode: {}", nodeId.getValue(), fcNode); switchManager.updateSwitch(nodeId, fcNode); break; case DELETE: LOG.trace("FlowCapableNode removed. NodeId: {}", nodeId.getValue()); switchManager.updateSwitch(nodeId, null); break; default: break; } } } FlowCapableNodeListener(DataBroker dataProvider, SwitchManager switchManager); @Override void onDataTreeChanged(Collection<DataTreeModification<FlowCapableNode>> changes); @Override void close();  }### Answer:
@SuppressWarnings("unchecked") @Test public void onDataChangeTestCreatedData() { FlowCapableNode entryValue = mock(FlowCapableNode.class); NodeId childNodeId = mock(NodeId.class); InstanceIdentifier<FlowCapableNode> entryKey = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(childNodeId)) .augmentation(FlowCapableNode.class) .build(); doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, entryKey)).when(mockDataTreeModification) .getRootPath(); doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType(); doReturn(entryValue).when(mockModification).getDataAfter(); listener.onDataTreeChanged(changeEvent); verify(switchManager).updateSwitch(childNodeId, entryValue); }
@SuppressWarnings("unchecked") @Test public void onDataChangeTestUpdatedData() { FlowCapableNode entryValue = mock(FlowCapableNode.class); NodeId childNodeId = mock(NodeId.class); InstanceIdentifier<FlowCapableNode> entryKey = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(childNodeId)) .augmentation(FlowCapableNode.class) .build(); doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, entryKey)).when(mockDataTreeModification) .getRootPath(); doReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED).when(mockModification).getModificationType(); doReturn(entryValue).when(mockModification).getDataAfter(); listener.onDataTreeChanged(changeEvent); verify(switchManager).updateSwitch(childNodeId, entryValue); }
@SuppressWarnings("unchecked") @Test public void onDataChangeTestRemovedPaths() { NodeId childNodeId = mock(NodeId.class); InstanceIdentifier<FlowCapableNode> entryKey = InstanceIdentifier.builder(Nodes.class) .child(Node.class, new NodeKey(childNodeId)) .augmentation(FlowCapableNode.class) .build(); doReturn(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, entryKey)).when(mockDataTreeModification) .getRootPath(); doReturn(DataObjectModification.ModificationType.DELETE).when(mockModification).getModificationType(); listener.onDataTreeChanged(changeEvent); verify(switchManager).updateSwitch(childNodeId, null); }