### Question:
MasterDatabaseBindingListenerImpl implements MasterDatabaseBindingListener { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<MasterDatabaseBinding>> collection) { for (DataTreeModification<MasterDatabaseBinding> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final MasterDatabaseBinding sxpMasterDBItem = change.getRootNode().getDataAfter(); if (sxpMasterDBItem == null) { LOG.debug("ip-sgt mapping was removed - NOOP: {}", change.getRootPath().getRootIdentifier().firstKeyOf(MasterDatabaseBinding.class)); } else { final IpPrefix ipPrefixKey = sxpMasterDBItem.getIpPrefix(); SxpListenerUtil.updateCachedDao(masterDBBindingDaoCached, ipPrefixKey, change); processWithEPTemplates(sxpMasterDBItem); } } } MasterDatabaseBindingListenerImpl(final DataBroker dataBroker,
                                             final SxpMapperReactor sxpMapperReactor,
                                             final SimpleCachedDao<IpPrefix, MasterDatabaseBinding> masterDBBindingDaoCached,
                                             final DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt> epPolicyTemplateDao,
                                             final DSAsyncDao<IpPrefix, EndpointForwardingTemplateBySubnet> epForwardingTemplateDao); @Override void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<MasterDatabaseBinding>> collection); @Override void close(); static final FutureCallback<RpcResult<Void>> RPC_FW_RESULT_FUTURE_CALLBACK; }### Answer:
@Test public void testOnDataTreeChanged() throws Exception { Mockito.when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); Mockito.when(dataTreeModification.getRootPath()).thenReturn(MASTER_DB_BINDING_TREE_PATH); Mockito.when(dataObjectModification.getDataAfter()).thenReturn(MASTER_DB_BINDING_VALUE); final EndpointPolicyTemplateBySgt epPolicyTemplate = new EndpointPolicyTemplateBySgtBuilder() .setSgt(SGT_1) .build(); Mockito.when(epPolicyTemplateDao.read(Matchers.<Sgt>any())).thenReturn( Futures.immediateFuture(Optional.of(epPolicyTemplate))); final IpPrefix ipPrefixSubnet = new IpPrefix(new Ipv4Prefix("1.2.3.0/24")); final EndpointForwardingTemplateBySubnet epForwardingTemplate = new EndpointForwardingTemplateBySubnetBuilder() .setIpPrefix(ipPrefixSubnet) .build(); Mockito.when(epForwardingTemplateDao.read(Matchers.<IpPrefix>any())).thenReturn( Futures.immediateFuture(Optional.of(epForwardingTemplate))); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); final InOrder inOrder = Mockito.inOrder(cachedDao, epPolicyTemplateDao, epForwardingTemplateDao, sxpMapper); inOrder.verify(cachedDao).update(IP_PREFIX, MASTER_DB_BINDING_VALUE); inOrder.verify(epPolicyTemplateDao).read(SGT_1); inOrder.verify(epForwardingTemplateDao).read(IP_PREFIX); inOrder.verify(sxpMapper).processTemplatesAndSxpMasterDB(epPolicyTemplate, epForwardingTemplate, MASTER_DB_BINDING_VALUE); inOrder.verifyNoMoreInteractions(); }