CnATreeElementLabelGenerator { public static String getElementTitle(CnATreeElement element) { if (element instanceof Safeguard) { Safeguard safeguard = (Safeguard) element; return createTitleForElementWithSecurityLevel(safeguard.getIdentifier(), safeguard.getSecurityLevel(), safeguard.getTitle()); } else if (element instanceof BpRequirement) { BpRequirement requirement = (BpRequirement) element; return createTitleForElementWithSecurityLevel(requirement.getIdentifier(), requirement.getSecurityLevel(), requirement.getTitle()); } else if (element instanceof IIdentifiableElement) { return ((IIdentifiableElement) element).getFullTitle(); } StringBuilder sb = new StringBuilder(); if (element instanceof IAbbreviatedElement) { String abbreviation = ((IAbbreviatedElement) element).getAbbreviation(); if (!StringUtils.isEmpty(abbreviation)) { sb.append(abbreviation); sb.append(" "); } } String title = element.getTitle(); if (!StringUtils.isEmpty(title)) { sb.append(title); } return sb.toString(); } private  CnATreeElementLabelGenerator(); static String getElementTitle(CnATreeElement element);  }
@Test public void titleIsReturnedIfIdentifierIsEmpty() { ItSystem itSystem = new ItSystem(null); itSystem.setPropertyValue(ItSystem.PROP_NAME, "Server 1"); Assert.assertEquals("Server 1", CnATreeElementLabelGenerator.getElementTitle(itSystem)); }
@Test public void identifierIsReturnedIfTitleIsEmpty() { ItSystem itSystem = new ItSystem(null); itSystem.setPropertyValue(ItSystem.PROP_NAME, null); itSystem.getEntity() .setSimpleValue(itSystem.getEntityType().getPropertyType(ItSystem.PROP_ABBR), "S1"); Assert.assertEquals("S1 ", CnATreeElementLabelGenerator.getElementTitle(itSystem)); }
@Test public void identifierIsIncluded() { ItSystem itSystem = new ItSystem(null); itSystem.setPropertyValue(ItSystem.PROP_NAME, "Server 1"); itSystem.getEntity() .setSimpleValue(itSystem.getEntityType().getPropertyType(ItSystem.PROP_ABBR), "S1"); Assert.assertEquals("S1 Server 1", CnATreeElementLabelGenerator.getElementTitle(itSystem)); }
@Test public void requirementWithoutIdentifier() { BpRequirement requirement = new BpRequirement(null); Assert.assertEquals("[] Baustein-Anforderung", CnATreeElementLabelGenerator.getElementTitle(requirement)); }