Added methods to access the map of options and sets

This commit is contained in:
Erik C. Thauvin 2024-06-22 21:13:28 -07:00
parent 057bb39247
commit 177ad3d961
Signed by: erik
GPG key ID: 776702A6A2DA330E
2 changed files with 197 additions and 151 deletions

View file

@ -39,23 +39,23 @@ import java.util.stream.Collectors;
@SuppressWarnings("PMD.TestClassWithoutTestCases") @SuppressWarnings("PMD.TestClassWithoutTestCases")
public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> { public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> {
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
/**
* The classpath entries used for running tests.
*/
private final Set<String> testClasspath_ = new HashSet<>();
/** /**
* The run options. * The run options.
*/ */
protected final Map<String, String> options = new ConcurrentHashMap<>(); private final Map<String, String> options_ = new ConcurrentHashMap<>();
/** /**
* The suite packages to run. * The suite packages to run.
*/ */
protected final Set<String> packages = new HashSet<>(); private final Set<String> packages_ = new HashSet<>();
/** /**
* The suites to run. * The suites to run.
*/ */
protected final Set<String> suites = new HashSet<>(); private final Set<String> suites_ = new HashSet<>();
/** private BaseProject project_;
* The classpath entries used for running tests.
*/
protected final Set<String> testClasspath = new HashSet<>();
private BaseProject project;
/** /**
* Should Method Invocation Listeners be run even for skipped methods. * Should Method Invocation Listeners be run even for skipped methods.
@ -66,7 +66,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -80,7 +80,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation dataProviderThreadCount(int count) { public TestNgOperation dataProviderThreadCount(int count) {
if (count >= 0) { if (count >= 0) {
options.put("-dataproviderthreadcount", String.valueOf(count)); options_.put("-dataproviderthreadcount", String.valueOf(count));
} }
return this; return this;
} }
@ -93,7 +93,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation dependencyInjectorFactory(String injectorFactory) { public TestNgOperation dependencyInjectorFactory(String injectorFactory) {
if (isNotBlank(injectorFactory)) { if (isNotBlank(injectorFactory)) {
options.put("-dependencyinjectorfactory", injectorFactory); options_.put("-dependencyinjectorfactory", injectorFactory);
} }
return this; return this;
} }
@ -108,7 +108,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation directory(String directoryPath) { public TestNgOperation directory(String directoryPath) {
if (isNotBlank(directoryPath)) { if (isNotBlank(directoryPath)) {
options.put("-d", directoryPath); options_.put("-d", directoryPath);
} }
return this; return this;
} }
@ -121,7 +121,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #excludeGroups(Collection) #excludeGroups(Collection) * @see #excludeGroups(Collection) #excludeGroups(Collection)
*/ */
public TestNgOperation excludeGroups(String... group) { public TestNgOperation excludeGroups(String... group) {
options.put("-excludegroups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList())); options_.put("-excludegroups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -133,7 +133,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #excludeGroups(String...) #excludeGroups(String...) * @see #excludeGroups(String...) #excludeGroups(String...)
*/ */
public TestNgOperation excludeGroups(Collection<String> group) { public TestNgOperation excludeGroups(Collection<String> group) {
options.put("-excludegroups", String.join(",", group.stream().filter(this::isNotBlank).toList())); options_.put("-excludegroups", String.join(",", group.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -144,39 +144,39 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
@Override @Override
protected List<String> executeConstructProcessCommandList() { protected List<String> executeConstructProcessCommandList() {
if (project == null) { if (project_ == null) {
LOGGER.severe("A project must be specified."); LOGGER.severe("A project must be specified.");
} else if (packages.isEmpty() && suites.isEmpty()) { } else if (packages_.isEmpty() && suites_.isEmpty()) {
LOGGER.severe("At least one package or XML suite is required."); LOGGER.severe("At least one package or XML suite is required.");
} }
if (!options.containsKey("-d")) { if (!options_.containsKey("-d")) {
options.put("-d", Path.of(project.buildDirectory().getPath(), "test-output").toString()); options_.put("-d", Path.of(project_.buildDirectory().getPath(), "test-output").toString());
} }
final List<String> args = new ArrayList<>(); final List<String> args = new ArrayList<>();
args.add(javaTool()); args.add(javaTool());
args.addAll(this.javaOptions()); args.addAll(javaOptions());
args.add("-cp"); args.add("-cp");
if (testClasspath.isEmpty()) { if (testClasspath_.isEmpty()) {
args.add(String.format("%s:%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"), args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"),
Path.of(project.libCompileDirectory().getPath(), "*"), project.buildMainDirectory(), Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(),
project.buildTestDirectory())); project_.buildTestDirectory()));
} else { } else {
args.add(String.join(":", testClasspath)); args.add(String.join(":", testClasspath_));
} }
args.add("org.testng.TestNG"); args.add("org.testng.TestNG");
options.forEach((k, v) -> { options_.forEach((k, v) -> {
args.add(k); args.add(k);
args.add(v); args.add(v);
}); });
if (!suites.isEmpty()) { if (!suites_.isEmpty()) {
args.addAll(suites); args.addAll(suites_);
} else if (!options.containsKey("-testclass")) { } else if (!options_.containsKey("-testclass")) {
try { try {
args.add(writeDefaultSuite().getPath()); args.add(writeDefaultSuite().getPath());
} catch (IOException ioe) { } catch (IOException ioe) {
@ -190,7 +190,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
if (LOGGER.isLoggable(Level.INFO)) { if (LOGGER.isLoggable(Level.INFO)) {
LOGGER.info(String.format("Report will be saved in file://%s", LOGGER.info(String.format("Report will be saved in file://%s",
new File(options.get("-d")).toURI().getPath())); new File(options_.get("-d")).toURI().getPath()));
} }
return args; return args;
@ -204,7 +204,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
@Override @Override
public TestNgOperation fromProject(BaseProject project) { public TestNgOperation fromProject(BaseProject project) {
this.project = project; project_ = project;
directory(Path.of(project.buildDirectory().getPath(), "test-output").toString()); directory(Path.of(project.buildDirectory().getPath(), "test-output").toString());
return this; return this;
} }
@ -216,7 +216,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -228,7 +228,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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()));
return this; return this;
} }
@ -242,7 +242,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -256,7 +256,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #groups(Collection) #groups(Collection) * @see #groups(Collection) #groups(Collection)
*/ */
public TestNgOperation groups(String... group) { public TestNgOperation groups(String... group) {
options.put("-groups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList())); options_.put("-groups", String.join(",", Arrays.stream(group).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -270,7 +270,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #groups(String...) #groups(String...) * @see #groups(String...) #groups(String...)
*/ */
public TestNgOperation groups(Collection<String> group) { public TestNgOperation groups(Collection<String> group) {
options.put("-groups", String.join(",", group.stream().filter(this::isNotBlank).toList())); options_.put("-groups", String.join(",", group.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -284,7 +284,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -297,7 +297,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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;
} }
@ -317,7 +317,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -330,7 +330,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #listener(Collection) #listener(Collection) * @see #listener(Collection) #listener(Collection)
*/ */
public TestNgOperation listener(String... listener) { public TestNgOperation listener(String... listener) {
options.put("-listener", String.join(",", Arrays.stream(listener).filter(this::isNotBlank).toList())); options_.put("-listener", String.join(",", Arrays.stream(listener).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -343,7 +343,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #listener(String...) #listener(String...) * @see #listener(String...) #listener(String...)
*/ */
public TestNgOperation listener(Collection<String> listener) { public TestNgOperation listener(Collection<String> listener) {
options.put("-listener", String.join(",", listener.stream().filter(this::isNotBlank).toList())); options_.put("-listener", String.join(",", listener.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -355,7 +355,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @return this operation instance
*/ */
public TestNgOperation listenerComparator(String listenerComparator) { public TestNgOperation listenerComparator(String listenerComparator) {
options.put("-listenercomparator", listenerComparator); options_.put("-listenercomparator", listenerComparator);
return this; return this;
} }
@ -366,7 +366,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @return this operation instance
*/ */
public TestNgOperation listenerFactory(String listenerFactory) { public TestNgOperation listenerFactory(String listenerFactory) {
options.put("-listenerfactory", listenerFactory); options_.put("-listenerfactory", listenerFactory);
return this; return this;
} }
@ -379,7 +379,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation log(int level) { public TestNgOperation log(int level) {
if (level >= 0) { if (level >= 0) {
options.put("-log", String.valueOf(level)); options_.put("-log", String.valueOf(level));
} }
return this; return this;
} }
@ -394,7 +394,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #methodSelectors(Collection) #methodSelectors(Collection) * @see #methodSelectors(Collection) #methodSelectors(Collection)
*/ */
public TestNgOperation methodSelectors(String... selector) { public TestNgOperation methodSelectors(String... selector) {
options.put("-methodselectors", options_.put("-methodselectors",
String.join(",", Arrays.stream(selector).filter(this::isNotBlank).toList())); String.join(",", Arrays.stream(selector).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -409,7 +409,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #methodSelectors(String...) #methodSelectors(String...) * @see #methodSelectors(String...) #methodSelectors(String...)
*/ */
public TestNgOperation methodSelectors(Collection<String> selector) { public TestNgOperation methodSelectors(Collection<String> selector) {
options.put("-methodselectors", String.join(",", selector.stream().filter(this::isNotBlank).toList())); options_.put("-methodselectors", String.join(",", selector.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -423,7 +423,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #methods(Collection) #methods(Collection) * @see #methods(Collection) #methods(Collection)
*/ */
public TestNgOperation methods(String... method) { public TestNgOperation methods(String... method) {
options.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList())); options_.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -437,7 +437,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #methods(String...) #methods(String...) * @see #methods(String...) #methods(String...)
*/ */
public TestNgOperation methods(Collection<String> method) { public TestNgOperation methods(Collection<String> method) {
options.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList())); options_.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -450,7 +450,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -462,7 +462,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @return this operation instance
*/ */
public TestNgOperation objectFactory(String objectFactory) { public TestNgOperation objectFactory(String objectFactory) {
options.put("-objectfactory", objectFactory); options_.put("-objectfactory", objectFactory);
return this; return this;
} }
@ -474,7 +474,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #objectFactory(Collection) #objectFactory(Collection) * @see #objectFactory(Collection) #objectFactory(Collection)
*/ */
public TestNgOperation objectFactory(String... factory) { public TestNgOperation objectFactory(String... factory) {
options.put("-objectfactory", String.join(",", Arrays.stream(factory).filter(this::isNotBlank).toList())); options_.put("-objectfactory", String.join(",", Arrays.stream(factory).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -486,10 +486,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #objectFactory(String...) #objectFactory(String...) * @see #objectFactory(String...) #objectFactory(String...)
*/ */
public TestNgOperation objectFactory(Collection<String> factory) { public TestNgOperation objectFactory(Collection<String> factory) {
options.put("-objectfactory", String.join(",", factory.stream().filter(this::isNotBlank).toList())); options_.put("-objectfactory", String.join(",", factory.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
/**
* Returns the run options.
*
* @return the map of run options
*/
public Map<String, String> options() {
return options_;
}
/** /**
* 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.
@ -499,7 +508,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #overrideIncludedMethods(Collection) #overrideIncludedMethods(Collection) * @see #overrideIncludedMethods(Collection) #overrideIncludedMethods(Collection)
*/ */
public TestNgOperation overrideIncludedMethods(String... method) { public TestNgOperation overrideIncludedMethods(String... method) {
options.put("-overrideincludedmethods", options_.put("-overrideincludedmethods",
String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList())); String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -513,7 +522,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #overrideIncludedMethods(String...) #overrideIncludedMethods(String...) * @see #overrideIncludedMethods(String...) #overrideIncludedMethods(String...)
*/ */
public TestNgOperation overrideIncludedMethods(Collection<String> method) { public TestNgOperation overrideIncludedMethods(Collection<String> method) {
options.put("-overrideincludedmethods", String.join(",", method.stream().filter(this::isNotBlank).toList())); options_.put("-overrideincludedmethods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -529,7 +538,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #packages(Collection) #packages(Collection) * @see #packages(Collection) #packages(Collection)
*/ */
public TestNgOperation packages(String... name) { public TestNgOperation packages(String... name) {
packages.addAll(Arrays.stream(name).filter(this::isNotBlank).toList()); packages_.addAll(Arrays.stream(name).filter(this::isNotBlank).toList());
return this; return this;
} }
@ -545,10 +554,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #packages(String...) #packages(String...) * @see #packages(String...) #packages(String...)
*/ */
public TestNgOperation packages(Collection<String> name) { public TestNgOperation packages(Collection<String> name) {
packages.addAll(name.stream().filter(this::isNotBlank).toList()); packages_.addAll(name.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
/**
* Returns the suite packages to run.
*
* @return the set of packages
*/
public Set<String> packages() {
return packages_;
}
/** /**
* If specified, sets the default mechanism used to determine how to use parallel threads when running tests. * If specified, sets the default mechanism used to determine how to use parallel threads when running tests.
* 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.
@ -559,7 +577,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see Parallel * @see Parallel
*/ */
public TestNgOperation parallel(Parallel mechanism) { public TestNgOperation parallel(Parallel mechanism) {
options.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault())); options_.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault()));
return this; return this;
} }
@ -571,7 +589,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation port(int port) { public TestNgOperation port(int port) {
if (port >= 1) { if (port >= 1) {
options.put("-port", String.valueOf(port)); options_.put("-port", String.valueOf(port));
} }
return this; return this;
} }
@ -585,7 +603,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -597,7 +615,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation reporter(String reporter) { public TestNgOperation reporter(String reporter) {
if (isNotBlank(reporter)) { if (isNotBlank(reporter)) {
options.put("-reporter", reporter); options_.put("-reporter", reporter);
} }
return this; return this;
} }
@ -610,7 +628,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders) { public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders) {
if (shareThreadPoolForDataProviders) { if (shareThreadPoolForDataProviders) {
options.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders)); options_.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders));
} }
return this; return this;
} }
@ -625,7 +643,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #sourceDir(String...) #sourceDir(String...) * @see #sourceDir(String...) #sourceDir(String...)
*/ */
public TestNgOperation sourceDir(String... directory) { public TestNgOperation sourceDir(String... directory) {
options.put("-sourcedir", String.join(";", Arrays.stream(directory).filter(this::isNotBlank).toList())); options_.put("-sourcedir", String.join(";", Arrays.stream(directory).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -639,7 +657,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #sourceDir(String...) #sourceDir(String...) * @see #sourceDir(String...) #sourceDir(String...)
*/ */
public TestNgOperation sourceDir(Collection<String> directory) { public TestNgOperation sourceDir(Collection<String> directory) {
options.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList())); options_.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -652,7 +670,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #spiListenersToSkip(Collection) #spiListenersToSkip(Collection) * @see #spiListenersToSkip(Collection) #spiListenersToSkip(Collection)
*/ */
public TestNgOperation spiListenersToSkip(String... listenerToSkip) { public TestNgOperation spiListenersToSkip(String... listenerToSkip) {
options.put("-spilistenerstoskip", options_.put("-spilistenerstoskip",
String.join(",", Arrays.stream(listenerToSkip).filter(this::isNotBlank).toList())); String.join(",", Arrays.stream(listenerToSkip).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -666,7 +684,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #spiListenersToSkip(String...) #spiListenersToSkip(String...) * @see #spiListenersToSkip(String...) #spiListenersToSkip(String...)
*/ */
public TestNgOperation spiListenersToSkip(Collection<String> listenerToSkip) { public TestNgOperation spiListenersToSkip(Collection<String> listenerToSkip) {
options.put("-spilistenerstoskip", options_.put("-spilistenerstoskip",
String.join(",", listenerToSkip.stream().filter(this::isNotBlank).toList())); String.join(",", listenerToSkip.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -680,7 +698,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation suiteName(String name) { public TestNgOperation suiteName(String name) {
if (isNotBlank(name)) { if (isNotBlank(name)) {
options.put("-suitename", '"' + name + '"'); options_.put("-suitename", '"' + name + '"');
} }
return this; return this;
} }
@ -694,7 +712,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation suiteThreadPoolSize(int poolSize) { public TestNgOperation suiteThreadPoolSize(int poolSize) {
if (poolSize >= 0) { if (poolSize >= 0) {
options.put("-suitethreadpoolsize", String.valueOf(poolSize)); options_.put("-suitethreadpoolsize", String.valueOf(poolSize));
} }
return this; return this;
} }
@ -709,7 +727,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #suites(Collection) #suites(Collection) * @see #suites(Collection) #suites(Collection)
*/ */
public TestNgOperation suites(String... suite) { public TestNgOperation suites(String... suite) {
suites.addAll(Arrays.stream(suite).filter(this::isNotBlank).toList()); suites_.addAll(Arrays.stream(suite).filter(this::isNotBlank).toList());
return this; return this;
} }
@ -723,10 +741,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #suites(String...) #suites(String...) * @see #suites(String...) #suites(String...)
*/ */
public TestNgOperation suites(Collection<String> suite) { public TestNgOperation suites(Collection<String> suite) {
suites.addAll(suite.stream().filter(this::isNotBlank).toList()); suites_.addAll(suite.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
/**
* Returns the suites to run.
*
* @return the set of suites
*/
public Set<String> suites() {
return suites_;
}
/** /**
* Create a test file and delete it on exit. * Create a test file and delete it on exit.
* *
@ -748,7 +775,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testClass(Collection) #testClass(Collection) * @see #testClass(Collection) #testClass(Collection)
*/ */
public TestNgOperation testClass(String... aClass) { public TestNgOperation testClass(String... aClass) {
options.put("-testclass", String.join(",", Arrays.stream(aClass).filter(this::isNotBlank).toList())); options_.put("-testclass", String.join(",", Arrays.stream(aClass).filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -762,7 +789,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testClass(String...) #testClass(String...) * @see #testClass(String...) #testClass(String...)
*/ */
public TestNgOperation testClass(Collection<String> aClass) { public TestNgOperation testClass(Collection<String> aClass) {
options.put("-testclass", String.join(",", aClass.stream().filter(this::isNotBlank).toList())); options_.put("-testclass", String.join(",", aClass.stream().filter(this::isNotBlank).toList()));
return this; return this;
} }
@ -774,7 +801,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testClasspath(String...) #testClasspath(String...) * @see #testClasspath(String...) #testClasspath(String...)
*/ */
public TestNgOperation testClasspath(String... entry) { public TestNgOperation testClasspath(String... entry) {
testClasspath.addAll(Arrays.stream(entry).filter(this::isNotBlank).toList()); testClasspath_.addAll(Arrays.stream(entry).filter(this::isNotBlank).toList());
return this; return this;
} }
@ -786,10 +813,19 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testClasspath(String...) #testClasspath(String...) * @see #testClasspath(String...) #testClasspath(String...)
*/ */
public TestNgOperation testClasspath(Collection<String> entry) { public TestNgOperation testClasspath(Collection<String> entry) {
testClasspath.addAll(entry.stream().filter(this::isNotBlank).toList()); testClasspath_.addAll(entry.stream().filter(this::isNotBlank).toList());
return this; return this;
} }
/**
* Returns the classpath entries used for running tests.
*
* @return the set of test classpath
*/
public Set<String> testClasspath() {
return testClasspath_;
}
/** /**
* 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
@ -800,7 +836,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation testJar(String jar) { public TestNgOperation testJar(String jar) {
if (isNotBlank(jar)) { if (isNotBlank(jar)) {
options.put("-testjar", jar); options_.put("-testjar", jar);
} }
return this; return this;
} }
@ -814,7 +850,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation testName(String name) { public TestNgOperation testName(String name) {
if (isNotBlank(name)) { if (isNotBlank(name)) {
options.put("-testname", '"' + name + '"'); options_.put("-testname", '"' + name + '"');
} }
return this; return this;
} }
@ -827,7 +863,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testNames(Collection) #testNames(Collection) * @see #testNames(Collection) #testNames(Collection)
*/ */
public TestNgOperation testNames(String... name) { public TestNgOperation testNames(String... name) {
options.put("-testnames", options_.put("-testnames",
Arrays.stream(name).filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(","))); Arrays.stream(name).filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
return this; return this;
} }
@ -840,7 +876,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @see #testName(String) #testName(String) * @see #testName(String) #testName(String)
*/ */
public TestNgOperation testNames(Collection<String> name) { public TestNgOperation testNames(Collection<String> name) {
options.put("-testnames", options_.put("-testnames",
name.stream().filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(","))); name.stream().filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(",")));
return this; return this;
} }
@ -853,7 +889,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation testRunFactory(String factory) { public TestNgOperation testRunFactory(String factory) {
if (isNotBlank(factory)) { if (isNotBlank(factory)) {
options.put("-testrunfactory", factory); options_.put("-testrunfactory", factory);
} }
return this; return this;
} }
@ -868,7 +904,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation threadCount(int count) { public TestNgOperation threadCount(int count) {
if (count >= 0) { if (count >= 0) {
options.put("-threadcount", String.valueOf(count)); options_.put("-threadcount", String.valueOf(count));
} }
return this; return this;
} }
@ -881,7 +917,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation threadPoolFactoryClass(String factoryClass) { public TestNgOperation threadPoolFactoryClass(String factoryClass) {
if (isNotBlank(factoryClass)) { if (isNotBlank(factoryClass)) {
options.put("-threadpoolfactoryclass", factoryClass); options_.put("-threadpoolfactoryclass", factoryClass);
} }
return this; return this;
} }
@ -895,7 +931,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* @return this operation instance * @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));
return this; return this;
} }
@ -907,7 +943,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) { public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) {
if (useGlobalThreadPool) { if (useGlobalThreadPool) {
options.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool)); options_.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool));
} }
return this; return this;
} }
@ -921,7 +957,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation verbose(int level) { public TestNgOperation verbose(int level) {
if (level >= 0) { if (level >= 0) {
options.put("-verbose", String.valueOf(level)); options_.put("-verbose", String.valueOf(level));
} }
return this; return this;
} }
@ -934,7 +970,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
"<suite name=\"bld Default Suite\" verbose=\"2\">" + "<suite name=\"bld Default Suite\" verbose=\"2\">" +
"<test name=\"All Packages\">" + "<test name=\"All Packages\">" +
"<packages>"); "<packages>");
for (var p : packages) { for (var p : packages_) {
bufWriter.write(String.format("<package name=\"%s\"/>", p)); bufWriter.write(String.format("<package name=\"%s\"/>", p));
} }
bufWriter.write("</packages></test></suite>"); bufWriter.write("</packages></test></suite>");
@ -952,7 +988,7 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
*/ */
public TestNgOperation xmlPathInJar(String path) { public TestNgOperation xmlPathInJar(String path) {
if (isNotBlank(path)) { if (isNotBlank(path)) {
options.put("-xmlpathinjar", path); options_.put("-xmlpathinjar", path);
} }
return this; return this;
} }

View file

@ -43,10 +43,10 @@ class TestNgOperationTest {
@Test @Test
void testAlwaysRunListeners() { void testAlwaysRunListeners() {
var op = new TestNgOperation().alwaysRunListeners(false); var op = new TestNgOperation().alwaysRunListeners(false);
assertThat(op.options.get("-alwaysrunlisteners")).isEqualTo("false"); assertThat(op.options().get("-alwaysrunlisteners")).isEqualTo("false");
op = new TestNgOperation().alwaysRunListeners(true); op = new TestNgOperation().alwaysRunListeners(true);
assertThat(op.options.get("-alwaysrunlisteners")).isEqualTo("true"); assertThat(op.options().get("-alwaysrunlisteners")).isEqualTo("true");
} }
@Test @Test
@ -113,38 +113,44 @@ 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("-testclass")).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("-testclass")).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));
} }
@Test
void testClasspath() {
var op = new TestNgOperation().testClasspath(FOO, BAR);
assertThat(op.testClasspath()).containsExactly(BAR, FOO);
}
@Test @Test
void testDataProviderThreadCount() { void testDataProviderThreadCount() {
var op = new TestNgOperation().dataProviderThreadCount(1); var op = new TestNgOperation().dataProviderThreadCount(1);
assertThat(op.options.get("-dataproviderthreadcount")).isEqualTo("1"); assertThat(op.options().get("-dataproviderthreadcount")).isEqualTo("1");
} }
@Test @Test
void testDependencyInjectorFactory() { void testDependencyInjectorFactory() {
var op = new TestNgOperation().dependencyInjectorFactory(FOO); var op = new TestNgOperation().dependencyInjectorFactory(FOO);
assertThat(op.options.get("-dependencyinjectorfactory")).isEqualTo(FOO); assertThat(op.options().get("-dependencyinjectorfactory")).isEqualTo(FOO);
} }
@Test @Test
void testDirectory() { void testDirectory() {
var op = new TestNgOperation().directory(FOO); var op = new TestNgOperation().directory(FOO);
assertThat(op.options.get("-d")).isEqualTo(FOO); assertThat(op.options().get("-d")).isEqualTo(FOO);
} }
@Test @Test
void testExcludeGroups() { void testExcludeGroups() {
var op = new TestNgOperation().excludeGroups(FOO, BAR); var op = new TestNgOperation().excludeGroups(FOO, BAR);
assertThat(op.options.get("-excludegroups")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-excludegroups")).isEqualTo(String.format("%s,%s", FOO, BAR));
op = new TestNgOperation().excludeGroups(List.of(FOO, BAR)); op = new TestNgOperation().excludeGroups(List.of(FOO, BAR));
assertThat(op.options.get("-excludegroups")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-excludegroups")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
@ -201,276 +207,280 @@ class TestNgOperationTest {
@Test @Test
void testFailWheneverEverythingSkipped() { void testFailWheneverEverythingSkipped() {
var op = new TestNgOperation().failWhenEverythingSkipped(false); var op = new TestNgOperation().failWhenEverythingSkipped(false);
assertThat(op.options.get("-failwheneverythingskipped")).isEqualTo("false"); assertThat(op.options().get("-failwheneverythingskipped")).isEqualTo("false");
op = new TestNgOperation().failWhenEverythingSkipped(true); op = new TestNgOperation().failWhenEverythingSkipped(true);
assertThat(op.options.get("-failwheneverythingskipped")).isEqualTo("true"); assertThat(op.options().get("-failwheneverythingskipped")).isEqualTo("true");
} }
@Test @Test
void testFailurePolicy() { void testFailurePolicy() {
var op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.CONTINUE); var op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.CONTINUE);
assertThat(op.options.get("-configfailurepolicy")).isEqualTo("continue"); assertThat(op.options().get("-configfailurepolicy")).isEqualTo("continue");
op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.SKIP); op = new TestNgOperation().failurePolicy(TestNgOperation.FailurePolicy.SKIP);
assertThat(op.options.get("-configfailurepolicy")).isEqualTo("skip"); assertThat(op.options().get("-configfailurepolicy")).isEqualTo("skip");
} }
@Test @Test
void testGenerateResultsPerSuite() { void testGenerateResultsPerSuite() {
var op = new TestNgOperation().generateResultsPerSuite(false); var op = new TestNgOperation().generateResultsPerSuite(false);
assertThat(op.options.get("-generateResultsPerSuite")).isEqualTo("false"); assertThat(op.options().get("-generateResultsPerSuite")).isEqualTo("false");
op = new TestNgOperation().generateResultsPerSuite(true); op = new TestNgOperation().generateResultsPerSuite(true);
assertThat(op.options.get("-generateResultsPerSuite")).isEqualTo("true"); assertThat(op.options().get("-generateResultsPerSuite")).isEqualTo("true");
} }
@Test @Test
void testGroups() { void testGroups() {
var op = new TestNgOperation().groups(FOO, BAR); var op = new TestNgOperation().groups(FOO, BAR);
assertThat(op.options.get("-groups")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-groups")).isEqualTo(String.format("%s,%s", FOO, BAR));
op.groups(List.of("group3", "group4"));
assertThat(op.options().get("-groups")).isEqualTo("group3,group4");
} }
@Test @Test
void testIgnoreMissedTestName() { void testIgnoreMissedTestName() {
var op = new TestNgOperation().ignoreMissedTestName(false); var op = new TestNgOperation().ignoreMissedTestName(false);
assertThat(op.options.get("-ignoreMissedTestNames")).isEqualTo("false"); assertThat(op.options().get("-ignoreMissedTestNames")).isEqualTo("false");
op = new TestNgOperation().ignoreMissedTestName(true); op = new TestNgOperation().ignoreMissedTestName(true);
assertThat(op.options.get("-ignoreMissedTestNames")).isEqualTo("true"); assertThat(op.options().get("-ignoreMissedTestNames")).isEqualTo("true");
} }
@Test @Test
void testIncludeAllDataDrivenTestsWhenSkipping() { void testIncludeAllDataDrivenTestsWhenSkipping() {
var op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(false); var op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(false);
assertThat(op.options.get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("false"); assertThat(op.options().get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("false");
op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(true); op = new TestNgOperation().includeAllDataDrivenTestsWhenSkipping(true);
assertThat(op.options.get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true"); assertThat(op.options().get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true");
} }
@Test @Test
void testJar() { void testJar() {
var op = new TestNgOperation().testJar(FOO); var op = new TestNgOperation().testJar(FOO);
assertThat(op.options.get("-testjar")).isEqualTo(FOO); assertThat(op.options().get("-testjar")).isEqualTo(FOO);
} }
@Test @Test
void testJunit() { void testJunit() {
var op = new TestNgOperation().jUnit(false); var op = new TestNgOperation().jUnit(false);
assertThat(op.options.get("-junit")).isEqualTo("false"); assertThat(op.options().get("-junit")).isEqualTo("false");
op = new TestNgOperation().jUnit(true); op = new TestNgOperation().jUnit(true);
assertThat(op.options.get("-junit")).isEqualTo("true"); assertThat(op.options().get("-junit")).isEqualTo("true");
} }
@Test @Test
void testListener() { void testListener() {
var ops = new TestNgOperation().listener(FOO, BAR); var ops = new TestNgOperation().listener(FOO, BAR);
assertThat(ops.options.get("-listener")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-listener")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().listener(List.of(FOO, BAR)); ops = new TestNgOperation().listener(List.of(FOO, BAR));
assertThat(ops.options.get("-listener")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-listener")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testMethodDetectors() { void testMethodDetectors() {
var op = new TestNgOperation().methodSelectors(FOO, BAR); var op = new TestNgOperation().methodSelectors(FOO, BAR);
assertThat(op.options.get("-methodselectors")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-methodselectors")).isEqualTo(String.format("%s,%s", FOO, BAR));
op = new TestNgOperation().methodSelectors(List.of(FOO, BAR)); op = new TestNgOperation().methodSelectors(List.of(FOO, BAR));
assertThat(op.options.get("-methodselectors")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-methodselectors")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testMethods() { void testMethods() {
var op = new TestNgOperation().methods(FOO, BAR); var op = new TestNgOperation().methods(FOO, BAR);
assertThat(op.options.get("-methods")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-methods")).isEqualTo(String.format("%s,%s", FOO, BAR));
new TestNgOperation().methods(List.of(FOO, BAR)); new TestNgOperation().methods(List.of(FOO, BAR));
assertThat(op.options.get("-methods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(op.options().get("-methods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testMixed() { void testMixed() {
var op = new TestNgOperation().mixed(false); var op = new TestNgOperation().mixed(false);
assertThat(op.options.get("-mixed")).isEqualTo("false"); assertThat(op.options().get("-mixed")).isEqualTo("false");
op = new TestNgOperation().mixed(true); op = new TestNgOperation().mixed(true);
assertThat(op.options.get("-mixed")).isEqualTo("true"); assertThat(op.options().get("-mixed")).isEqualTo("true");
} }
@Test @Test
void testName() { void testName() {
var op = new TestNgOperation().testName(FOO); var op = new TestNgOperation().testName(FOO);
assertThat(op.options.get("-testname")).isEqualTo("\"" + FOO + '\"'); assertThat(op.options().get("-testname")).isEqualTo("\"" + FOO + '\"');
} }
@Test @Test
void testNames() { void testNames() {
var ops = new TestNgOperation().testNames(FOO, BAR); var ops = new TestNgOperation().testNames(FOO, BAR);
assertThat(ops.options.get("-testnames")).isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR)); assertThat(ops.options().get("-testnames")).isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
new TestNgOperation().testNames(List.of(FOO, BAR)); new TestNgOperation().testNames(List.of(FOO, BAR));
assertThat(ops.options.get("-testnames")).as("as list").isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR)); assertThat(ops.options().get("-testnames")).as("as list").isEqualTo(String.format("\"%s\",\"%s\"", FOO, BAR));
} }
@Test @Test
void testObjectFactory() { void testObjectFactory() {
var ops = new TestNgOperation().objectFactory(FOO, BAR); var ops = new TestNgOperation().objectFactory(FOO, BAR);
assertThat(ops.options.get("-objectfactory")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-objectfactory")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().objectFactory(List.of(FOO, BAR)); ops = new TestNgOperation().objectFactory(List.of(FOO, BAR));
assertThat(ops.options.get("-objectfactory")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-objectfactory")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testOverrideIncludedMethods() { void testOverrideIncludedMethods() {
var ops = new TestNgOperation().overrideIncludedMethods(FOO, BAR); var ops = new TestNgOperation().overrideIncludedMethods(FOO, BAR);
assertThat(ops.options.get("-overrideincludedmethods")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-overrideincludedmethods")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().overrideIncludedMethods(List.of(FOO, BAR)); ops = new TestNgOperation().overrideIncludedMethods(List.of(FOO, BAR));
assertThat(ops.options.get("-overrideincludedmethods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-overrideincludedmethods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testPackages() { void testPackages() {
var op = new TestNgOperation().packages(FOO, BAR); var op = new TestNgOperation().packages(FOO, BAR);
assertThat(op.packages).contains(FOO).contains(BAR); assertThat(op.packages()).contains(FOO).contains(BAR);
op = new TestNgOperation().packages(List.of(FOO, BAR)); op = new TestNgOperation().packages(List.of(FOO, BAR));
assertThat(op.packages).as("as list").contains(FOO).contains(BAR); assertThat(op.packages()).as("as list").contains(FOO).contains(BAR);
} }
@Test @Test
void testParallel() { void testParallel() {
var op = new TestNgOperation().parallel(TestNgOperation.Parallel.TESTS); var op = new TestNgOperation().parallel(TestNgOperation.Parallel.TESTS);
assertThat(op.options.get("-parallel")).isEqualTo("tests"); assertThat(op.options().get("-parallel")).isEqualTo("tests");
op = new TestNgOperation().parallel(TestNgOperation.Parallel.METHODS); op = new TestNgOperation().parallel(TestNgOperation.Parallel.METHODS);
assertThat(op.options.get("-parallel")).isEqualTo("methods"); assertThat(op.options().get("-parallel")).isEqualTo("methods");
op = new TestNgOperation().parallel(TestNgOperation.Parallel.CLASSES); op = new TestNgOperation().parallel(TestNgOperation.Parallel.CLASSES);
assertThat(op.options.get("-parallel")).isEqualTo("classes"); assertThat(op.options().get("-parallel")).isEqualTo("classes");
} }
@Test @Test
void testPort() { void testPort() {
var op = new TestNgOperation().port(1); var op = new TestNgOperation().port(1);
assertThat(op.options.get("-port")).isEqualTo("1"); assertThat(op.options().get("-port")).isEqualTo("1");
} }
@Test @Test
void testPropagateDataProviderFailureAsTestFailure() { void testPropagateDataProviderFailureAsTestFailure() {
var op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(false); var op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(false);
assertThat(op.options.get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("false"); assertThat(op.options().get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("false");
op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(true); op = new TestNgOperation().propagateDataProviderFailureAsTestFailure(true);
assertThat(op.options.get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true"); assertThat(op.options().get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true");
} }
@Test @Test
void testReported() { void testReported() {
var op = new TestNgOperation().reporter(FOO); var op = new TestNgOperation().reporter(FOO);
assertThat(op.options.get("-reporter")).isEqualTo(FOO); assertThat(op.options().get("-reporter")).isEqualTo(FOO);
} }
@Test @Test
void testRunFactory() { void testRunFactory() {
var op = new TestNgOperation().testRunFactory(FOO); var op = new TestNgOperation().testRunFactory(FOO);
assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO); assertThat(op.options().get("-testrunfactory")).isEqualTo(FOO);
} }
@Test @Test
void testShareThreadPoolForDataProviders() { void testShareThreadPoolForDataProviders() {
var op = new TestNgOperation().shareThreadPoolForDataProviders(true); var op = new TestNgOperation().shareThreadPoolForDataProviders(true);
assertThat(op.options.get("-shareThreadPoolForDataProviders")).isEqualTo("true"); assertThat(op.options().get("-shareThreadPoolForDataProviders")).isEqualTo("true");
op = new TestNgOperation().shareThreadPoolForDataProviders(false); op = new TestNgOperation().shareThreadPoolForDataProviders(false);
assertThat(op.options.get("-shareThreadPoolForDataProviders")).isNull(); assertThat(op.options().get("-shareThreadPoolForDataProviders")).isNull();
} }
@Test @Test
void testSourceDir() { void testSourceDir() {
var op = new TestNgOperation().sourceDir(FOO, BAR); var op = new TestNgOperation().sourceDir(FOO, BAR);
assertThat(op.options.get("-sourcedir")).isEqualTo(String.format("%s;%s", FOO, BAR)); assertThat(op.options().get("-sourcedir")).isEqualTo(String.format("%s;%s", FOO, BAR));
op = new TestNgOperation().sourceDir(List.of(FOO, BAR)); op = new TestNgOperation().sourceDir(List.of(FOO, BAR));
assertThat(op.options.get("-sourcedir")).as("as list").isEqualTo(String.format("%s;%s", FOO, BAR)); assertThat(op.options().get("-sourcedir")).as("as list").isEqualTo(String.format("%s;%s", FOO, BAR));
} }
@Test @Test
void testSpiListenersToSkip() { void testSpiListenersToSkip() {
var ops = new TestNgOperation().spiListenersToSkip(FOO, BAR); var ops = new TestNgOperation().spiListenersToSkip(FOO, BAR);
assertThat(ops.options.get("-spilistenerstoskip")).isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-spilistenerstoskip")).isEqualTo(String.format("%s,%s", FOO, BAR));
ops = new TestNgOperation().spiListenersToSkip(List.of(FOO, BAR)); ops = new TestNgOperation().spiListenersToSkip(List.of(FOO, BAR));
assertThat(ops.options.get("-spilistenerstoskip")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR)); assertThat(ops.options().get("-spilistenerstoskip")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
} }
@Test @Test
void testSuiteName() { void testSuiteName() {
var op = new TestNgOperation().suiteName(FOO); var op = new TestNgOperation().suiteName(FOO);
assertThat(op.options.get("-suitename")).isEqualTo("\"" + FOO + '\"'); assertThat(op.options().get("-suitename")).isEqualTo("\"" + FOO + '\"');
} }
@Test @Test
void testSuiteThreadPoolSize() { void testSuiteThreadPoolSize() {
var op = new TestNgOperation().suiteThreadPoolSize(1); var op = new TestNgOperation().suiteThreadPoolSize(1);
assertThat(op.options.get("-suitethreadpoolsize")).isEqualTo("1"); assertThat(op.options().get("-suitethreadpoolsize")).isEqualTo("1");
} }
@Test @Test
void testSuites() { void testSuites() {
var op = new TestNgOperation().suites(FOO, BAR); var op = new TestNgOperation().suites(FOO, BAR);
assertThat(op.suites).contains(FOO).contains(BAR); assertThat(op.suites()).contains(FOO).contains(BAR);
op = new TestNgOperation().suites(List.of(FOO, BAR)); op = new TestNgOperation().suites(List.of(FOO, BAR));
assertThat(op.suites).as("as list").contains(FOO).contains(BAR); assertThat(op.suites()).as("as list").contains(FOO).contains(BAR);
} }
@Test @Test
void testThreadCount() { void testThreadCount() {
var op = new TestNgOperation().threadCount(1); var op = new TestNgOperation().threadCount(1);
assertThat(op.options.get("-threadcount")).isEqualTo("1"); assertThat(op.options().get("-threadcount")).isEqualTo("1");
} }
@Test @Test
void testThreadPoolFactoryClass() { void testThreadPoolFactoryClass() {
var op = new TestNgOperation().threadPoolFactoryClass(FOO); var op = new TestNgOperation().threadPoolFactoryClass(FOO);
assertThat(op.options.get("-threadpoolfactoryclass")).isEqualTo(FOO); assertThat(op.options().get("-threadpoolfactoryclass")).isEqualTo(FOO);
} }
@Test @Test
void testUseDefaultListeners() { void testUseDefaultListeners() {
var op = new TestNgOperation().useDefaultListeners(false); var op = new TestNgOperation().useDefaultListeners(false);
assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("false"); assertThat(op.options().get("-usedefaultlisteners")).isEqualTo("false");
op = new TestNgOperation().useDefaultListeners(true); op = new TestNgOperation().useDefaultListeners(true);
assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true"); assertThat(op.options().get("-usedefaultlisteners")).isEqualTo("true");
} }
@Test @Test
void testUseGlobalThreadPool() { void testUseGlobalThreadPool() {
var op = new TestNgOperation().useGlobalThreadPool(true); var op = new TestNgOperation().useGlobalThreadPool(true);
assertThat(op.options.get("-useGlobalThreadPool")).isEqualTo("true"); assertThat(op.options().get("-useGlobalThreadPool")).isEqualTo("true");
op = new TestNgOperation().useGlobalThreadPool(false); op = new TestNgOperation().useGlobalThreadPool(false);
assertThat(op.options.get("-useGlobalThreadPool")).isNull(); assertThat(op.options().get("-useGlobalThreadPool")).isNull();
} }
@Test @Test
void testVerbose() { void testVerbose() {
var op = new TestNgOperation().log(1); var op = new TestNgOperation().log(1);
assertThat(op.options.get("-log")).isEqualTo("1"); assertThat(op.options().get("-log")).isEqualTo("1");
op = new TestNgOperation().verbose(1); op = new TestNgOperation().verbose(1);
assertThat(op.options.get("-verbose")).isEqualTo("1"); assertThat(op.options().get("-verbose")).isEqualTo("1");
} }
@Test @Test
void testXmlPathInJar() { void testXmlPathInJar() {
var op = new TestNgOperation().xmlPathInJar(FOO); var op = new TestNgOperation().xmlPathInJar(FOO);
assertThat(op.options.get("-xmlpathinjar")).isEqualTo(FOO); assertThat(op.options().get("-xmlpathinjar")).isEqualTo(FOO);
} }
} }