PhysicalNetworkAdapter { protected void ofLinkRemoved(Link link) { log.debug("OF link removed:{}.", link.getKey()); String strLinkId = link.getLinkId().getValue(); PhysicalLinkId linkId = new PhysicalLinkId(strLinkId); PhysicalLink confPhyLink = phyConfigLoader.getPhysicalLink(linkId); if (confPhyLink == null) { log.warn("Can not find conf info of {} while remove.", link); } dataBrokerAdapter.removePhysicalLink(new PhysicalLinkKey(linkId)); } PhysicalNetworkAdapter(DataBroker dataBroker
            , NotificationProviderService notificationProviderService
            , PhyConfigLoader phyConfigLoader
            , FlowUtils ofFlowUtils); void close(); PhyConfigLoader getPhyConfigLoader();  }
@Test public void testOfLinkRemoved() throws Exception { Class<PhysicalNetworkAdapter> class1 = PhysicalNetworkAdapter.class; Method method = class1.getDeclaredMethod("ofLinkRemoved", new Class[]{Link.class}); method.setAccessible(true); Link link = mock(Link.class); LinkKey linkKey = mock(LinkKey.class); LinkId linkId = mock(LinkId.class); PhysicalLink physicalLink = mock(PhysicalLink.class); WriteTransaction writeTransaction = mock(WriteTransaction.class); InstanceIdentifier instanceIdentifier = mock(InstanceIdentifier.class); CheckedFuture checkedFuture = mock(CheckedFuture.class); when(link.getKey()).thenReturn(linkKey); when(link.getLinkId()).thenReturn(linkId); when(linkId.getValue()).thenReturn(new String("1")); when(phyConfigLoader.getPhysicalLink(any(PhysicalLinkId.class))) .thenReturn(null) .thenReturn(physicalLink); when(dataBroker.newWriteOnlyTransaction()).thenReturn(writeTransaction); when(writeTransaction.submit()).thenReturn(checkedFuture); method.invoke(physicalNetworkAdapter, link); method.invoke(physicalNetworkAdapter, link); verify(phyConfigLoader,times(2)).getPhysicalLink(any(PhysicalLinkId.class)); verify(writeTransaction,times(2)).submit(); }