All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.xml.XmlUtils Maven / Gradle / Ivy

There is a newer version: 7.10.1
Show newest version
package org.testng.xml;

import org.testng.internal.Utils;
import org.testng.reporters.XMLStringBuffer;

import java.util.Map;
import java.util.Properties;

public class XmlUtils {

  /** Don't add this property if it's equal to its default value. */
  public static void setProperty(Properties p, String name, String value, String def) {
    if (!def.equals(value) && value != null) {
      p.setProperty(name, value);
    }
  }

  public static void dumpParameters(XMLStringBuffer xsb, Map parameters) {
    // parameters
    if (parameters.isEmpty()) {
      return;
    }
    for (Map.Entry para : parameters.entrySet()) {
      Properties paramProps = new Properties();
      if (para.getKey() == null) {
        Utils.log("Skipping a null parameter.");
        continue;
      }
      if (para.getValue() == null) {
        String msg =
            String.format("Skipping parameter [%s] since it has a null value", para.getKey());
        Utils.log(msg);
        continue;
      }
      paramProps.setProperty("name", para.getKey());
      paramProps.setProperty("value", para.getValue());
      xsb.addEmptyElement("parameter", paramProps); // BUGFIX: TESTNG-27
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy