### Question:
RendererConfigurationListenerImpl implements ClusteredDataTreeChangeListener<RendererPolicy>, AutoCloseable { @Override public void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<RendererPolicy>> collection) { LOG.debug("renderer policy configuration changed"); for (DataTreeModification<RendererPolicy> rendererPolicyDataTreeModification : collection) { final DataObjectModification<RendererPolicy> rootNode = rendererPolicyDataTreeModification.getRootNode(); final RendererPolicy dataBefore = rootNode.getDataBefore(); final RendererPolicy dataAfter = rootNode.getDataAfter(); Configuration oldConfig = null; Configuration newConfig = null; long version = 0; if (dataBefore != null) { oldConfig = dataBefore.getConfiguration(); } if (dataAfter != null) { newConfig = dataAfter.getConfiguration(); if (dataAfter.getVersion() != null) { version = dataAfter.getVersion(); } } policyManager.syncPolicy(newConfig, oldConfig, version); } } RendererConfigurationListenerImpl(final DataBroker dataBroker,
                                             final PolicyManager policyManager); @Override void onDataTreeChanged(@Nonnull final Collection<DataTreeModification<RendererPolicy>> collection); @Override void close();  }### Answer:
@Test public void testOnDataTreeChanged_add() throws Exception { Mockito.when(rootNode.getDataBefore()).thenReturn(null); Mockito.when(rootNode.getDataAfter()).thenReturn(policy1); Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); Mockito.verify(policyManager).syncPolicy(policy1.getConfiguration(), null, 0); }
@Test public void testOnDataTreeChanged_update() throws Exception { Mockito.when(rootNode.getDataBefore()).thenReturn(policy1); Mockito.when(rootNode.getDataAfter()).thenReturn(policy2); Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); Mockito.verify(policyManager).syncPolicy(policy2.getConfiguration(), policy1.getConfiguration(), 1); }
@Test public void testOnDataTreeChanged_remove() throws Exception { Mockito.when(rootNode.getDataBefore()).thenReturn(policy2); Mockito.when(rootNode.getDataAfter()).thenReturn(createVersion(1)); Mockito.when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE); Mockito.when(dataTreeModification.getRootNode()).thenReturn(rootNode); listener.onDataTreeChanged(Collections.singleton(dataTreeModification)); Mockito.verify(policyManager).syncPolicy(null, policy2.getConfiguration(), 1); }