diff --git a/src/main/java/rife/bld/extension/TestNgOperation.java b/src/main/java/rife/bld/extension/TestNgOperation.java index e73b396..c2e6f0f 100644 --- a/src/main/java/rife/bld/extension/TestNgOperation.java +++ b/src/main/java/rife/bld/extension/TestNgOperation.java @@ -49,14 +49,16 @@ public class TestNgOperation extends AbstractProcessOperation { */ protected final List packages = new ArrayList<>(); /** - * THe suites to run. + * The suites to run. */ protected final List suites = new ArrayList<>(); private final List args = new ArrayList<>(); private BaseProject project; /** - * Should Method Invocation Listeners be run even for skipped methods. Default is {@code true}. + * Should Method Invocation Listeners be run even for skipped methods. + * + *

Default is {@code true}

*/ public TestNgOperation alwaysRunListeners(Boolean isAlwaysRunListeners) { options.put("-alwaysrunlisteners", String.valueOf(isAlwaysRunListeners)); @@ -82,7 +84,9 @@ public class TestNgOperation extends AbstractProcessOperation { } /** - * The directory where the reports will be generated (defaults to {@code build/test-output}). + * The directory where the reports will be generated + * + *

Default is {@code build/test-output})

*/ public TestNgOperation directory(String directoryPath) { options.put("-d", directoryPath); @@ -128,19 +132,7 @@ public class TestNgOperation extends AbstractProcessOperation { args.addAll(suites); } else if (!options.containsKey(TEST_CLASS_ARG)) { try { - var temp = tempFile(); - try (var bufWriter = Files.newBufferedWriter(Paths.get(temp.getPath()))) { - bufWriter.write("" + - "" + - "" + - "" + - ""); - for (var p : packages) { - bufWriter.write(String.format("", p)); - } - bufWriter.write(""); - args.add(temp.getPath()); - } + args.add(writeDefaultSuite().getPath()); } catch (IOException ioe) { LOGGER.log(Level.SEVERE, "An IO error occurred while accessing the default testng.xml file", ioe); } @@ -182,7 +174,9 @@ public class TestNgOperation extends AbstractProcessOperation { } /** - * Should TestNG consider failures in Data Providers as test failures. Default is {@code false}. + * Should TestNG consider failures in Data Providers as test failures. + * + *

Default is {@code false}

. */ public TestNgOperation generateResultsPerSuite(Boolean resultsPerSuite) { options.put("-generateResultsPerSuite", String.valueOf(resultsPerSuite)); @@ -191,7 +185,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * The list of groups you want to run. - * For example: {@code "windows", "linux", "regression}. + * + *

For example: {@code "windows", "linux", "regression}

*/ public TestNgOperation groups(String... group) { options.put("-groups", String.join(",", group)); @@ -200,7 +195,9 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Ignore missed test names given by {@link #testNames(String...) testNames} and continue to run existing tests, - * if any. Default is {@code false}. + * if any. + * + *

Default is {@code false}

*/ public TestNgOperation ignoreMissedTestName(Boolean isIgnoreMissedTestNames) { options.put("-ignoreMissedTestNames", String.valueOf(isIgnoreMissedTestNames)); @@ -209,7 +206,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Should TestNG report all iterations of a data driven test as individual skips, in-case of upstream failures. - * Default is {@code false}. + * + *

Default is {@code false}

*/ public TestNgOperation includeAllDataDrivenTestsWhenSkipping(Boolean isIncludeDrivenTestsWhenSkipping) { options.put("-includeAllDataDrivenTestsWhenSkipping", String.valueOf(isIncludeDrivenTestsWhenSkipping)); @@ -218,7 +216,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Enables or disables the JUnit mode. - * Default is {@code false}. + * + *

Default is {@code false}

*/ public TestNgOperation jUnit(Boolean isJunit) { options.put("-junit", String.valueOf(isJunit)); @@ -246,7 +245,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Specifies the list of {@code .class} files or class names implementing {@code IMethodSelector}. - * For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"} + * + *

For example: {@code "com.example.Selector1:3", "com.example.Selector2:2"}

*/ public TestNgOperation methodSelectors(String... selector) { options.put("-methodselectors", String.join(",", selector)); @@ -255,7 +255,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Lets you specify individual methods to run. - * For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"} + * + *

For example: {@code "com.example.Foo.f1", "com.example.Bar.f2"}

*/ public TestNgOperation methods(String... method) { options.put("-methods", String.join(",", method)); @@ -264,7 +265,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Mixed mode autodetects the type of current test and run it with appropriate runner. - * Default is {@code false}. + * + *

Default is {@code false}

*/ public TestNgOperation mixed(Boolean isMixed) { options.put("-mixed", String.valueOf(isMixed)); @@ -290,9 +292,10 @@ public class TestNgOperation extends AbstractProcessOperation { /** * The list of packages to include in this test. - * For example: {@code "com.example", "test.sample.*"} * If the package name ends with .* then subpackages are included too. * Required if no {@link #suites(String... suites)} specified. + * + *

For example: {@code "com.example", "test.sample.*"}

*/ public TestNgOperation packages(String... name) { packages.addAll(Arrays.stream(name).toList()); @@ -321,7 +324,8 @@ public class TestNgOperation extends AbstractProcessOperation { /** * Should TestNG consider failures in Data Providers as test failures. - * Default is {@code false}. + * + *

Default is {@code false}

*/ public TestNgOperation propagateDataProviderFailureAsTestFailure(Boolean isPropagateDataProviderFailure) { options.put("-propagateDataProviderFailureAsTestFailure", String.valueOf(isPropagateDataProviderFailure)); @@ -374,7 +378,9 @@ public class TestNgOperation extends AbstractProcessOperation { } /** - * Specifies the suites to run. For example: {@code "testng.xml", "testng2.xml"}. + * Specifies the suites to run. + * + *

For example: {@code "testng.xml", "testng2.xml"}

*/ public TestNgOperation suites(String... suite) { suites.addAll(Arrays.stream(suite).toList()); @@ -391,7 +397,9 @@ public class TestNgOperation extends AbstractProcessOperation { } /** - * Specifies the list of class files. For example: {@code "org.foo.Test1","org.foo.test2"}. + * Specifies the list of class files. + * + *

For example: {@code "org.foo.Test1","org.foo.test2"}

*/ public TestNgOperation testClass(String... aClass) { options.put("-testclass", String.join(",", aClass)); @@ -452,7 +460,9 @@ public class TestNgOperation extends AbstractProcessOperation { } /** - * Whether to use the default listeners. Default is {@code true}. + * Whether to use the default listeners + * + *

Default is {@code true}

*/ public TestNgOperation useDefaultListeners(Boolean isDefaultListener) { options.put("-usedefaultlisteners", String.valueOf(isDefaultListener)); @@ -469,6 +479,22 @@ public class TestNgOperation extends AbstractProcessOperation { return this; } + private File writeDefaultSuite() throws IOException { + var temp = tempFile(); + try (var bufWriter = Files.newBufferedWriter(Paths.get(temp.getPath()))) { + bufWriter.write("" + + "" + + "" + + "" + + ""); + for (var p : packages) { + bufWriter.write(String.format("", p)); + } + bufWriter.write(""); + } + return temp; + } + /** * This attribute should contain the path to a valid XML file inside the test jar * (e.g. {@code "resources/testng.xml"}). The default is {@code testng.xml}, which means a file called