DataBrokerAdapter { protected boolean addPhysicalNode(final PhysicalNode physicalNode){ final boolean[] addResult = {false}; try { WriteTransaction t = dataBroker.newWriteOnlyTransaction(); InstanceIdentifier<PhysicalNode> identifier = getPhysicalNodeIdentifier(physicalNode.getKey()); t.put(LogicalDatastoreType.OPERATIONAL, identifier, physicalNode, true); CheckedFuture<Void, TransactionCommitFailedException> future = t.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onFailure(Throwable t) { log.warn("Could not write PhysicalNode {} : {}",physicalNode, t); } @Override public void onSuccess(Void result) { addResult[0] = true; log.debug("write transaction onSuccess."); } }); } catch (Exception e) { log.error("Exception:",e); } return addResult[0]; } DataBrokerAdapter(DataBroker dataBroker);   }
@Test public void testAddPhysicalNode() throws Exception { final PhysicalNode physicalNode = mock(PhysicalNode.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); PhysicalNodeKey physicalNodeKey = mock(PhysicalNodeKey.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); Class<DataBrokerAdapter> class1 = DataBrokerAdapter.class; Method method = class1.getDeclaredMethod("addPhysicalNode",new Class[]{PhysicalNode.class}); method.setAccessible(true); when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(physicalNode.getKey()).thenReturn(physicalNodeKey); when(writeTransaction.submit()).thenReturn(checkedFuture); Assert.assertNotNull(method.invoke(dataBrokerAdapter, physicalNode)); verify(dataBroker).newWriteOnlyTransaction(); verify(physicalNode).getKey(); verify(writeTransaction).submit(); }