BuilderUtils { public static Element buildPropertiesElement(final Map<String, Object> properties, final Document document) { return buildPropertiesElement(properties, document, PROPERTIES); } private  BuilderUtils(); static void buildAndAppendPropertiesElement(final Map<String, Object> properties, final Document document, final Element elementToAppendInto); static Element buildPropertiesElement(final Map<String, Object> properties, final Document document); static Element buildPropertiesElement(final Map<String, Object> properties, final Document document, final String propertiesElementName); @NotNull static Element createPropertyElement(Document document, String key, Object value); static Map<String, Object> mapPropertiesElements(final Element propertiesElement, final String propertiesElementName); static String insertPrefixToEnvironmentVariable(String environmentVariable, String prefix); static String removeAllSpecialChars(String str);  }
@Test void buildPropertiesElement() throws ParserConfigurationException { Element properties = BuilderUtils.buildPropertiesElement(new HashMap<String, Object>() {{ put("keyString", "value1"); put("keyInteger", 1); put("keyLong", 1L); put("keyBoolean", true); }}, DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); NodeList propertyNodes = properties.getElementsByTagName("l7:Property"); for (Node property : DocumentUtils.nodeList(propertyNodes)) { Node key = property.getAttributes().getNamedItem("key"); switch (key.getTextContent()) { case "keyString": NodeList valueString = ((Element) property).getElementsByTagName(STRING_VALUE); assertEquals("value1", valueString.item(0).getTextContent()); break; case "keyInteger": NodeList valueInt = ((Element) property).getElementsByTagName(INTEGER_VALUE); assertEquals(1, Integer.valueOf(valueInt.item(0).getTextContent()).intValue()); break; case "keyLong": NodeList valueLong = ((Element) property).getElementsByTagName(LONG_VALUE); assertEquals(1L, Long.valueOf(valueLong.item(0).getTextContent()).longValue()); break; case "keyBoolean": NodeList valueBoolean = ((Element) property).getElementsByTagName(BOOLEAN_VALUE); assertEquals(true, Boolean.valueOf(valueBoolean.item(0).getTextContent())); break; default: fail("Unexpected key " + key.getTextContent()); } } }
@Test void buildPropertiesElementEmptyProperties() throws ParserConfigurationException { Element properties = BuilderUtils.buildPropertiesElement(new HashMap<>(), DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()); NodeList propertyNodes = properties.getElementsByTagName("l7:Property"); assertEquals(0, propertyNodes.getLength()); }