From f390738a5186db535867b28be0624cd7f3e456ce Mon Sep 17 00:00:00 2001 From: Julien Herr Date: Sat, 17 Feb 2024 11:14:58 +0100 Subject: [PATCH] chore: Fix warning --- src/main/java/org/testng/TestNGAntTask.java | 39 ++++++++++++--------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/testng/TestNGAntTask.java b/src/main/java/org/testng/TestNGAntTask.java index 9fa523a..fb313ec 100644 --- a/src/main/java/org/testng/TestNGAntTask.java +++ b/src/main/java/org/testng/TestNGAntTask.java @@ -28,10 +28,7 @@ import java.nio.file.Paths; import java.text.CharacterIterator; import java.text.StringCharacterIterator; -import java.util.Enumeration; -import java.util.List; -import java.util.Properties; -import java.util.StringTokenizer; +import java.util.*; import static java.lang.Boolean.TRUE; import static org.testng.internal.Utils.isStringNotBlank; @@ -112,8 +109,8 @@ public class TestNGAntTask extends Task { protected File m_testjar; protected File m_workingDir; private Integer m_timeout; - private List m_listeners = Lists.newArrayList(); - private List m_methodselectors = Lists.newArrayList(); + private final List m_listeners = Lists.newArrayList(); + private final List m_methodselectors = Lists.newArrayList(); private String m_objectFactory; protected String m_testRunnerFactory; private boolean m_delegateCommandSystemProperties = false; @@ -166,7 +163,7 @@ public enum Mode { private static final Logger LOGGER = Logger.getLogger(TestNGAntTask.class); /** The list of report listeners added via <reporter> sub-element of the Ant task */ - private List reporterConfigs = Lists.newArrayList(); + private final List reporterConfigs = Lists.newArrayList(); private String m_testNames = ""; @@ -579,6 +576,14 @@ protected List createArguments() { addReporterConfigs(argv); addIntegerIfNotNull(argv, CommandLineArgs.SUITE_THREAD_POOL_SIZE, m_suiteThreadPoolSize); addStringIfNotNull(argv, CommandLineArgs.XML_PATH_IN_JAR, m_xmlPathInJar); + switch (mode) { + case junit: + addBooleanIfTrue(argv, CommandLineArgs.JUNIT, TRUE); + break; + case mixed: + addBooleanIfTrue(argv, CommandLineArgs.MIXED, TRUE); + break; + } addXmlFiles(argv); return argv; } @@ -680,9 +685,9 @@ protected List getSuiteFileNames() { private void delegateCommandSystemProperties() { // Iterate over command-line args and pass them through as sysproperty // exclude any built-in properties that start with "ant." - for (Object propKey : getProject().getUserProperties().keySet()) { - String propName = (String) propKey; - String propVal = getProject().getUserProperty(propName); + for (Map.Entry propEntry : getProject().getUserProperties().entrySet()) { + String propName = propEntry.getKey(); + String propVal = (String) propEntry.getValue(); if (propName.startsWith("ant.")) { log("Excluding ant property: " + propName + ": " + propVal, Project.MSG_DEBUG); } else { @@ -699,7 +704,7 @@ private void printDebugInfo(String fileName) { if (m_dumpSys) { debug("* SYSTEM PROPERTIES *"); Properties props = System.getProperties(); - Enumeration en = props.propertyNames(); + Enumeration en = props.propertyNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); debug(key + ": " + props.getProperty(key)); @@ -868,13 +873,13 @@ protected ExecuteWatchdog createWatchdog() /*throws BuildException*/ { protected void validateOptions() throws BuildException { int suiteCount = getSuiteFileNames().size(); if (suiteCount == 0 - && m_classFilesets.size() == 0 + && m_classFilesets.isEmpty() && Utils.isStringEmpty(m_methods) && ((null == m_testjar) || !m_testjar.isFile())) { throw new BuildException("No suites, classes, methods or jar file was specified."); } - if ((null != m_includedGroups) && (m_classFilesets.size() == 0 && suiteCount == 0)) { + if ((null != m_includedGroups) && (m_classFilesets.isEmpty() && suiteCount == 0)) { throw new BuildException("No class filesets or xml file sets specified while using groups"); } @@ -907,7 +912,7 @@ private FileSet appendClassSelector(FileSet fs) { } private File findJar() { - Class thisClass = getClass(); + Class thisClass = getClass(); String resource = thisClass.getName().replace('.', '/') + ".class"; URL url = thisClass.getClassLoader().getResource(resource); @@ -985,7 +990,7 @@ private String fromURI(String uri) { * * @param resources - A list of {@link ResourceCollection} * @return the list of files corresponding to the resource collection - * @throws BuildException + * @throws BuildException if the resource collection is not a file resource */ private List getFiles(List resources) throws BuildException { List files = Lists.newArrayList(); @@ -1069,8 +1074,8 @@ protected void handleOutput(String output) { private static class TestNGLogOS extends LogOutputStream { - private Task task; - private boolean verbose; + private final Task task; + private final boolean verbose; public TestNGLogOS(Task task, int level, boolean verbose) { super(task, level);