### Question:
SupportedClassifierDefinitionListener extends DataTreeChangeHandler<SupportedClassifierDefinition> { @VisibleForTesting static ClassifierDefinition createClassifierDefinitionWithUnionOfParams(ClassifierDefinition cd, List<ParameterName> supportedParams) { if (supportedParams == null || supportedParams.isEmpty()) { LOG.debug("Classifier-definition with ID {} is not supported by any renderer.", cd.getId().getValue()); return null; } if (cd.getParameter() == null || cd.getParameter().isEmpty()) { LOG.trace("Classifier-definition with ID {} does not contain any parameter in CONF datastore.", cd.getId().getValue()); return cd; } List<Parameter> params = new ArrayList<>(); for (ParameterName supportedParam : supportedParams) { for (Parameter param : cd.getParameter()) { if (param.getName().equals(supportedParam)) { params.add(param); } } } ClassifierDefinitionBuilder cdBuilder = new ClassifierDefinitionBuilder(cd); return cdBuilder.setParameter(params).build(); } SupportedClassifierDefinitionListener(DataBroker dataProvider, PolicyValidatorRegistry validatorRegistry);   }### Answer:
@Test public void testCreateClassifierDefinitionWithUnionOfParams_allSupportedParams() { List<ParameterName> supportedParams = ImmutableList.of(new ParameterName(EtherTypeClassifierDefinition.ETHERTYPE_PARAM)); ClassifierDefinition classifierDefinitionWithUnionOfParams = listener .createClassifierDefinitionWithUnionOfParams(EtherTypeClassifierDefinition.DEFINITION, supportedParams); assertEquals(EtherTypeClassifierDefinition.DEFINITION, classifierDefinitionWithUnionOfParams); }
@Test public void testCreateClassifierDefinitionWithUnionOfParams_emptySupportedParams() { List<ParameterName> supportedParams = ImmutableList.of(); ClassifierDefinition classifierDefinitionWithUnionOfParams = listener .createClassifierDefinitionWithUnionOfParams(EtherTypeClassifierDefinition.DEFINITION, supportedParams); Assert.assertNull(classifierDefinitionWithUnionOfParams); }
@Test public void testCreateClassifierDefinitionWithUnionOfParams_someSupportedParams() { ImmutableList<ParameterName> supportedParams = ImmutableList.of(new ParameterName(L4ClassifierDefinition.DST_PORT_PARAM), new ParameterName(L4ClassifierDefinition.DST_PORT_RANGE_PARAM)); ClassifierDefinition classifierDefinitionWithUnionOfParams = listener .createClassifierDefinitionWithUnionOfParams(L4ClassifierDefinition.DEFINITION, supportedParams); ClassifierDefinition expectedCd = new ClassifierDefinitionBuilder(L4ClassifierDefinition.DEFINITION) .setParameter(ImmutableList.<Parameter>of( getParameterFromDefinition(L4ClassifierDefinition.DEFINITION, L4ClassifierDefinition.DST_PORT_PARAM), getParameterFromDefinition(L4ClassifierDefinition.DEFINITION, L4ClassifierDefinition.DST_PORT_RANGE_PARAM))) .build(); assertEquals(expectedCd, classifierDefinitionWithUnionOfParams); }