RemoveEmptyLists extends Visitor { public void removeEmptyLists(TTopologyTemplate topologyTemplate) { final TPolicies policies = topologyTemplate.getPolicies(); if ((policies != null) && policies.getPolicy().isEmpty()) { topologyTemplate.setPolicies(null); } this.visit(topologyTemplate); }  @Override void visit(TEntityTemplate entityTemplate); @Override void visit(TNodeTemplate nodeTemplate); @Override void visit(TRelationshipTemplate relationshipTemplate); void removeEmptyLists(TTopologyTemplate topologyTemplate);  }
@Test public void emptyPropertiesAndPoliciesListsRemovedFromNodeTemplate() { TTopologyTemplate topologyTemplate = new TTopologyTemplate(); TNodeTemplate nodeTemplate = new TNodeTemplate(); topologyTemplate.getNodeTemplateOrRelationshipTemplate().add(nodeTemplate); nodeTemplate.setProperties(new TEntityTemplate.Properties()); nodeTemplate.setPolicies(new TPolicies()); assertNotNull(((TNodeTemplate) topologyTemplate.getNodeTemplateOrRelationshipTemplate().get(0)).getPolicies()); assertNotNull(((TNodeTemplate) topologyTemplate.getNodeTemplateOrRelationshipTemplate().get(0)).getProperties()); RemoveEmptyLists removeEmptyLists = new RemoveEmptyLists(); removeEmptyLists.removeEmptyLists(topologyTemplate); assertNull(((TNodeTemplate) topologyTemplate.getNodeTemplateOrRelationshipTemplate().get(0)).getPolicies()); assertNull(((TNodeTemplate) topologyTemplate.getNodeTemplateOrRelationshipTemplate().get(0)).getProperties()); }