PhysicalNetworkAdapter { private FlowCapableNodeConnector getOFPort(final NodeKey nodeKey, final NodeConnectorKey nodeConnectorKey) { final FlowCapableNodeConnector[] flowCapableNodeConnector = {null}; InstanceIdentifier<NodeConnector> nodeConnectorInsId = getOFPortInstanceIdentifier(nodeKey, nodeConnectorKey); final CountDownLatch downLatch = new CountDownLatch(1); ListenableFuture<Optional<NodeConnector>> nodeConnectorFuture = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, nodeConnectorInsId); Futures.addCallback(nodeConnectorFuture, new FutureCallback<Optional<NodeConnector>>() { @Override public void onSuccess(Optional<NodeConnector> result) { if (result.isPresent() && result.get() instanceof NodeConnector) { flowCapableNodeConnector[0] = result.get().getAugmentation(FlowCapableNodeConnector.class); downLatch.countDown(); } return; } @Override public void onFailure(Throwable t) { log.error("Can not read the information of node connector {}-{} : {}", nodeKey, nodeConnectorKey, t); downLatch.countDown(); return; } }); try { downLatch.await(); } catch (InterruptedException e) { log.error("Exception:",e); } return flowCapableNodeConnector[0]; } PhysicalNetworkAdapter(DataBroker dataBroker
            , NotificationProviderService notificationProviderService
            , PhyConfigLoader phyConfigLoader
            , FlowUtils ofFlowUtils); void close(); PhyConfigLoader getPhyConfigLoader();  }
@Test public void testGetOFPort() throws Exception{ Class<PhysicalNetworkAdapter> class1 = PhysicalNetworkAdapter.class; Method method = class1.getDeclaredMethod("getOFPort", new Class[]{NodeKey.class,NodeConnectorKey.class}); method.setAccessible(true); NodeKey nodeKey = mock(NodeKey.class); NodeConnectorKey connectorKey = mock(NodeConnectorKey.class); CheckedFuture checkedFuture_read = mock(CheckedFuture.class); ReadOnlyTransaction readOnlyTransaction = mock(ReadOnlyTransaction.class); when(dataBroker.newReadOnlyTransaction()).thenReturn(readOnlyTransaction); when(readOnlyTransaction.read(any(LogicalDatastoreType.class),any(InstanceIdentifier.class))).thenReturn(checkedFuture_read); }