### Question:
EPForwardingTemplateListenerImpl implements EPTemplateListener<EndpointForwardingTemplateBySubnet> { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointForwardingTemplateBySubnet>> collection) { for (DataTreeModification<EndpointForwardingTemplateBySubnet> change : collection) { LOG.trace("received modification: {} -> {}", change.getRootPath(), change.getRootNode().getModificationType()); final InstanceIdentifier<EndpointForwardingTemplateBySubnet> changePath = change.getRootPath().getRootIdentifier(); final IpPrefix changeKey = changePath.firstKeyOf(EndpointForwardingTemplateBySubnet.class).getIpPrefix(); SxpListenerUtil.updateCachedDao(templateCachedDao, changeKey, change); final EndpointForwardingTemplateBySubnet epForwardingTemplate = change.getRootNode().getDataAfter(); if (epForwardingTemplate == null) { LOG.debug("EPForwarding template removed - NOOP {}", change.getRootNode().getDataBefore()); } else { processWithEPTemplates(epForwardingTemplate); } } } EPForwardingTemplateListenerImpl(final DataBroker dataBroker,
                                            final SxpMapperReactor sxpMapperReactor,
                                            final SimpleCachedDao<IpPrefix, EndpointForwardingTemplateBySubnet> templateCachedDao,
                                            final DSAsyncDao<IpPrefix, MasterDatabaseBinding> masterDBBindingDao,
                                            final DSAsyncDao<Sgt, EndpointPolicyTemplateBySgt> epPolicyTemplateDao); @Override void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<EndpointForwardingTemplateBySubnet>> collection); @Override void close(); static final FutureCallback<RpcResult<Void>> ANY_RPC_FUTURE_CALLBACK; }### Answer:
@Test public void testOnDataTreeChanged() throws Exception { Mockito.when(dataTreeModification.getRootNode()).thenReturn(dataObjectModification); Mockito.when(dataTreeModification.getRootPath()).thenReturn(TEMPLATE_TREE_PATH); Mockito.when(dataObjectModification.getDataAfter()).thenReturn(EP_FW_TEMPLATE_VALUE); final IpPrefix ipPrefix = buildIpPrefix("1.2.3.4/32"); final MasterDatabaseBinding masterDBBinding = new MasterDatabaseBindingBuilder() .setSecurityGroupTag(SGT) .setIpPrefix(ipPrefix) .build(); Mockito.when(masterDBBindingDao.read(Matchers.<IpPrefix>any())).thenReturn( Futures.immediateFuture(Optional.of(masterDBBinding))); Mockito.when(epPolicyTemplateDao.read(Matchers.<Sgt>any())).thenReturn( Futures.immediateFuture(Optional.of(EP_POLICY_TEMPLATE))); Mockito.when(sxpMapper.processTemplatesAndSxpMasterDB(Matchers.<EndpointPolicyTemplateBySgt>any(), Matchers.<EndpointForwardingTemplateBySubnet>any(),Matchers.<MasterDatabaseBinding>any())).thenReturn( RpcResultBuilder.success((Void) null).buildFuture()); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); final InOrder inOrder = Mockito.inOrder(masterDBBindingDao, simpleCachedDao, epPolicyTemplateDao, sxpMapper); inOrder.verify(simpleCachedDao).update(IP_PREFIX_TMPL, EP_FW_TEMPLATE_VALUE); inOrder.verify(masterDBBindingDao).read(IP_PREFIX_TMPL); inOrder.verify(epPolicyTemplateDao).read(SGT); inOrder.verify(sxpMapper).processTemplatesAndSxpMasterDB(EP_POLICY_TEMPLATE, EP_FW_TEMPLATE_VALUE, masterDBBinding); inOrder.verifyNoMoreInteractions(); }