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