### Question:
SupportedClassifierDefinitionListener extends DataTreeChangeHandler<SupportedClassifierDefinition> { @VisibleForTesting void setParentValidators(ClassifierInstanceValidator ciValidator, boolean setParentToNull) { if (ciValidator.getParentClassifierDefinitionId() != null && !setParentToNull) { ClassifierInstanceValidator parentCiValidator = validatorByRendererAndCd.get(ciValidator.getRendererName(), ciValidator.getParentClassifierDefinitionId()); if (parentCiValidator != null) { ciValidator.setParentValidator(parentCiValidator); } } for (ClassifierInstanceValidator existingCiValidator : getValidatorsWithParentCdForRenderer( ciValidator.getClassifierDefinitionId(), ciValidator.getRendererName())) { if (setParentToNull) { existingCiValidator.setParentValidator(null); } else { existingCiValidator.setParentValidator(ciValidator); } } } SupportedClassifierDefinitionListener(DataBroker dataProvider, PolicyValidatorRegistry validatorRegistry);   }### Answer:
@Test public void testSetParentValidators_newValidatorHasParent_parentValidatorExists() { RendererName rendererFoo = new RendererName("Foo"); SupportedClassifierDefinition supportedIpProtoPort = new SupportedClassifierDefinitionBuilder() .setClassifierDefinitionId(IpProtoClassifierDefinition.ID).build(); ClassifierInstanceValidator rendererFooIpProtoParentValidator = new ClassifierInstanceValidator(supportedIpProtoPort, rendererFoo); listener.validatorByRendererAndCd.put(rendererFoo, IpProtoClassifierDefinition.ID, rendererFooIpProtoParentValidator); SupportedClassifierDefinition supportedL4SrcPort = new SupportedClassifierDefinitionBuilder().setClassifierDefinitionId(L4ClassifierDefinition.ID) .setParentClassifierDefinitionId(IpProtoClassifierDefinition.ID) .build(); ClassifierInstanceValidator rendererFooL4SrcPortNewValidator = new ClassifierInstanceValidator(supportedL4SrcPort, rendererFoo); listener.validatorByRendererAndCd.put(rendererFoo, L4ClassifierDefinition.ID, rendererFooL4SrcPortNewValidator); listener.setParentValidators(rendererFooL4SrcPortNewValidator, false); Assert.assertEquals(rendererFooIpProtoParentValidator, rendererFooL4SrcPortNewValidator.getParentValidator()); listener.setParentValidators(rendererFooL4SrcPortNewValidator, true); Assert.assertNull(rendererFooIpProtoParentValidator.getParentValidator()); }
@Test public void testSetParentValidators_newValidatorHasParent_parentValidatorNotExists() { RendererName rendererFoo = new RendererName("Foo"); SupportedClassifierDefinition supportedL4SrcPort = new SupportedClassifierDefinitionBuilder().setClassifierDefinitionId(L4ClassifierDefinition.ID) .setParentClassifierDefinitionId(IpProtoClassifierDefinition.ID) .build(); ClassifierInstanceValidator rendererFooL4SrcPortNewValidator = new ClassifierInstanceValidator(supportedL4SrcPort, rendererFoo); listener.validatorByRendererAndCd.put(rendererFoo, L4ClassifierDefinition.ID, rendererFooL4SrcPortNewValidator); listener.setParentValidators(rendererFooL4SrcPortNewValidator, false); Assert.assertNull(rendererFooL4SrcPortNewValidator.getParentValidator()); SupportedClassifierDefinition supportedIpProtoPort = new SupportedClassifierDefinitionBuilder() .setClassifierDefinitionId(IpProtoClassifierDefinition.ID).build(); ClassifierInstanceValidator rendererFooIpProtoParentValidator = new ClassifierInstanceValidator(supportedIpProtoPort, rendererFoo); listener.validatorByRendererAndCd.put(rendererFoo, IpProtoClassifierDefinition.ID, rendererFooIpProtoParentValidator); listener.setParentValidators(rendererFooL4SrcPortNewValidator, false); Assert.assertEquals(rendererFooIpProtoParentValidator, rendererFooL4SrcPortNewValidator.getParentValidator()); listener.setParentValidators(rendererFooL4SrcPortNewValidator, true); Assert.assertNull(rendererFooIpProtoParentValidator.getParentValidator()); }