Skip to content

Commit

Permalink
Added array for the methods argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Jun 28, 2024
1 parent 8db60b4 commit 7aedfc7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
27 changes: 23 additions & 4 deletions src/main/java/rife/bld/extension/TestNgOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
public class TestNgOperation extends TestOperation<TestNgOperation, List<String>> {
private static final Logger LOGGER = Logger.getLogger(TestNgOperation.class.getName());
/**
* The classpath entries used for running tests.
* The methods to run.
*/
private final Set<String> testClasspath_ = new HashSet<>();
private final Set<String> methods_ = new HashSet<>();
/**
* The run options.
*/
Expand All @@ -56,6 +56,10 @@ public class TestNgOperation extends TestOperation<TestNgOperation, List<String>
* The suites to run.
*/
private final Set<String> suites_ = new HashSet<>();
/**
* The classpath entries used for running tests.
*/
private final Set<String> testClasspath_ = new HashSet<>();
private BaseProject project_;

/**
Expand Down Expand Up @@ -202,13 +206,19 @@ protected List<String> executeConstructProcessCommandList() {
}
}

if (!methods_.isEmpty()) {
args.add("-methods");
args.add(String.join(",", methods_));
}

if (LOGGER.isLoggable(Level.FINE) && !silent()) {
LOGGER.fine(String.join(" ", args));
}

if (LOGGER.isLoggable(Level.INFO) && !silent()) {
LOGGER.info(String.format("Report will be saved in file://%s",
new File(options_.get("-d")).toURI().getPath()));
}
}

return args;
Expand Down Expand Up @@ -441,7 +451,7 @@ public TestNgOperation methodSelectors(Collection<String> selector) {
* @see #methods(Collection) #methods(Collection)
*/
public TestNgOperation methods(String... method) {
options_.put("-methods", String.join(",", Arrays.stream(method).filter(this::isNotBlank).toList()));
methods_.addAll(List.of(method));
return this;
}

Expand All @@ -455,10 +465,19 @@ public TestNgOperation methods(String... method) {
* @see #methods(String...) #methods(String...)
*/
public TestNgOperation methods(Collection<String> method) {
options_.put("-methods", String.join(",", method.stream().filter(this::isNotBlank).toList()));
methods_.addAll(method);
return this;
}

/**
* Returns the methods to run.
*
* @return the set of methods
*/
public Set<String> methods() {
return methods_;
}

/**
* Mixed mode autodetects the type of current test and run it with appropriate runner.
*
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/rife/bld/extension/TestNgOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ void testExecute() {

assertThatCode(() ->
new TestNgOperation().fromProject(new Project())
.testClass("rife.bld.extension.TestNgExampleTest")
.methods("rife.bld.extension.TestNgExampleTest.verifyHello")
.methods("rife.bld.extension.TestNgExampleTest.foo")
.execute())
.as("with methods").doesNotThrowAnyException();
.as("with methods").isInstanceOf(ExitStatusException.class);

assertThatCode(() ->
new TestNgOperation().fromProject(new Project())
Expand Down Expand Up @@ -295,10 +294,10 @@ void testMethodDetectors() {
@Test
void testMethods() {
var op = new TestNgOperation().methods(FOO, BAR);
assertThat(op.options().get("-methods")).isEqualTo(String.format("%s,%s", FOO, BAR));
assertThat(op.methods()).containsExactly(BAR, FOO);

new TestNgOperation().methods(List.of(FOO, BAR));
assertThat(op.options().get("-methods")).as("as list").isEqualTo(String.format("%s,%s", FOO, BAR));
assertThat(op.methods()).containsExactly(BAR, FOO);
}

@Test
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<test name="simple test">
<classes>
<class name="rife.bld.extension.TestNgExample"/>
<methods>
<exclude name="foo"/>
</methods>
</class>
</classes>
</test>
</suite>

0 comments on commit 7aedfc7

Please sign in to comment.