Skip to content

Commit

Permalink
Cleaned up API to match bld operations aand options APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ethauvin committed Aug 28, 2024
1 parent 994bc39 commit 4e44484
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .idea/bld.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/lib/bld/bld-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.7
bld.extension-testng=com.uwyn.rife2:bld-testng:0.9.9
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.8-SNAPSHOT
bld.extension-testng=com.uwyn.rife2:bld-testng:1.0.0-SNAPSHOT
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
bld.sourceDirectories=
bld.version=2.0.1
7 changes: 2 additions & 5 deletions src/bld/java/rife/bld/extension/TestNgOperationBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@

import java.util.List;

import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
import static rife.bld.dependencies.Repository.MAVEN_LOCAL;
import static rife.bld.dependencies.Repository.RIFE2_RELEASES;
import static rife.bld.dependencies.Repository.RIFE2_SNAPSHOTS;
import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.compile;
import static rife.bld.dependencies.Scope.test;
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
Expand All @@ -36,7 +33,7 @@ public class TestNgOperationBuild extends Project {
public TestNgOperationBuild() {
pkg = "rife.bld.extension";
name = "bld-testng";
version = version(0, 9, 9);
version = version(1, 0, 0, "SNAPSHOT");

javaRelease = 17;

Expand Down
107 changes: 103 additions & 4 deletions src/main/java/rife/bld/extension/TestNgOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,30 @@ public TestNgOperation directory(String directoryPath) {
return this;
}

/**
* The directory where the reports will be generated
*
* <p>Default is {@code build/test-output})</p>
*
* @param directoryPath the directory path
* @return this operation instance
*/
public TestNgOperation directory(File directoryPath) {
return directory(directoryPath.getAbsolutePath());
}

/**
* The directory where the reports will be generated
*
* <p>Default is {@code build/test-output})</p>
*
* @param directoryPath the directory path
* @return this operation instance
*/
public TestNgOperation directory(Path directoryPath) {
return directory(directoryPath.toFile());
}

/**
* The list of groups you want to be excluded from this run.
*
Expand Down Expand Up @@ -678,11 +702,36 @@ public TestNgOperation shareThreadPoolForDataProviders(boolean shareThreadPoolFo
*
* @param directory one or more directories
* @return this operation instance
* @see #sourceDir(String...) #sourceDir(String...)
* @see #sourceDir(Collection)
*/
public TestNgOperation sourceDir(String... directory) {
options_.put("-sourcedir", String.join(";", Arrays.stream(directory).filter(this::isNotBlank).toList()));
return this;
return sourceDir(List.of(directory));
}

/**
* The directories where your javadoc annotated test sources are. This option is only necessary
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
*
* @param directory one or more directories
* @return this operation instance
* @see #sourceDirFiles(Collection)
*/
public TestNgOperation sourceDir(File... directory) {
return sourceDirFiles(List.of(directory));
}

/**
* The directories where your javadoc annotated test sources are. This option is only necessary
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
*
* @param directory one or more directories
* @return this operation instance
* @see #sourceDirPaths(Collection)
*/
public TestNgOperation sourceDir(Path... directory) {
return sourceDirPaths(List.of(directory));
}

/**
Expand All @@ -692,13 +741,39 @@ public TestNgOperation sourceDir(String... directory) {
*
* @param directory the list of directories
* @return this operation instance
* @see #sourceDir(String...) #sourceDir(String...)
* @see #sourceDir(String...)
*/
public TestNgOperation sourceDir(Collection<String> directory) {
options_.put("-sourcedir", String.join(";", directory.stream().filter(this::isNotBlank).toList()));
return this;
}

/**
* The directories where your javadoc annotated test sources are. This option is only necessary
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
*
* @param directory the list of directories
* @return this operation instance
* @see #sourceDir(File...)
*/
public TestNgOperation sourceDirFiles(Collection<File> directory) {
return sourceDir(directory.stream().map(File::getAbsolutePath).toList());
}

/**
* The directories where your javadoc annotated test sources are. This option is only necessary
* if you are using javadoc type annotations. (e.g. {@code "src/test"} or
* {@code "src/test/org/testng/eclipse-plugin", "src/test/org/testng/testng"}).
*
* @param directory the list of directories
* @return this operation instance
* @see #sourceDir(Path...)
*/
public TestNgOperation sourceDirPaths(Collection<Path> directory) {
return sourceDirFiles(directory.stream().map(Path::toFile).toList());
}

/**
* Specifies the List of fully qualified class names of listeners that should be skipped from being wired in via
* Service Loaders.
Expand Down Expand Up @@ -1031,6 +1106,30 @@ public TestNgOperation xmlPathInJar(String path) {
return this;
}

/**
* 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
* {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified.
*
* @param path the path
* @return this operation instance
*/
public TestNgOperation xmlPathInJar(File path) {
return xmlPathInJar(path.getAbsolutePath());
}

/**
* 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
* {@code testng.xml} at the root of the jar file. This option will be ignored unless a test jar is specified.
*
* @param path the path
* @return this operation instance
*/
public TestNgOperation xmlPathInJar(Path path) {
return xmlPathInJar(path.toFile());
}

/**
* Parallel Mechanisms
*/
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rife/bld/extension/TestNgExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
@SuppressWarnings("PMD.TestClassWithoutTestCases")
@SuppressWarnings({"PMD.TestClassWithoutTestCases", "unused"})
class TestNgExample {
public String getMessage() {
return "Hello World!";
Expand Down
1 change: 1 addition & 0 deletions src/test/java/rife/bld/extension/TestNgExampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
@SuppressWarnings("unused")
class TestNgExampleTest {
private final TestNgExample example = new TestNgExample();

Expand Down
40 changes: 36 additions & 4 deletions src/test/java/rife/bld/extension/TestNgOperationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,16 @@ void testDependencyInjectorFactory() {

@Test
void testDirectory() {
var foo = new File("FOO");

var op = new TestNgOperation().directory(FOO);
assertThat(op.options().get("-d")).isEqualTo(FOO);
assertThat(op.options().get("-d")).as("as string").isEqualTo(FOO);

op = new TestNgOperation().directory(foo);
assertThat(op.options().get("-d")).as("as file").isEqualTo(foo.getAbsolutePath());

op = new TestNgOperation().directory(foo.toPath());
assertThat(op.options().get("-d")).as("as path").isEqualTo(foo.getAbsolutePath());
}

@Test
Expand Down Expand Up @@ -401,11 +409,28 @@ void testShareThreadPoolForDataProviders() {

@Test
void testSourceDir() {
var foo = new File(FOO);
var bar = new File(BAR);

var foobar = String.format("%s;%s", 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")).as("String...").isEqualTo(foobar);

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("List(String...)").isEqualTo(foobar);

foobar = String.format("%s;%s", foo.getAbsolutePath(), bar.getAbsolutePath());
op = new TestNgOperation().sourceDir(foo, bar);
assertThat(op.options().get("-sourcedir")).as("File...").isEqualTo(foobar);

op = new TestNgOperation().sourceDirFiles(List.of(foo, bar));
assertThat(op.options().get("-sourcedir")).as("List(String...)").isEqualTo(foobar);

op = new TestNgOperation().sourceDir(foo.toPath(), bar.toPath());
assertThat(op.options().get("-sourcedir")).as("Path...").isEqualTo(foobar);

op = new TestNgOperation().sourceDirPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.options().get("-sourcedir")).as("List(Path...)").isEqualTo(foobar);
}

@Test
Expand Down Expand Up @@ -479,7 +504,14 @@ void testVerbose() {

@Test
void testXmlPathInJar() {
var foo = new File(FOO);
var op = new TestNgOperation().xmlPathInJar(FOO);
assertThat(op.options().get("-xmlpathinjar")).isEqualTo(FOO);
assertThat(op.options().get("-xmlpathinjar")).as("as string").isEqualTo(FOO);

op = new TestNgOperation().xmlPathInJar(foo);
assertThat(op.options().get("-xmlpathinjar")).as("as file").isEqualTo(foo.getAbsolutePath());

op = new TestNgOperation().xmlPathInJar(foo.toPath());
assertThat(op.options().get("-xmlpathinjar")).as("as path").isEqualTo(foo.getAbsolutePath());
}
}

0 comments on commit 4e44484

Please sign in to comment.