Cleaned up Javadocs

This commit is contained in:
Erik C. Thauvin 2023-11-27 13:10:11 -08:00
parent e32abb231b
commit ef4a259a33
12 changed files with 518 additions and 96 deletions

204
.idea/intellij-javadocs-4.0.1.xml generated Normal file
View file

@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaDocConfiguration">
<GENERAL>
<MODE>UPDATE</MODE>
<OVERRIDDEN_METHODS>false</OVERRIDDEN_METHODS>
<SPLITTED_CLASS_NAME>true</SPLITTED_CLASS_NAME>
<LEVELS>
<LEVEL>TYPE</LEVEL>
<LEVEL>METHOD</LEVEL>
<LEVEL>FIELD</LEVEL>
</LEVELS>
<VISIBILITIES>
<VISIBILITY>PROTECTED</VISIBILITY>
<VISIBILITY>DEFAULT</VISIBILITY>
<VISIBILITY>PUBLIC</VISIBILITY>
</VISIBILITIES>
</GENERAL>
<TEMPLATES>
<CLASSES>
<CLASS>
<KEY>^.*(public|protected|private)*.+interface\s+\w+.*</KEY>
<VALUE>/**\n
* The interface ${name}.\n
&lt;#if element.typeParameters?has_content&gt; * \n
&lt;/#if&gt;
&lt;#list element.typeParameters as typeParameter&gt;
* @param &lt;${typeParameter.name}&gt; the type parameter\n
&lt;/#list&gt;
*/</VALUE>
</CLASS>
<CLASS>
<KEY>^.*(public|protected|private)*.+enum\s+\w+.*</KEY>
<VALUE>/**\n
* The enum ${name}.\n
*/</VALUE>
</CLASS>
<CLASS>
<KEY>^.*(public|protected|private)*.+class\s+\w+.*</KEY>
<VALUE>/**\n
* The type ${name}.\n
&lt;#if element.typeParameters?has_content&gt; * \n
&lt;/#if&gt;
&lt;#list element.typeParameters as typeParameter&gt;
* @param &lt;${typeParameter.name}&gt; the type parameter\n
&lt;/#list&gt;
*/</VALUE>
</CLASS>
<CLASS>
<KEY>.+</KEY>
<VALUE>/**\n
* The type ${name}.\n
*/</VALUE>
</CLASS>
</CLASSES>
<CONSTRUCTORS>
<CONSTRUCTOR>
<KEY>.+</KEY>
<VALUE>/**\n
* Instantiates a new ${name}.\n
&lt;#if element.parameterList.parameters?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.parameterList.parameters as parameter&gt;
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
&lt;/#list&gt;
&lt;#if element.throwsList.referenceElements?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.throwsList.referenceElements as exception&gt;
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
&lt;/#list&gt;
*/</VALUE>
</CONSTRUCTOR>
</CONSTRUCTORS>
<METHODS>
<METHOD>
<KEY>^.*(public|protected|private)*\s*.*(\w(\s*&lt;.+&gt;)*)+\s+get\w+\s*\(.*\).+</KEY>
<VALUE>/**\n
* Gets ${partName}.\n
&lt;#if element.typeParameters?has_content&gt; * \n
&lt;/#if&gt;
&lt;#list element.typeParameters as typeParameter&gt;
* @param &lt;${typeParameter.name}&gt; the type parameter\n
&lt;/#list&gt;
&lt;#if element.parameterList.parameters?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.parameterList.parameters as parameter&gt;
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
&lt;/#list&gt;
&lt;#if isNotVoid&gt;
*\n
* @return the ${partName}\n
&lt;/#if&gt;
&lt;#if element.throwsList.referenceElements?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.throwsList.referenceElements as exception&gt;
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
&lt;/#list&gt;
*/</VALUE>
</METHOD>
<METHOD>
<KEY>^.*(public|protected|private)*\s*.*(void|\w(\s*&lt;.+&gt;)*)+\s+set\w+\s*\(.*\).+</KEY>
<VALUE>/**\n
* Sets ${partName}.\n
&lt;#if element.typeParameters?has_content&gt; * \n
&lt;/#if&gt;
&lt;#list element.typeParameters as typeParameter&gt;
* @param &lt;${typeParameter.name}&gt; the type parameter\n
&lt;/#list&gt;
&lt;#if element.parameterList.parameters?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.parameterList.parameters as parameter&gt;
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
&lt;/#list&gt;
&lt;#if isNotVoid&gt;
*\n
* @return the ${partName}\n
&lt;/#if&gt;
&lt;#if element.throwsList.referenceElements?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.throwsList.referenceElements as exception&gt;
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
&lt;/#list&gt;
*/</VALUE>
</METHOD>
<METHOD>
<KEY>^.*((public\s+static)|(static\s+public))\s+void\s+main\s*\(\s*String\s*(\[\s*\]|\.\.\.)\s+\w+\s*\).+</KEY>
<VALUE>/**\n
* The entry point of application.\n
&lt;#if element.parameterList.parameters?has_content&gt;
*\n
&lt;/#if&gt;
* @param ${element.parameterList.parameters[0].name} the input arguments\n
&lt;#if element.throwsList.referenceElements?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.throwsList.referenceElements as exception&gt;
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
&lt;/#list&gt;
*/</VALUE>
</METHOD>
<METHOD>
<KEY>.+</KEY>
<VALUE>/**\n
* ${name}&lt;#if isNotVoid&gt; ${return}&lt;/#if&gt;.\n
&lt;#if element.typeParameters?has_content&gt; * \n
&lt;/#if&gt;
&lt;#list element.typeParameters as typeParameter&gt;
* @param &lt;${typeParameter.name}&gt; the type parameter\n
&lt;/#list&gt;
&lt;#if element.parameterList.parameters?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.parameterList.parameters as parameter&gt;
* @param ${parameter.name} the ${paramNames[parameter.name]}\n
&lt;/#list&gt;
&lt;#if isNotVoid&gt;
*\n
* @return the ${return}\n
&lt;/#if&gt;
&lt;#if element.throwsList.referenceElements?has_content&gt;
*\n
&lt;/#if&gt;
&lt;#list element.throwsList.referenceElements as exception&gt;
* @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
&lt;/#list&gt;
*/</VALUE>
</METHOD>
</METHODS>
<FIELDS>
<FIELD>
<KEY>^.*(public|protected|private)*.+static.*(\w\s\w)+.+</KEY>
<VALUE>/**\n
* The constant ${element.getName()}.\n
*/</VALUE>
</FIELD>
<FIELD>
<KEY>^.*(public|protected|private)*.*(\w\s\w)+.+</KEY>
<VALUE>/**\n
&lt;#if element.parent.isInterface()&gt;
* The constant ${element.getName()}.\n
&lt;#else&gt;
* The ${name}.\n
&lt;/#if&gt; */</VALUE>
</FIELD>
<FIELD>
<KEY>.+</KEY>
<VALUE>/**\n
&lt;#if element.parent.isEnum()&gt;
*${name} ${typeName}.\n
&lt;#else&gt;
* The ${name}.\n
&lt;/#if&gt;*/</VALUE>
</FIELD>
</FIELDS>
</TEMPLATES>
</component>
</project>

View file

@ -6,6 +6,7 @@
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>

1
.idea/misc.xml generated
View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<pattern value="rife.bld.extension.TestNgOperationBuild" method="pmd" /> <pattern value="rife.bld.extension.TestNgOperationBuild" method="pmd" />

View file

@ -22,7 +22,7 @@ public void testng() throws Exception {
} }
``` ```
```text ```console
./bld compile testng ./bld compile testng
``` ```
@ -39,7 +39,7 @@ public void test throws Exception {
} }
``` ```
``` ```console
./bld compile test ./bld compile test
``` ```

1
examples/.idea/.name generated Normal file
View file

@ -0,0 +1 @@
bld-testng-examples

View file

@ -6,6 +6,7 @@
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES> <SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" /> <root url="jar://$USER_HOME$/.bld/dist/bld-1.7.5-sources.jar!/" />
</SOURCES> </SOURCES>
<excluded> <excluded>

5
examples/README.md Normal file
View file

@ -0,0 +1,5 @@
Compile and Run Tests with TestNG
```console
./run compile test
```

View file

@ -1,6 +1,6 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.extensions=com.uwyn.rife2:bld-testng:0.9.2 bld.extensions=com.uwyn.rife2:bld-testng:0.9.3-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation= bld.downloadLocation=
bld.sourceDirectories= bld.sourceDirectories=

View file

@ -1,7 +1,6 @@
bld.downloadExtensionJavadoc=false bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true bld.downloadExtensionSources=true
bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.3 bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.4
bld.extension-generated-version=com.uwyn.rife2:bld-generated-version:0.9.2
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.downloadLocation= bld.downloadLocation=
bld.sourceDirectories= bld.sourceDirectories=

View file

@ -34,7 +34,7 @@ public class TestNgOperationBuild extends Project {
public TestNgOperationBuild() { public TestNgOperationBuild() {
pkg = "rife.bld.extension"; pkg = "rife.bld.extension";
name = "bld-testng"; name = "bld-testng";
version = version(0, 9, 2); version = version(0, 9, 3, "SNAPSHOT");
javaRelease = 17; javaRelease = 17;
downloadSources = true; downloadSources = true;
@ -48,12 +48,13 @@ public class TestNgOperationBuild extends Project {
scope(test) scope(test)
.include(dependency("org.testng", "testng", version(7, 8, 0))) .include(dependency("org.testng", "testng", version(7, 8, 0)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2))); .include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
javadocOperation() javadocOperation()
.javadocOptions() .javadocOptions()
.author()
.docLint(NO_MISSING) .docLint(NO_MISSING)
.link("https://rife2.github.io/bld/") .link("https://rife2.github.io/bld/")
.link("https://rife2.github.io/rife2/"); .link("https://rife2.github.io/rife2/");
@ -65,13 +66,24 @@ public class TestNgOperationBuild extends Project {
.artifactId("bld-testng") .artifactId("bld-testng")
.description("bld Extension to execute tests with TestNG") .description("bld Extension to execute tests with TestNG")
.url("https://github.com/rife2/bld-testng") .url("https://github.com/rife2/bld-testng")
.developer(new PublishDeveloper().id("ethauvin").name("Erik C. Thauvin").email("erik@thauvin.net") .developer(
.url("https://erik.thauvin.net/")) new PublishDeveloper()
.license(new PublishLicense().name("The Apache License, Version 2.0") .id("ethauvin")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt")) .name("Erik C. Thauvin")
.scm(new PublishScm().connection("scm:git:https://github.com/rife2/bld-testng.git") .email("erik@thauvin.net")
.developerConnection("scm:git:git@github.com:rife2/bld-testng.git") .url("https://erik.thauvin.net/")
.url("https://github.com/rife2/bld-testng")) )
.license(
new PublishLicense()
.name("The Apache License, Version 2.0")
.url("http://www.apache.org/licenses/LICENSE-2.0.txt")
)
.scm(
new PublishScm()
.connection("scm:git:https://github.com/rife2/bld-testng.git")
.developerConnection("scm:git:git@github.com:rife2/bld-testng.git")
.url("https://github.com/rife2/bld-testng")
)
.signKey(property("sign.key")) .signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase")); .signPassphrase(property("sign.passphrase"));
} }
@ -81,7 +93,7 @@ public class TestNgOperationBuild extends Project {
} }
@BuildCommand(summary = "Runs PMD analysis") @BuildCommand(summary = "Runs PMD analysis")
public void pmd() throws Exception { public void pmd() {
new PmdOperation() new PmdOperation()
.fromProject(this) .fromProject(this)
.failOnViolation(true) .failOnViolation(true)

View file

@ -38,7 +38,6 @@ import java.util.stream.Collectors;
*/ */
@SuppressWarnings("PMD.TestClassWithoutTestCases") @SuppressWarnings("PMD.TestClassWithoutTestCases")
public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> { public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
public static final String TEST_CLASS_ARG = "-testclass";
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
/** /**
* The run options. * The run options.
@ -62,6 +61,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Should Method Invocation Listeners be run even for skipped methods. * Should Method Invocation Listeners be run even for skipped methods.
* *
* <p>Default is {@code true}</p> * <p>Default is {@code true}</p>
*
* @param isAlwaysRunListeners {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners) { public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners) {
options.put("-alwaysrunlisteners", String.valueOf(isAlwaysRunListeners)); options.put("-alwaysrunlisteners", String.valueOf(isAlwaysRunListeners));
@ -72,17 +74,27 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* This sets the default maximum number of threads to use for data providers when running tests in parallel. * This sets the default maximum number of threads to use for data providers when running tests in parallel.
* It will only take effect if the parallel mode has been selected (for example,with the * It will only take effect if the parallel mode has been selected (for example,with the
* {@link #parallel(Parallel) parallel} option). This can be overridden in the suite definition. * {@link #parallel(Parallel) parallel} option). This can be overridden in the suite definition.
*
* @param count the count
* @return this operation instance
*/ */
public TestNgOperation dataProviderThreadCount(int count) { public TestNgOperation dataProviderThreadCount(int count) {
options.put("-dataproviderthreadcount", String.valueOf(count)); if (count >= 0) {
options.put("-dataproviderthreadcount", String.valueOf(count));
}
return this; return this;
} }
/** /**
* The dependency injector factory implementation that TestNG should use. * The dependency injector factory implementation that TestNG should use.
*
* @param injectorFactory the injector factory
* @return this operation instance
*/ */
public TestNgOperation dependencyInjectorFactory(String injectorFactory) { public TestNgOperation dependencyInjectorFactory(String injectorFactory) {
options.put("-dependencyinjectorfactory", injectorFactory); if (isNotBlank(injectorFactory)) {
options.put("-dependencyinjectorfactory", injectorFactory);
}
return this; return this;
} }
@ -90,34 +102,45 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* The directory where the reports will be generated * The directory where the reports will be generated
* *
* <p>Default is {@code build/test-output})</p> * <p>Default is {@code build/test-output})</p>
*
* @param directoryPath the directory path
* @return this operation instance
*/ */
public TestNgOperation directory(String directoryPath) { public TestNgOperation directory(String directoryPath) {
options.put("-d", directoryPath); if (isNotBlank(directoryPath)) {
options.put("-d", directoryPath);
}
return this; return this;
} }
/** /**
* The list of groups you want to be excluded from this run. * The list of groups you want to be excluded from this run.
* *
* @see #excludeGroups(Collection) * @param group one or more groups
* @return this operation instance
* @see #excludeGroups(Collection) #excludeGroups(Collection)
*/ */
public TestNgOperation excludeGroups(String... group) { public TestNgOperation excludeGroups(String... group) {
options.put("-excludegroups", String.join(",", group)); options.put("-excludegroups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* The list of groups you want to be excluded from this run. * The list of groups you want to be excluded from this run.
* *
* @see #excludeGroups(String...) * @param group the list of groups
* @return this operation instance
* @see #excludeGroups(String...) #excludeGroups(String...)
*/ */
public TestNgOperation excludeGroups(Collection<String> group) { public TestNgOperation excludeGroups(Collection<String> group) {
options.put("-excludegroups", String.join(",", group)); options.put("-excludegroups", String.join(",", group.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* Part of the {@link #execute execute} operation, constructs the command list to use for building the process. * Part of the {@link #execute execute} operation, constructs the command list to use for building the process.
*
* @return the command list
*/ */
@Override @Override
protected List<String> executeConstructProcessCommandList() { protected List<String> executeConstructProcessCommandList() {
@ -152,7 +175,7 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
if (!suites.isEmpty()) { if (!suites.isEmpty()) {
args.addAll(suites); args.addAll(suites);
} else if (!options.containsKey(TEST_CLASS_ARG)) { } else if (!options.containsKey("-testclass")) {
try { try {
args.add(writeDefaultSuite().getPath()); args.add(writeDefaultSuite().getPath());
} catch (IOException ioe) { } catch (IOException ioe) {
@ -170,6 +193,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Configures the {@link BaseProject}. * Configures the {@link BaseProject}.
*
* @param project the project
* @return this operation instance
*/ */
@Override @Override
public TestNgOperation fromProject(BaseProject project) { public TestNgOperation fromProject(BaseProject project) {
@ -180,6 +206,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Should TestNG fail execution if all tests were skipped and nothing was run. * Should TestNG fail execution if all tests were skipped and nothing was run.
*
* @param isFailAllSkipped {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation failWhenEverythingSkipped(Boolean isFailAllSkipped) { public TestNgOperation failWhenEverythingSkipped(Boolean isFailAllSkipped) {
options.put("-failwheneverythingskipped", String.valueOf(isFailAllSkipped)); options.put("-failwheneverythingskipped", String.valueOf(isFailAllSkipped));
@ -189,6 +218,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Whether TestNG should continue to execute the remaining tests in the suite or skip them if in a {@code @Before*} * Whether TestNG should continue to execute the remaining tests in the suite or skip them if in a {@code @Before*}
* method. * method.
*
* @param policy the policy
* @return this operation instance
*/ */
public TestNgOperation failurePolicy(FailurePolicy policy) { public TestNgOperation failurePolicy(FailurePolicy policy) {
options.put("-configfailurepolicy", policy.name().toLowerCase(Locale.getDefault())); options.put("-configfailurepolicy", policy.name().toLowerCase(Locale.getDefault()));
@ -199,6 +231,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Should TestNG consider failures in Data Providers as test failures. * Should TestNG consider failures in Data Providers as test failures.
* *
* <p>Default is {@code false}</p>. * <p>Default is {@code false}</p>.
*
* @param resultsPerSuite {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite) { public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite) {
options.put("-generateResultsPerSuite", String.valueOf(resultsPerSuite)); options.put("-generateResultsPerSuite", String.valueOf(resultsPerSuite));
@ -210,10 +245,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "windows", "linux", "regression}</p> * <p>For example: {@code "windows", "linux", "regression}</p>
* *
* @see #groups(Collection) * @param group one or more groups
* @return this operation instance
* @see #groups(Collection) #groups(Collection)
*/ */
public TestNgOperation groups(String... group) { public TestNgOperation groups(String... group) {
options.put("-groups", String.join(",", group)); options.put("-groups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -222,10 +259,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "windows", "linux", "regression}</p> * <p>For example: {@code "windows", "linux", "regression}</p>
* *
* @see #groups(String...) * @param group the list of groups
* @return this operation instance
* @see #groups(String...) #groups(String...)
*/ */
public TestNgOperation groups(Collection<String> group) { public TestNgOperation groups(Collection<String> group) {
options.put("-groups", String.join(",", group)); options.put("-groups", String.join(",", group.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -234,6 +273,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* if any. * if any.
* *
* <p>Default is {@code false}</p> * <p>Default is {@code false}</p>
*
* @param isIgnoreMissedTestNames {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) { public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) {
options.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames)); options.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames));
@ -244,16 +286,29 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Should TestNG report all iterations of a data driven test as individual skips, in-case of upstream failures. * Should TestNG report all iterations of a data driven test as individual skips, in-case of upstream failures.
* *
* <p>Default is {@code false}</p> * <p>Default is {@code false}</p>
*
* @param isIncludeDrivenTestsWhenSkipping {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation includeAllDataDrivenTestsWhenSkipping(Boolean isIncludeDrivenTestsWhenSkipping) { public TestNgOperation includeAllDataDrivenTestsWhenSkipping(Boolean isIncludeDrivenTestsWhenSkipping) {
options.put("-includeAllDataDrivenTestsWhenSkipping", String.valueOf(isIncludeDrivenTestsWhenSkipping)); options.put("-includeAllDataDrivenTestsWhenSkipping", String.valueOf(isIncludeDrivenTestsWhenSkipping));
return this; return this;
} }
/*
* Determines if a string is not blank.
*/
private boolean isNotBlank(String s) {
return s != null && !s.isBlank();
}
/** /**
* Enables or disables the JUnit mode. * Enables or disables the JUnit mode.
* *
* <p>Default is {@code false}</p> * <p>Default is {@code false}</p>
*
* @param isJunit {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation jUnit(Boolean isJunit) { public TestNgOperation jUnit(Boolean isJunit) {
options.put("-junit", String.valueOf(isJunit)); options.put("-junit", String.valueOf(isJunit));
@ -264,10 +319,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* The list of {@code .class} files or list of class names implementing {@code ITestListener} or * The list of {@code .class} files or list of class names implementing {@code ITestListener} or
* {@code ISuiteListener} * {@code ISuiteListener}
* *
* @see #listener(Collection) * @param listener one or more listeners
* @return this operation instance
* @see #listener(Collection) #listener(Collection)
*/ */
public TestNgOperation listener(String... listener) { public TestNgOperation listener(String... listener) {
options.put("-listener", String.join(",", listener)); options.put("-listener", String.join(",", Arrays.stream(listener).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -275,20 +332,26 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* The list of {@code .class} files or list of class names implementing {@code ITestListener} or * The list of {@code .class} files or list of class names implementing {@code ITestListener} or
* {@code ISuiteListener} * {@code ISuiteListener}
* *
* @see #listener(String...) * @param listener the list of listeners
* @return this operation instance
* @see #listener(String...) #listener(String...)
*/ */
public TestNgOperation listener(Collection<String> listener) { public TestNgOperation listener(Collection<String> listener) {
options.put("-listener", String.join(",", listener)); options.put("-listener", String.join(",", listener.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* Set the Level of verbosity. * Set the Level of verbosity.
* *
* @see #verbose(int) * @param level the level
* @return this operation instance
* @see #verbose(int) #verbose(int)
*/ */
public TestNgOperation log(int level) { public TestNgOperation log(int level) {
options.put("-log", String.valueOf(level)); if (level >= 0) {
options.put("-log", String.valueOf(level));
}
return this; return this;
} }
@ -297,10 +360,13 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}</p> * <p>For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}</p>
* *
* @see #methodSelectors(Collection) * @param selector one or more selectors
* @return this operation instance
* @see #methodSelectors(Collection) #methodSelectors(Collection)
*/ */
public TestNgOperation methodSelectors(String... selector) { public TestNgOperation methodSelectors(String... selector) {
options.put("-methodselectors", String.join(",", selector)); options.put("-methodselectors",
String.join(",", Arrays.stream(selector).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -309,10 +375,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}</p> * <p>For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}</p>
* *
* @see #methodSelectors(String...) * @param selector the list of selectors
* @return this operation instance
* @see #methodSelectors(String...) #methodSelectors(String...)
*/ */
public TestNgOperation methodSelectors(Collection<String> selector) { public TestNgOperation methodSelectors(Collection<String> selector) {
options.put("-methodselectors", String.join(",", selector)); options.put("-methodselectors", String.join(",", selector.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -321,10 +389,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}</p> * <p>For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}</p>
* *
* @see #methods(Collection) * @param method one or more methods
* @return this operation instance
* @see #methods(Collection) #methods(Collection)
*/ */
public TestNgOperation methods(String... method) { public TestNgOperation methods(String... method) {
options.put("-methods", String.join(",", method)); options.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -333,10 +403,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}</p> * <p>For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}</p>
* *
* @see #methods(String...) * @param method the list of methods
* @return this operation instance
* @see #methods(String...) #methods(String...)
*/ */
public TestNgOperation methods(Collection<String> method) { public TestNgOperation methods(Collection<String> method) {
options.put("-methods", String.join(",", method)); options.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -344,6 +416,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Mixed mode autodetects the type of current test and run it with appropriate runner. * Mixed mode autodetects the type of current test and run it with appropriate runner.
* *
* <p>Default is {@code false}</p> * <p>Default is {@code false}</p>
*
* @param isMixed {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation mixed(Boolean isMixed) { public TestNgOperation mixed(Boolean isMixed) {
options.put("-mixed", String.valueOf(isMixed)); options.put("-mixed", String.valueOf(isMixed));
@ -353,20 +428,24 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}. * The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}.
* *
* @see #objectFactory(Collection) * @param factory one or more factories
* @return this operation instance
* @see #objectFactory(Collection) #objectFactory(Collection)
*/ */
public TestNgOperation objectFactory(String... factory) { public TestNgOperation objectFactory(String... factory) {
options.put("-objectfactory", String.join(",", factory)); options.put("-objectfactory", String.join(",", Arrays.stream(factory).filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}. * The list of {@code .class} files or class names implementing {@code ITestRunnerFactory}.
* *
* @see #objectFactory(String...) * @param factory the list of factories
* @return this operation instance
* @see #objectFactory(String...) #objectFactory(String...)
*/ */
public TestNgOperation objectFactory(Collection<String> factory) { public TestNgOperation objectFactory(Collection<String> factory) {
options.put("-objectfactory", String.join(",", factory)); options.put("-objectfactory", String.join(",", factory.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -374,10 +453,13 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* The list of fully qualified class names of listeners that should be skipped from being wired in via * The list of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders. * Service Loaders.
* *
* @see #overrideIncludedMethods(Collection) * @param method one or more methods
* @return this operation instance
* @see #overrideIncludedMethods(Collection) #overrideIncludedMethods(Collection)
*/ */
public TestNgOperation overrideIncludedMethods(String... method) { public TestNgOperation overrideIncludedMethods(String... method) {
options.put("-overrideincludedmethods", String.join(",", method)); options.put("-overrideincludedmethods",
String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -385,10 +467,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* The list of fully qualified class names of listeners that should be skipped from being wired in via * The list of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders. * Service Loaders.
* *
* @see #overrideIncludedMethods(String...) * @param method the list of methods
* @return this operation instance
* @see #overrideIncludedMethods(String...) #overrideIncludedMethods(String...)
*/ */
public TestNgOperation overrideIncludedMethods(Collection<String> method) { public TestNgOperation overrideIncludedMethods(Collection<String> method) {
options.put("-overrideincludedmethods", String.join(",", method)); options.put("-overrideincludedmethods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -399,10 +483,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example", "test.sample.*"}</p> * <p>For example: {@code "com.example", "test.sample.*"}</p>
* *
* @see #packages(Collection) * @param name one or more names
* @return this operation instance
* @see #packages(Collection) #packages(Collection)
*/ */
public TestNgOperation packages(String... name) { public TestNgOperation packages(String... name) {
packages.addAll(Arrays.stream(name).toList()); packages.addAll(Arrays.stream(name).filter(this::isNotBlank).toList());
return this; return this;
} }
@ -413,10 +499,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "com.example", "test.sample.*"}</p> * <p>For example: {@code "com.example", "test.sample.*"}</p>
* *
* @see #packages(String...) * @param name the list of names
* @return this operation instance
* @see #packages(String...) #packages(String...)
*/ */
public TestNgOperation packages(Collection<String> name) { public TestNgOperation packages(Collection<String> name) {
packages.addAll(name); packages.addAll(name.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
@ -425,6 +513,8 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* If not set, default mechanism is not to use parallel threads at all. * If not set, default mechanism is not to use parallel threads at all.
* This can be overridden in the suite definition. * This can be overridden in the suite definition.
* *
* @param mechanism the mechanism
* @return this operation instance
* @see Parallel * @see Parallel
*/ */
public TestNgOperation parallel(Parallel mechanism) { public TestNgOperation parallel(Parallel mechanism) {
@ -434,9 +524,14 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Specifies the port number. * Specifies the port number.
*
* @param port the port
* @return this operation instance
*/ */
public TestNgOperation port(int port) { public TestNgOperation port(int port) {
options.put("-port", String.valueOf(port)); if (port >= 1) {
options.put("-port", String.valueOf(port));
}
return this; return this;
} }
@ -444,6 +539,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Should TestNG consider failures in Data Providers as test failures. * Should TestNG consider failures in Data Providers as test failures.
* *
* <p>Default is {@code false}</p> * <p>Default is {@code false}</p>
*
* @param isPropagateDataProviderFailure {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) { public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) {
options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure)); options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure));
@ -452,9 +550,14 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Specifies the extended configuration for custom report listener. * Specifies the extended configuration for custom report listener.
*
* @param reporter the reporter
* @return this operation instance
*/ */
public TestNgOperation reporter(String reporter) { public TestNgOperation reporter(String reporter) {
options.put("-reporter", reporter); if (isNotBlank(reporter)) {
options.put("-reporter", reporter);
}
return this; return this;
} }
@ -463,10 +566,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}). * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
* *
* @see #sourceDir(String...) * @param directory one or more directories
* @return this operation instance
* @see #sourceDir(String...) #sourceDir(String...)
*/ */
public TestNgOperation sourceDir(String... directory) { public TestNgOperation sourceDir(String... directory) {
options.put("-sourcedir", String.join(";", directory)); options.put("-sourcedir", String.join(";", Arrays.stream(directory).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -475,10 +580,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or * if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}). * {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
* *
* @see #sourceDir(String...) * @param directory the list of directories
* @return this operation instance
* @see #sourceDir(String...) #sourceDir(String...)
*/ */
public TestNgOperation sourceDir(Collection<String> directory) { public TestNgOperation sourceDir(Collection<String> directory) {
options.put("-sourcedir", String.join(";", directory)); options.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -486,10 +593,13 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via * Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders. * Service Loaders.
* *
* @see #spiListenersToSkip(Collection) * @param listenerToSkip the listeners to skip
* @return this operation instance
* @see #spiListenersToSkip(Collection) #spiListenersToSkip(Collection)
*/ */
public TestNgOperation spiListenersToSkip(String... listenerToSkip) { public TestNgOperation spiListenersToSkip(String... listenerToSkip) {
options.put("-spilistenerstoskip", String.join(",", listenerToSkip)); options.put("-spilistenerstoskip",
String.join(",", Arrays.stream(listenerToSkip).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -497,28 +607,41 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via * Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders. * Service Loaders.
* *
* @see #spiListenersToSkip(String...) * @param listenerToSkip the listeners to skip
* @return this operation instance
* @see #spiListenersToSkip(String...) #spiListenersToSkip(String...)
*/ */
public TestNgOperation spiListenersToSkip(Collection<String> listenerToSkip) { public TestNgOperation spiListenersToSkip(Collection<String> listenerToSkip) {
options.put("-spilistenerstoskip", String.join(",", listenerToSkip)); options.put("-spilistenerstoskip",
String.join(",", listenerToSkip.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* This specifies the default name of the test suite, if not specified in the suite definition file or source code. * This specifies the default name of the test suite, if not specified in the suite definition file or source code.
* This option is ignored if the {@code suite.xml} file or the source code specifies a different suite name. * This option is ignored if the {@code suite.xml} file or the source code specifies a different suite name.
*
* @param name the name
* @return this operation instance
*/ */
public TestNgOperation suiteName(String name) { public TestNgOperation suiteName(String name) {
options.put("-suitename", '"' + name + '"'); if (isNotBlank(name)) {
options.put("-suitename", '"' + name + '"');
}
return this; return this;
} }
/** /**
* Specifies the size of the thread pool to use to run suites. * Specifies the size of the thread pool to use to run suites.
* Required if no {@link #packages(String...)} specified. * Required if no {@link #packages(String...)} specified.
*
* @param poolSize the pool size
* @return this operation instance
*/ */
public TestNgOperation suiteThreadPoolSize(int poolSize) { public TestNgOperation suiteThreadPoolSize(int poolSize) {
options.put("-suitethreadpoolsize", String.valueOf(poolSize)); if (poolSize >= 0) {
options.put("-suitethreadpoolsize", String.valueOf(poolSize));
}
return this; return this;
} }
@ -527,10 +650,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "testng.xml", "testng2.xml"}</p> * <p>For example: {@code "testng.xml", "testng2.xml"}</p>
* *
* @see #suites(Collection) * @param suite one or more suites
* @return this operation instance
* @see #suites(Collection) #suites(Collection)
*/ */
public TestNgOperation suites(String... suite) { public TestNgOperation suites(String... suite) {
suites.addAll(Arrays.stream(suite).toList()); suites.addAll(Arrays.stream(suite).filter(this::isNotBlank).toList());
return this; return this;
} }
@ -539,15 +664,19 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "testng.xml", "testng2.xml"}</p> * <p>For example: {@code "testng.xml", "testng2.xml"}</p>
* *
* @see #suites(String...) * @param suite the list of suites
* @return this operation instance
* @see #suites(String...) #suites(String...)
*/ */
public TestNgOperation suites(Collection<String> suite) { public TestNgOperation suites(Collection<String> suite) {
suites.addAll(suite); suites.addAll(suite.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
/** /**
* Create a test file and delete it on exit. * Create a test file and delete it on exit.
*
* @return this operation instance
*/ */
private File tempFile() throws IOException { private File tempFile() throws IOException {
var temp = File.createTempFile("testng", ".xml"); var temp = File.createTempFile("testng", ".xml");
@ -560,10 +689,12 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "org.foo.Test1","org.foo.test2"}</p> * <p>For example: {@code "org.foo.Test1","org.foo.test2"}</p>
* *
* @see #testClass(Collection) * @param aClass one or more classes
* @return this operation instance
* @see #testClass(Collection) #testClass(Collection)
*/ */
public TestNgOperation testClass(String... aClass) { public TestNgOperation testClass(String... aClass) {
options.put("-testclass", String.join(",", aClass)); options.put("-testclass", String.join(",", Arrays.stream(aClass).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -572,30 +703,36 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* *
* <p>For example: {@code "org.foo.Test1","org.foo.test2"}</p> * <p>For example: {@code "org.foo.Test1","org.foo.test2"}</p>
* *
* @see #testClass(String...) * @param aClass the list of classes
* @return this operation instance
* @see #testClass(String...) #testClass(String...)
*/ */
public TestNgOperation testClass(Collection<String> aClass) { public TestNgOperation testClass(Collection<String> aClass) {
options.put("-testclass", String.join(",", aClass)); options.put("-testclass", String.join(",", aClass.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
/** /**
* Specifies the classpath entries used to run tests. * Specifies the classpath entries used to run tests.
* *
* @see #testClasspath(String...) * @param entry one or more entries
* @return this operation instance
* @see #testClasspath(String...) #testClasspath(String...)
*/ */
public TestNgOperation testClasspath(String... entry) { public TestNgOperation testClasspath(String... entry) {
testClasspath.addAll(Arrays.stream(entry).toList()); testClasspath.addAll(Arrays.stream(entry).filter(this::isNotBlank).toList());
return this; return this;
} }
/** /**
* Specifies the classpath entries used to run tests. * Specifies the classpath entries used to run tests.
* *
* @see #testClasspath(String...) * @param entry the list of entries
* @return this operation instance
* @see #testClasspath(String...) #testClasspath(String...)
*/ */
public TestNgOperation testClasspath(Collection<String> entry) { public TestNgOperation testClasspath(Collection<String> entry) {
testClasspath.addAll(entry); testClasspath.addAll(entry.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
@ -603,46 +740,67 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Specifies a jar file that contains test classes. If a {@code testng.xml} file is found at the root of that * Specifies a jar file that contains test classes. If a {@code testng.xml} file is found at the root of that
* jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test * jar file, it will be used, otherwise, all the test classes found in this jar file will be considered test
* classes. * classes.
*
* @param jar the jar
* @return this operation instance
*/ */
public TestNgOperation testJar(String jar) { public TestNgOperation testJar(String jar) {
options.put("-testjar", jar); if (isNotBlank(jar)) {
options.put("-testjar", jar);
}
return this; return this;
} }
/** /**
* This specifies the default name of test, if not specified in the suite definition file or source code. * This specifies the default name of test, if not specified in the suite definition file or source code.
* This option is ignored if the {@code suite.xml} file or the source code specifies a different test name. * This option is ignored if the {@code suite.xml} file or the source code specifies a different test name.
*
* @param name the name
* @return this operation instance
*/ */
public TestNgOperation testName(String name) { public TestNgOperation testName(String name) {
options.put("-testname", '"' + name + '"'); if (isNotBlank(name)) {
options.put("-testname", '"' + name + '"');
}
return this; return this;
} }
/** /**
* Only tests defined in a {@code <test>} tag matching one of these names will be run. * Only tests defined in a {@code <test>} tag matching one of these names will be run.
* *
* @see #testNames(Collection) * @param name one or more names
* @return this operation instance
* @see #testNames(Collection) #testNames(Collection)
*/ */
public TestNgOperation testNames(String... name) { public TestNgOperation testNames(String... name) {
options.put("-testnames", Arrays.stream(name).map(s -> '"' + s + '"').collect(Collectors.joining(","))); options.put("-testnames",
Arrays.stream(name).filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
return this; return this;
} }
/** /**
* Only tests defined in a {@code <test>} tag matching one of these names will be run. * Only tests defined in a {@code <test>} tag matching one of these names will be run.
* *
* @see #testName(String) * @param name the list of names
* @return this operation instance
* @see #testName(String) #testName(String)
*/ */
public TestNgOperation testNames(Collection<String> name) { public TestNgOperation testNames(Collection<String> name) {
options.put("-testnames", name.stream().map(s -> '"' + s + '"').collect(Collectors.joining(","))); options.put("-testnames",
name.stream().filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
return this; return this;
} }
/** /**
* Specifies the factory used to create tests. * Specifies the factory used to create tests.
*
* @param factory the factory
* @return this operation instance
*/ */
public TestNgOperation testRunFactory(String factory) { public TestNgOperation testRunFactory(String factory) {
options.put("-testrunfactory", factory); if (isNotBlank(factory)) {
options.put("-testrunfactory", factory);
}
return this; return this;
} }
@ -650,17 +808,27 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* This sets the default maximum number of threads to use for running tests in parallel. It will only take effect * This sets the default maximum number of threads to use for running tests in parallel. It will only take effect
* if the parallel mode has been selected (for example, with the {@link #parallel(Parallel) parallel} option). * if the parallel mode has been selected (for example, with the {@link #parallel(Parallel) parallel} option).
* This can be overridden in the suite definition. * This can be overridden in the suite definition.
*
* @param count the count
* @return this operation instance
*/ */
public TestNgOperation threadCount(int count) { public TestNgOperation threadCount(int count) {
options.put("-threadcount", String.valueOf(count)); if (count >= 0) {
options.put("-threadcount", String.valueOf(count));
}
return this; return this;
} }
/** /**
* Specifies the thread pool executor factory implementation that TestNG should use. * Specifies the thread pool executor factory implementation that TestNG should use.
*
* @param factoryClass the factory class
* @return this operation instance
*/ */
public TestNgOperation threadPoolFactoryClass(String factoryClass) { public TestNgOperation threadPoolFactoryClass(String factoryClass) {
options.put("-threadpoolfactoryclass", factoryClass); if (isNotBlank(factoryClass)) {
options.put("-threadpoolfactoryclass", factoryClass);
}
return this; return this;
} }
@ -668,6 +836,9 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Whether to use the default listeners * Whether to use the default listeners
* *
* <p>Default is {@code true}</p> * <p>Default is {@code true}</p>
*
* @param isDefaultListener {@code true} or {@code false}
* @return this operation instance
*/ */
public TestNgOperation useDefaultListeners(Boolean isDefaultListener) { public TestNgOperation useDefaultListeners(Boolean isDefaultListener) {
options.put("-usedefaultlisteners", String.valueOf(isDefaultListener)); options.put("-usedefaultlisteners", String.valueOf(isDefaultListener));
@ -677,10 +848,14 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
/** /**
* Set the Level of verbosity. * Set the Level of verbosity.
* *
* @see #log(int) * @param level the level
* @return this operation instance
* @see #log(int) #log(int)
*/ */
public TestNgOperation verbose(int level) { public TestNgOperation verbose(int level) {
options.put("-verbose", String.valueOf(level)); if (level >= 0) {
options.put("-verbose", String.valueOf(level));
}
return this; return this;
} }
@ -704,9 +879,14 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* This attribute should contain the path to a valid XML file inside the test jar * This attribute should contain the path to a valid XML file inside the test jar
* (e.g. {@code "resources/testng.xml"}). The default is {@code testng.xml}, which means a file called * (e.g. {@code "resources/testng.xml"}). The default is {@code testng.xml}, which means a file called
* {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified. * {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified.
*
* @param path the path
* @return this operation instance
*/ */
public TestNgOperation xmlPathInJar(String path) { public TestNgOperation xmlPathInJar(String path) {
options.put("-xmlpathinjar", path); if (isNotBlank(path)) {
options.put("-xmlpathinjar", path);
}
return this; return this;
} }
@ -714,13 +894,31 @@ public class TestNgOperation extends AbstractProcessOperation<TestNgOperation> {
* Parallel Mechanisms * Parallel Mechanisms
*/ */
public enum Parallel { public enum Parallel {
METHODS, TESTS, CLASSES /**
* Methods mechanism.
*/
METHODS,
/**
* Tests mechanism.
*/
TESTS,
/**
* Classes mechanism.
*/
CLASSES
} }
/** /**
* Failure Policies * Failure Policies
*/ */
public enum FailurePolicy { public enum FailurePolicy {
SKIP, CONTINUE /**
* Skip failure policy.
*/
SKIP,
/**
* Continue failure policy.
*/
CONTINUE
} }
} }

View file

@ -47,10 +47,10 @@ class TestNgOperationTest {
@Test @Test
void testClass() { void testClass() {
var op = new TestNgOperation().testClass(FOO, BAR); var op = new TestNgOperation().testClass(FOO, BAR);
assertThat(op.options.get(TestNgOperation.TEST_CLASS_ARG)).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options.get("-testclass")).isEqualTo(String.format("%s,%s", FOO, BAR));
new TestNgOperation().testClass(List.of(FOO, BAR)); new TestNgOperation().testClass(List.of(FOO, BAR));
assertThat(op.options.get(TestNgOperation.TEST_CLASS_ARG)).as("as list") assertThat(op.options.get("-testclass")).as("as list")
.isEqualTo(String.format("%s,%s", FOO, BAR)); .isEqualTo(String.format("%s,%s", FOO, BAR));
} }