XmlSettingsReader { public List<String> getStringListProperty(String tagName) { List<String> propertyStrings = new ArrayList<>(); NodeList propertyList = doc.getElementsByTagName(tagName); if (propertyList.getLength() == 0) { return propertyStrings; } if (propertyList.item(0).getNodeType() == Node.ELEMENT_NODE) { Element parentElement = (Element) propertyList.item(0); NodeList childProperties = parentElement.getElementsByTagName("param"); for (int i = 0; i < childProperties.getLength(); i++) { propertyStrings.add(childProperties.item(i).getTextContent().trim()); } } return propertyStrings; } XmlSettingsReader(String xmlString); int getIntProperty(String xPathExp, String tagName, int defaultVal); String getStringPropertyByXPath(String xPathExp, String tagName); String getStringPropertyByXPath(String xPathExp, String tagName, String defaultVal); boolean getBooleanProperty(String xPathExp, String tagName, boolean defaultVal); String getStringProperty(String tagName); File getFileProperty(String tagName); String getStringProperty(String tagName, String defaultValue); List<String> getStringListProperty(String tagName); Map<String, Boolean> getStringKeyedBooleanMapProperty(String tagName); Map<String, T> getStringKeyedMapProperty(String tagName, Function<String, T> mapFunction); T getComplexType(String tagName, Class<T> targetClass);  }
@Test public void readStringListProperty() throws Exception { String stringItem1 = prepareElement(PARAM_TAG, stringValue); String stringItem2 = prepareElement(PARAM_TAG, DEFAULT_STRING); String stringListXml = prepareElement(STRING_TAG, stringItem1 + stringItem2); xsr = new XmlSettingsReader(stringListXml); List<String> readStringListProperty = xsr.getStringListProperty(STRING_TAG); assertEquals(2, readStringListProperty.size()); assertTrue(readStringListProperty .stream() .anyMatch(e -> e.equals(stringValue))); assertTrue(readStringListProperty .stream() .anyMatch(e -> e.equals(DEFAULT_STRING))); }