From 177ad3d9613756ec9b459b65e59814f898d2f8bf Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sat, 22 Jun 2024 21:13:28 -0700 Subject: [PATCH] Added methods to access the map of options and sets --- .../rife/bld/extension/TestNgOperation.java | 204 ++++++++++-------- .../bld/extension/TestNgOperationTest.java | 144 +++++++------ 2 files changed, 197 insertions(+), 151 deletions(-) diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index 0d810c1..cf2ea52 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -39,23 +39,23 @@ @SuppressWarnings("PMD.TestClassWithoutTestCases") public class TestNgOperation extends TestOperation> { private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName()); + /** + * The classpath entries used for running tests. + */ + private final Set testClasspath_ = new HashSet<>(); /** * The run options. */ - protected final Map options = new ConcurrentHashMap<>(); + private final Map options_ = new ConcurrentHashMap<>(); /** * The suite packages to run. */ - protected final Set packages = new HashSet<>(); + private final Set packages_ = new HashSet<>(); /** * The suites to run. */ - protected final Set suites = new HashSet<>(); - /** - * The classpath entries used for running tests. - */ - protected final Set testClasspath = new HashSet<>(); - private BaseProject project; + private final Set suites_ = new HashSet<>(); + private BaseProject project_; /** * Should Method Invocation Listeners be run even for skipped methods. @@ -66,7 +66,7 @@ public class TestNgOperation extends TestOperation * @return this operation instance */ public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners) { - options.put("-alwaysrunlisteners", String.valueOf(isAlwaysRunListeners)); + options_.put("-alwaysrunlisteners", String.valueOf(isAlwaysRunListeners)); return this; } @@ -80,7 +80,7 @@ public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners) { */ public TestNgOperation dataProviderThreadCount(int count) { if (count >= 0) { - options.put("-dataproviderthreadcount", String.valueOf(count)); + options_.put("-dataproviderthreadcount", String.valueOf(count)); } return this; } @@ -93,7 +93,7 @@ public TestNgOperation dataProviderThreadCount(int count) { */ public TestNgOperation dependencyInjectorFactory(String injectorFactory) { if (isNotBlank(injectorFactory)) { - options.put("-dependencyinjectorfactory", injectorFactory); + options_.put("-dependencyinjectorfactory", injectorFactory); } return this; } @@ -108,7 +108,7 @@ public TestNgOperation dependencyInjectorFactory(String injectorFactory) { */ public TestNgOperation directory(String directoryPath) { if (isNotBlank(directoryPath)) { - options.put("-d", directoryPath); + options_.put("-d", directoryPath); } return this; } @@ -121,7 +121,7 @@ public TestNgOperation directory(String directoryPath) { * @see #excludeGroups(Collection) #excludeGroups(Collection) */ 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; } @@ -133,7 +133,7 @@ public TestNgOperation excludeGroups(String... group) { * @see #excludeGroups(String...) #excludeGroups(String...) */ public TestNgOperation excludeGroups(Collection 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; } @@ -144,39 +144,39 @@ public TestNgOperation excludeGroups(Collection group) { */ @Override protected List executeConstructProcessCommandList() { - if (project == null) { + if (project_ == null) { 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."); } - if (!options.containsKey("-d")) { - options.put("-d", Path.of(project.buildDirectory().getPath(), "test-output").toString()); + if (!options_.containsKey("-d")) { + options_.put("-d", Path.of(project_.buildDirectory().getPath(), "test-output").toString()); } final List args = new ArrayList<>(); args.add(javaTool()); - args.addAll(this.javaOptions()); + args.addAll(javaOptions()); args.add("-cp"); - if (testClasspath.isEmpty()) { - args.add(String.format("%s:%s:%s:%s", Path.of(project.libTestDirectory().getPath(), "*"), - Path.of(project.libCompileDirectory().getPath(), "*"), project.buildMainDirectory(), - project.buildTestDirectory())); + if (testClasspath_.isEmpty()) { + args.add(String.format("%s:%s:%s:%s", Path.of(project_.libTestDirectory().getPath(), "*"), + Path.of(project_.libCompileDirectory().getPath(), "*"), project_.buildMainDirectory(), + project_.buildTestDirectory())); } else { - args.add(String.join(":", testClasspath)); + args.add(String.join(":", testClasspath_)); } args.add("org.testng.TestNG"); - options.forEach((k, v) -> { + options_.forEach((k, v) -> { args.add(k); args.add(v); }); - if (!suites.isEmpty()) { - args.addAll(suites); - } else if (!options.containsKey("-testclass")) { + if (!suites_.isEmpty()) { + args.addAll(suites_); + } else if (!options_.containsKey("-testclass")) { try { args.add(writeDefaultSuite().getPath()); } catch (IOException ioe) { @@ -190,7 +190,7 @@ protected List executeConstructProcessCommandList() { if (LOGGER.isLoggable(Level.INFO)) { 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; @@ -204,7 +204,7 @@ protected List executeConstructProcessCommandList() { */ @Override public TestNgOperation fromProject(BaseProject project) { - this.project = project; + project_ = project; directory(Path.of(project.buildDirectory().getPath(), "test-output").toString()); return this; } @@ -216,7 +216,7 @@ public TestNgOperation fromProject(BaseProject project) { * @return this operation instance */ public TestNgOperation failWhenEverythingSkipped(Boolean isFailAllSkipped) { - options.put("-failwheneverythingskipped", String.valueOf(isFailAllSkipped)); + options_.put("-failwheneverythingskipped", String.valueOf(isFailAllSkipped)); return this; } @@ -228,7 +228,7 @@ public TestNgOperation failWhenEverythingSkipped(Boolean isFailAllSkipped) { * @return this operation instance */ public TestNgOperation failurePolicy(FailurePolicy policy) { - options.put("-configfailurepolicy", policy.name().toLowerCase(Locale.getDefault())); + options_.put("-configfailurepolicy", policy.name().toLowerCase(Locale.getDefault())); return this; } @@ -242,7 +242,7 @@ public TestNgOperation failurePolicy(FailurePolicy policy) { * @return this operation instance */ public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite) { - options.put("-generateResultsPerSuite", String.valueOf(resultsPerSuite)); + options_.put("-generateResultsPerSuite", String.valueOf(resultsPerSuite)); return this; } @@ -256,7 +256,7 @@ public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite) { * @see #groups(Collection) #groups(Collection) */ 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; } @@ -270,7 +270,7 @@ public TestNgOperation groups(String... group) { * @see #groups(String...) #groups(String...) */ public TestNgOperation groups(Collection 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; } @@ -284,7 +284,7 @@ public TestNgOperation groups(Collection group) { * @return this operation instance */ public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) { - options.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames)); + options_.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames)); return this; } @@ -297,7 +297,7 @@ public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) { * @return this operation instance */ public TestNgOperation includeAllDataDrivenTestsWhenSkipping(Boolean isIncludeDrivenTestsWhenSkipping) { - options.put("-includeAllDataDrivenTestsWhenSkipping", String.valueOf(isIncludeDrivenTestsWhenSkipping)); + options_.put("-includeAllDataDrivenTestsWhenSkipping", String.valueOf(isIncludeDrivenTestsWhenSkipping)); return this; } @@ -317,7 +317,7 @@ private boolean isNotBlank(String s) { * @return this operation instance */ public TestNgOperation jUnit(Boolean isJunit) { - options.put("-junit", String.valueOf(isJunit)); + options_.put("-junit", String.valueOf(isJunit)); return this; } @@ -330,7 +330,7 @@ public TestNgOperation jUnit(Boolean isJunit) { * @see #listener(Collection) #listener(Collection) */ 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; } @@ -343,7 +343,7 @@ public TestNgOperation listener(String... listener) { * @see #listener(String...) #listener(String...) */ public TestNgOperation listener(Collection 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; } @@ -355,7 +355,7 @@ public TestNgOperation listener(Collection listener) { * @return this operation instance */ public TestNgOperation listenerComparator(String listenerComparator) { - options.put("-listenercomparator", listenerComparator); + options_.put("-listenercomparator", listenerComparator); return this; } @@ -366,7 +366,7 @@ public TestNgOperation listenerComparator(String listenerComparator) { * @return this operation instance */ public TestNgOperation listenerFactory(String listenerFactory) { - options.put("-listenerfactory", listenerFactory); + options_.put("-listenerfactory", listenerFactory); return this; } @@ -379,7 +379,7 @@ public TestNgOperation listenerFactory(String listenerFactory) { */ public TestNgOperation log(int level) { if (level >= 0) { - options.put("-log", String.valueOf(level)); + options_.put("-log", String.valueOf(level)); } return this; } @@ -394,7 +394,7 @@ public TestNgOperation log(int level) { * @see #methodSelectors(Collection) #methodSelectors(Collection) */ public TestNgOperation methodSelectors(String... selector) { - options.put("-methodselectors", + options_.put("-methodselectors", String.join(",", Arrays.stream(selector).filter(this::isNotBlank).toList())); return this; } @@ -409,7 +409,7 @@ public TestNgOperation methodSelectors(String... selector) { * @see #methodSelectors(String...) #methodSelectors(String...) */ public TestNgOperation methodSelectors(Collection 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; } @@ -423,7 +423,7 @@ public TestNgOperation methodSelectors(Collection selector) { * @see #methods(Collection) #methods(Collection) */ 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; } @@ -437,7 +437,7 @@ public TestNgOperation methods(String... method) { * @see #methods(String...) #methods(String...) */ public TestNgOperation methods(Collection 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; } @@ -450,7 +450,7 @@ public TestNgOperation methods(Collection method) { * @return this operation instance */ public TestNgOperation mixed(Boolean isMixed) { - options.put("-mixed", String.valueOf(isMixed)); + options_.put("-mixed", String.valueOf(isMixed)); return this; } @@ -462,7 +462,7 @@ public TestNgOperation mixed(Boolean isMixed) { * @return this operation instance */ public TestNgOperation objectFactory(String objectFactory) { - options.put("-objectfactory", objectFactory); + options_.put("-objectfactory", objectFactory); return this; } @@ -474,7 +474,7 @@ public TestNgOperation objectFactory(String objectFactory) { * @see #objectFactory(Collection) #objectFactory(Collection) */ 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; } @@ -486,10 +486,19 @@ public TestNgOperation objectFactory(String... factory) { * @see #objectFactory(String...) #objectFactory(String...) */ public TestNgOperation objectFactory(Collection 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; } + /** + * Returns the run options. + * + * @return the map of run options + */ + public Map options() { + return options_; + } + /** * The list of fully qualified class names of listeners that should be skipped from being wired in via * Service Loaders. @@ -499,7 +508,7 @@ public TestNgOperation objectFactory(Collection factory) { * @see #overrideIncludedMethods(Collection) #overrideIncludedMethods(Collection) */ public TestNgOperation overrideIncludedMethods(String... method) { - options.put("-overrideincludedmethods", + options_.put("-overrideincludedmethods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList())); return this; } @@ -513,7 +522,7 @@ public TestNgOperation overrideIncludedMethods(String... method) { * @see #overrideIncludedMethods(String...) #overrideIncludedMethods(String...) */ public TestNgOperation overrideIncludedMethods(Collection 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; } @@ -529,7 +538,7 @@ public TestNgOperation overrideIncludedMethods(Collection method) { * @see #packages(Collection) #packages(Collection) */ 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; } @@ -545,10 +554,19 @@ public TestNgOperation packages(String... name) { * @see #packages(String...) #packages(String...) */ public TestNgOperation packages(Collection name) { - packages.addAll(name.stream().filter(this::isNotBlank).toList()); + packages_.addAll(name.stream().filter(this::isNotBlank).toList()); return this; } + /** + * Returns the suite packages to run. + * + * @return the set of packages + */ + public Set packages() { + return packages_; + } + /** * 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. @@ -559,7 +577,7 @@ public TestNgOperation packages(Collection name) { * @see Parallel */ public TestNgOperation parallel(Parallel mechanism) { - options.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault())); + options_.put("-parallel", mechanism.name().toLowerCase(Locale.getDefault())); return this; } @@ -571,7 +589,7 @@ public TestNgOperation parallel(Parallel mechanism) { */ public TestNgOperation port(int port) { if (port >= 1) { - options.put("-port", String.valueOf(port)); + options_.put("-port", String.valueOf(port)); } return this; } @@ -585,7 +603,7 @@ public TestNgOperation port(int port) { * @return this operation instance */ public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) { - options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure)); + options_.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure)); return this; } @@ -597,7 +615,7 @@ public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropa */ public TestNgOperation reporter(String reporter) { if (isNotBlank(reporter)) { - options.put("-reporter", reporter); + options_.put("-reporter", reporter); } return this; } @@ -610,7 +628,7 @@ public TestNgOperation reporter(String reporter) { */ public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolForDataProviders) { if (shareThreadPoolForDataProviders) { - options.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders)); + options_.put("-shareThreadPoolForDataProviders", String.valueOf(shareThreadPoolForDataProviders)); } return this; } @@ -625,7 +643,7 @@ public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolFo * @see #sourceDir(String...) #sourceDir(String...) */ 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; } @@ -639,7 +657,7 @@ public TestNgOperation sourceDir(String... directory) { * @see #sourceDir(String...) #sourceDir(String...) */ public TestNgOperation sourceDir(Collection 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; } @@ -652,7 +670,7 @@ public TestNgOperation sourceDir(Collection directory) { * @see #spiListenersToSkip(Collection) #spiListenersToSkip(Collection) */ public TestNgOperation spiListenersToSkip(String... listenerToSkip) { - options.put("-spilistenerstoskip", + options_.put("-spilistenerstoskip", String.join(",", Arrays.stream(listenerToSkip).filter(this::isNotBlank).toList())); return this; } @@ -666,7 +684,7 @@ public TestNgOperation spiListenersToSkip(String... listenerToSkip) { * @see #spiListenersToSkip(String...) #spiListenersToSkip(String...) */ public TestNgOperation spiListenersToSkip(Collection listenerToSkip) { - options.put("-spilistenerstoskip", + options_.put("-spilistenerstoskip", String.join(",", listenerToSkip.stream().filter(this::isNotBlank).toList())); return this; } @@ -680,7 +698,7 @@ public TestNgOperation spiListenersToSkip(Collection listenerToSkip) { */ public TestNgOperation suiteName(String name) { if (isNotBlank(name)) { - options.put("-suitename", '"' + name + '"'); + options_.put("-suitename", '"' + name + '"'); } return this; } @@ -694,7 +712,7 @@ public TestNgOperation suiteName(String name) { */ public TestNgOperation suiteThreadPoolSize(int poolSize) { if (poolSize >= 0) { - options.put("-suitethreadpoolsize", String.valueOf(poolSize)); + options_.put("-suitethreadpoolsize", String.valueOf(poolSize)); } return this; } @@ -709,7 +727,7 @@ public TestNgOperation suiteThreadPoolSize(int poolSize) { * @see #suites(Collection) #suites(Collection) */ 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; } @@ -723,10 +741,19 @@ public TestNgOperation suites(String... suite) { * @see #suites(String...) #suites(String...) */ public TestNgOperation suites(Collection suite) { - suites.addAll(suite.stream().filter(this::isNotBlank).toList()); + suites_.addAll(suite.stream().filter(this::isNotBlank).toList()); return this; } + /** + * Returns the suites to run. + * + * @return the set of suites + */ + public Set suites() { + return suites_; + } + /** * Create a test file and delete it on exit. * @@ -748,7 +775,7 @@ private File tempFile() throws IOException { * @see #testClass(Collection) #testClass(Collection) */ 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; } @@ -762,7 +789,7 @@ public TestNgOperation testClass(String... aClass) { * @see #testClass(String...) #testClass(String...) */ public TestNgOperation testClass(Collection 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; } @@ -774,7 +801,7 @@ public TestNgOperation testClass(Collection aClass) { * @see #testClasspath(String...) #testClasspath(String...) */ 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; } @@ -786,10 +813,19 @@ public TestNgOperation testClasspath(String... entry) { * @see #testClasspath(String...) #testClasspath(String...) */ public TestNgOperation testClasspath(Collection entry) { - testClasspath.addAll(entry.stream().filter(this::isNotBlank).toList()); + testClasspath_.addAll(entry.stream().filter(this::isNotBlank).toList()); return this; } + /** + * Returns the classpath entries used for running tests. + * + * @return the set of test classpath + */ + public Set testClasspath() { + return testClasspath_; + } + /** * 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 @@ -800,7 +836,7 @@ public TestNgOperation testClasspath(Collection entry) { */ public TestNgOperation testJar(String jar) { if (isNotBlank(jar)) { - options.put("-testjar", jar); + options_.put("-testjar", jar); } return this; } @@ -814,7 +850,7 @@ public TestNgOperation testJar(String jar) { */ public TestNgOperation testName(String name) { if (isNotBlank(name)) { - options.put("-testname", '"' + name + '"'); + options_.put("-testname", '"' + name + '"'); } return this; } @@ -827,7 +863,7 @@ public TestNgOperation testName(String name) { * @see #testNames(Collection) #testNames(Collection) */ public TestNgOperation testNames(String... name) { - options.put("-testnames", + options_.put("-testnames", Arrays.stream(name).filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(","))); return this; } @@ -840,7 +876,7 @@ public TestNgOperation testNames(String... name) { * @see #testName(String) #testName(String) */ public TestNgOperation testNames(Collection name) { - options.put("-testnames", + options_.put("-testnames", name.stream().filter(this::isNotBlank).map(s -> '"' + s + '"').collect(Collectors.joining(","))); return this; } @@ -853,7 +889,7 @@ public TestNgOperation testNames(Collection name) { */ public TestNgOperation testRunFactory(String factory) { if (isNotBlank(factory)) { - options.put("-testrunfactory", factory); + options_.put("-testrunfactory", factory); } return this; } @@ -868,7 +904,7 @@ public TestNgOperation testRunFactory(String factory) { */ public TestNgOperation threadCount(int count) { if (count >= 0) { - options.put("-threadcount", String.valueOf(count)); + options_.put("-threadcount", String.valueOf(count)); } return this; } @@ -881,7 +917,7 @@ public TestNgOperation threadCount(int count) { */ public TestNgOperation threadPoolFactoryClass(String factoryClass) { if (isNotBlank(factoryClass)) { - options.put("-threadpoolfactoryclass", factoryClass); + options_.put("-threadpoolfactoryclass", factoryClass); } return this; } @@ -895,7 +931,7 @@ public TestNgOperation threadPoolFactoryClass(String factoryClass) { * @return this operation instance */ public TestNgOperation useDefaultListeners(Boolean isDefaultListener) { - options.put("-usedefaultlisteners", String.valueOf(isDefaultListener)); + options_.put("-usedefaultlisteners", String.valueOf(isDefaultListener)); return this; } @@ -907,7 +943,7 @@ public TestNgOperation useDefaultListeners(Boolean isDefaultListener) { */ public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) { if (useGlobalThreadPool) { - options.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool)); + options_.put("-useGlobalThreadPool", String.valueOf(useGlobalThreadPool)); } return this; } @@ -921,7 +957,7 @@ public TestNgOperation useGlobalThreadPool(boolean useGlobalThreadPool) { */ public TestNgOperation verbose(int level) { if (level >= 0) { - options.put("-verbose", String.valueOf(level)); + options_.put("-verbose", String.valueOf(level)); } return this; } @@ -934,7 +970,7 @@ private File writeDefaultSuite() throws IOException { "" + "" + ""); - for (var p : packages) { + for (var p : packages_) { bufWriter.write(String.format("", p)); } bufWriter.write(""); @@ -952,7 +988,7 @@ private File writeDefaultSuite() throws IOException { */ public TestNgOperation xmlPathInJar(String path) { if (isNotBlank(path)) { - options.put("-xmlpathinjar", path); + options_.put("-xmlpathinjar", path); } return this; } diff --git a/src/test/java/rife/bld/extension/TestNgOperationTest.java b/src/test/java/rife/bld/extension/TestNgOperationTest.java index 01add27..c6c7bc2 100644 --- a/src/test/java/rife/bld/extension/TestNgOperationTest.java +++ b/src/test/java/rife/bld/extension/TestNgOperationTest.java @@ -43,10 +43,10 @@ class TestNgOperationTest { @Test void testAlwaysRunListeners() { 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); - assertThat(op.options.get("-alwaysrunlisteners")).isEqualTo("true"); + assertThat(op.options().get("-alwaysrunlisteners")).isEqualTo("true"); } @Test @@ -113,38 +113,44 @@ void testCheckAllParameters() throws IOException { @Test void testClass() { 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)); - assertThat(op.options.get("-testclass")).as("as list") + assertThat(op.options().get("-testclass")).as("as list") .isEqualTo(String.format("%s,%s", FOO, BAR)); } + @Test + void testClasspath() { + var op = new TestNgOperation().testClasspath(FOO, BAR); + assertThat(op.testClasspath()).containsExactly(BAR, FOO); + } + @Test void testDataProviderThreadCount() { var op = new TestNgOperation().dataProviderThreadCount(1); - assertThat(op.options.get("-dataproviderthreadcount")).isEqualTo("1"); + assertThat(op.options().get("-dataproviderthreadcount")).isEqualTo("1"); } @Test void testDependencyInjectorFactory() { var op = new TestNgOperation().dependencyInjectorFactory(FOO); - assertThat(op.options.get("-dependencyinjectorfactory")).isEqualTo(FOO); + assertThat(op.options().get("-dependencyinjectorfactory")).isEqualTo(FOO); } @Test void testDirectory() { var op = new TestNgOperation().directory(FOO); - assertThat(op.options.get("-d")).isEqualTo(FOO); + assertThat(op.options().get("-d")).isEqualTo(FOO); } @Test void testExcludeGroups() { 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)); - 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 @@ -201,276 +207,280 @@ void testExecute() { @Test void testFailWheneverEverythingSkipped() { 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); - assertThat(op.options.get("-failwheneverythingskipped")).isEqualTo("true"); + assertThat(op.options().get("-failwheneverythingskipped")).isEqualTo("true"); } @Test void testFailurePolicy() { 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); - assertThat(op.options.get("-configfailurepolicy")).isEqualTo("skip"); + assertThat(op.options().get("-configfailurepolicy")).isEqualTo("skip"); } @Test void testGenerateResultsPerSuite() { 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); - assertThat(op.options.get("-generateResultsPerSuite")).isEqualTo("true"); + assertThat(op.options().get("-generateResultsPerSuite")).isEqualTo("true"); } @Test void testGroups() { 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 void testIgnoreMissedTestName() { 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); - assertThat(op.options.get("-ignoreMissedTestNames")).isEqualTo("true"); + assertThat(op.options().get("-ignoreMissedTestNames")).isEqualTo("true"); } @Test void testIncludeAllDataDrivenTestsWhenSkipping() { 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); - assertThat(op.options.get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true"); + assertThat(op.options().get("-includeAllDataDrivenTestsWhenSkipping")).isEqualTo("true"); } @Test void testJar() { var op = new TestNgOperation().testJar(FOO); - assertThat(op.options.get("-testjar")).isEqualTo(FOO); + assertThat(op.options().get("-testjar")).isEqualTo(FOO); } @Test void testJunit() { 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); - assertThat(op.options.get("-junit")).isEqualTo("true"); + assertThat(op.options().get("-junit")).isEqualTo("true"); } @Test void testListener() { 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)); - 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 void testMethodDetectors() { 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)); - 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 void testMethods() { 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)); - 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 void testMixed() { 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); - assertThat(op.options.get("-mixed")).isEqualTo("true"); + assertThat(op.options().get("-mixed")).isEqualTo("true"); } @Test void testName() { var op = new TestNgOperation().testName(FOO); - assertThat(op.options.get("-testname")).isEqualTo("\"" + FOO + '\"'); + assertThat(op.options().get("-testname")).isEqualTo("\"" + FOO + '\"'); } @Test void testNames() { 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)); - 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 void testObjectFactory() { 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)); - 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 void testOverrideIncludedMethods() { 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)); - 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 void testPackages() { 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)); - assertThat(op.packages).as("as list").contains(FOO).contains(BAR); + assertThat(op.packages()).as("as list").contains(FOO).contains(BAR); } @Test void testParallel() { 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); - assertThat(op.options.get("-parallel")).isEqualTo("methods"); + assertThat(op.options().get("-parallel")).isEqualTo("methods"); op = new TestNgOperation().parallel(TestNgOperation.Parallel.CLASSES); - assertThat(op.options.get("-parallel")).isEqualTo("classes"); + assertThat(op.options().get("-parallel")).isEqualTo("classes"); } @Test void testPort() { var op = new TestNgOperation().port(1); - assertThat(op.options.get("-port")).isEqualTo("1"); + assertThat(op.options().get("-port")).isEqualTo("1"); } @Test void testPropagateDataProviderFailureAsTestFailure() { 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); - assertThat(op.options.get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true"); + assertThat(op.options().get("-propagateDataProviderFailureAsTestFailure")).isEqualTo("true"); } @Test void testReported() { var op = new TestNgOperation().reporter(FOO); - assertThat(op.options.get("-reporter")).isEqualTo(FOO); + assertThat(op.options().get("-reporter")).isEqualTo(FOO); } @Test void testRunFactory() { var op = new TestNgOperation().testRunFactory(FOO); - assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO); + assertThat(op.options().get("-testrunfactory")).isEqualTo(FOO); } @Test void testShareThreadPoolForDataProviders() { 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); - assertThat(op.options.get("-shareThreadPoolForDataProviders")).isNull(); + assertThat(op.options().get("-shareThreadPoolForDataProviders")).isNull(); } @Test void testSourceDir() { 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)); - 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 void testSpiListenersToSkip() { 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)); - 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 void testSuiteName() { var op = new TestNgOperation().suiteName(FOO); - assertThat(op.options.get("-suitename")).isEqualTo("\"" + FOO + '\"'); + assertThat(op.options().get("-suitename")).isEqualTo("\"" + FOO + '\"'); } @Test void testSuiteThreadPoolSize() { var op = new TestNgOperation().suiteThreadPoolSize(1); - assertThat(op.options.get("-suitethreadpoolsize")).isEqualTo("1"); + assertThat(op.options().get("-suitethreadpoolsize")).isEqualTo("1"); } @Test void testSuites() { 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)); - assertThat(op.suites).as("as list").contains(FOO).contains(BAR); + assertThat(op.suites()).as("as list").contains(FOO).contains(BAR); } @Test void testThreadCount() { var op = new TestNgOperation().threadCount(1); - assertThat(op.options.get("-threadcount")).isEqualTo("1"); + assertThat(op.options().get("-threadcount")).isEqualTo("1"); } @Test void testThreadPoolFactoryClass() { var op = new TestNgOperation().threadPoolFactoryClass(FOO); - assertThat(op.options.get("-threadpoolfactoryclass")).isEqualTo(FOO); + assertThat(op.options().get("-threadpoolfactoryclass")).isEqualTo(FOO); } @Test void testUseDefaultListeners() { 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); - assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true"); + assertThat(op.options().get("-usedefaultlisteners")).isEqualTo("true"); } @Test void testUseGlobalThreadPool() { 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); - assertThat(op.options.get("-useGlobalThreadPool")).isNull(); + assertThat(op.options().get("-useGlobalThreadPool")).isNull(); } @Test void testVerbose() { 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); - assertThat(op.options.get("-verbose")).isEqualTo("1"); + assertThat(op.options().get("-verbose")).isEqualTo("1"); } @Test void testXmlPathInJar() { var op = new TestNgOperation().xmlPathInJar(FOO); - assertThat(op.options.get("-xmlpathinjar")).isEqualTo(FOO); + assertThat(op.options().get("-xmlpathinjar")).isEqualTo(FOO); } }