AttributeHelper { public String extractAttributeValueString(Attribute attrib) { StringBuilder strBuilder = new StringBuilder(); if (attrib != null) { List<XMLObject> attrVals = attrib.getAttributeValues(); for (Object o : attrVals) { if (o instanceof org.w3c.dom.Element) { org.w3c.dom.Element elem = (org.w3c.dom.Element) o; strBuilder.append(elem.getTextContent()); break; } else if (o instanceof String) { strBuilder.append(o).append(" "); } else if (o instanceof XSStringImpl) { strBuilder.append(((XSStringImpl) o).getValue()); } else if (o instanceof XSAnyImpl) { strBuilder.append(((XSAnyImpl) o).getTextContent()); } } } return strBuilder.toString().trim(); }  CeType extractNhinCodedElement(Attribute attrib, String codeId); String extractAttributeValueString(Attribute attrib); void extractNameParts(Attribute attrib, AssertionType assertOut);  }
@Test public final void testExtractAttributeValueString() { Attribute attrib = mock(Attribute.class); List<XMLObject> attrVals = new ArrayList<>(); XSStringImpl mockStringValue = mock(XSStringImpl.class); when(mockStringValue.getValue()).thenReturn("ONC Team"); attrVals.add(mockStringValue); when(attrib.getAttributeValues()).thenReturn(attrVals); String result = helper.extractAttributeValueString(attrib); Assert.assertEquals("ONC Team", result); }
@Test public final void testExtractAttributeValueAnyString() { final String testValue = "ONC Team"; Attribute attrib = mock(Attribute.class); List<XMLObject> attrVals = new ArrayList<>(); XSAnyImpl mockAnyValue = mock(XSAnyImpl.class); when(mockAnyValue.getTextContent()).thenReturn(testValue); attrVals.add(mockAnyValue); when(attrib.getAttributeValues()).thenReturn(attrVals); String result = helper.extractAttributeValueString(attrib); Assert.assertEquals(testValue, result); }