Cleanup tests

This commit is contained in:
Erik C. Thauvin 2025-05-04 03:44:40 -07:00
parent fb3832ace9
commit 95df2d5838
Signed by: erik
GPG key ID: 776702A6A2DA330E
2 changed files with 181 additions and 111 deletions

View file

@ -411,7 +411,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
/** /**
* Sets the location of the HTML report. * Sets the location of the HTML report.
* *
* @param html the html * @param html the HTML
* @return this operation instance * @return this operation instance
*/ */
public JacocoReportOperation html(File html) { public JacocoReportOperation html(File html) {
@ -422,7 +422,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
/** /**
* Sets the location of the HTML report. * Sets the location of the HTML report.
* *
* @param html the html * @param html the HTML
* @return this operation instance * @return this operation instance
*/ */
public JacocoReportOperation html(String html) { public JacocoReportOperation html(String html) {
@ -432,7 +432,7 @@ public class JacocoReportOperation extends AbstractOperation<JacocoReportOperati
/** /**
* Sets the location of the HTML report. * Sets the location of the HTML report.
* *
* @param html the html * @param html the HTML
* @return this operation instance * @return this operation instance
*/ */
public JacocoReportOperation html(Path html) { public JacocoReportOperation html(Path html) {

View file

@ -17,6 +17,8 @@
package rife.bld.extension; package rife.bld.extension;
import org.assertj.core.api.AutoCloseableSoftAssertions; import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS; import org.junit.jupiter.api.condition.OS;
@ -61,7 +63,7 @@ class JacocoReportOperationTest {
@Test @Test
@EnabledOnOs(OS.LINUX) @EnabledOnOs(OS.LINUX)
void checkAllParamsTest() throws IOException { void checkAllParams() throws IOException {
var supported = List.of("<execfiles>", var supported = List.of("<execfiles>",
"--classfiles", "--classfiles",
"--csv", "--csv",
@ -79,131 +81,199 @@ class JacocoReportOperationTest {
} }
@Test @Nested
void executeFailureTest() { @DisplayName("Execute Tests")
var op = new JacocoReportOperation().fromProject(new Project()); class ExecuteTests {
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class); JacocoReportOperation newJacocoReportOperation() {
var op = new JacocoReportOperation()
.fromProject(new Project())
.csv(csv)
.html(html)
.xml(xml)
.classFiles(new File("src/test/resources/Examples.class"))
.sourceFiles(new File("examples/src/main/java"))
.execFiles(new File("src/test/resources/jacoco.exec"));
deleteOnExit(tempDir.toFile());
return op;
}
@Test
void execute() throws Exception {
newJacocoReportOperation().execute();
assertThat(csv).exists();
assertThat(html).isDirectory();
assertThat(xml).exists();
try (var softly = new AutoCloseableSoftAssertions()) {
try (var lines = Files.lines(xml.toPath())) {
softly.assertThat(lines.anyMatch(s ->
s.contains("<counter type=\"INSTRUCTION\" missed=\"0\" covered=\"3\"/>"))).isTrue();
}
}
assertThat(Path.of(html.getPath(), "com.example", "Examples.java.html")).exists();
}
@Test
void executeFailure() {
var op = new JacocoReportOperation().fromProject(new Project());
assertThatCode(op::execute).isInstanceOf(ExitStatusException.class);
}
} }
@Test @Nested
void executeTest() throws Exception { @DisplayName("File Operation Tests")
newJacocoReportOperation().execute(); class FilesOperationTests {
private final File bar = new File("bar");
private final File foo = new File("foo");
private final JacocoReportOperation op = new JacocoReportOperation();
assertThat(csv).exists(); @Nested
assertThat(html).isDirectory(); @DisplayName("Class Files Tests")
assertThat(xml).exists(); class ClassFilesTests {
try (var softly = new AutoCloseableSoftAssertions()) { @Test
try (var lines = Files.lines(xml.toPath())) { void classFilesAsFileArray() {
softly.assertThat(lines.anyMatch(s -> op.classFiles().clear();
s.contains("<counter type=\"INSTRUCTION\" missed=\"0\" covered=\"3\"/>"))).isTrue(); op.classFiles(foo, bar);
assertThat(op.classFiles()).contains(foo, bar);
}
@Test
void classFilesAsFileList() {
op.classFiles().clear();
op.classFiles(List.of(foo, bar));
assertThat(op.classFiles()).contains(foo, bar);
}
@Test
void classFilesAsPathArray() {
op.classFiles().clear();
op.classFiles(foo.toPath(), bar.toPath());
assertThat(op.classFiles()).contains(foo, bar);
}
@Test
void classFilesAsPathList() {
op.classFiles().clear();
op.classFilesPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.classFiles()).contains(foo, bar);
}
@Test
void classFilesAsStringArray() {
op.classFiles().clear();
op.classFiles("foo", "bar");
assertThat(op.classFiles()).contains(foo, bar);
}
@Test
void classFilesAsStringList() {
op.classFiles().clear();
op.classFilesStrings(List.of("foo", "bar"));
assertThat(op.classFiles()).contains(foo, bar);
} }
} }
assertThat(Path.of(html.getPath(), "com.example", "Examples.java.html")).exists();
} @Nested
@DisplayName("Exec Files Tests")
class ExecFilesTests {
private final File bar = new File("bar");
private final File foo = new File("foo");
private final JacocoReportOperation op = new JacocoReportOperation();
JacocoReportOperation newJacocoReportOperation() { @Test
var op = new JacocoReportOperation() void execFilesAsFileArray() {
.fromProject(new Project()) op.execFiles().clear();
.csv(csv) op.execFiles(foo, bar);
.html(html) assertThat(op.execFiles()).contains(foo, bar);
.xml(xml) }
.classFiles(new File("src/test/resources/Examples.class"))
.sourceFiles(new File("examples/src/main/java"))
.execFiles(new File("src/test/resources/jacoco.exec"));
deleteOnExit(tempDir.toFile()); @Test
void execFilesAsFileList() {
op.execFiles().clear();
op.execFiles(List.of(foo, bar));
assertThat(op.execFiles()).contains(foo, bar);
}
return op; @Test
} void execFilesAsPathArray() {
op.execFiles().clear();
op.execFiles(foo.toPath(), bar.toPath());
assertThat(op.execFiles()).contains(foo, bar);
}
@Test @Test
void testClassFiles() { void execFilesAsPathList() {
var foo = new File("foo"); op.execFiles().clear();
var bar = new File("bar"); op.execFilesPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.execFiles()).contains(foo, bar);
op.execFiles().clear();
}
var op = new JacocoReportOperation().classFiles("foo", "bar"); @Test
assertThat(op.classFiles()).as("String...").contains(foo, bar); void execFilesAsStringArray() {
op.classFiles().clear(); op.execFiles().clear();
op.execFiles("foo", "bar");
assertThat(op.execFiles()).contains(foo, bar);
}
op = op.classFiles(foo, bar); @Test
assertThat(op.classFiles()).as("File...").contains(foo, bar); void execFilesAsStringList() {
op.classFiles().clear(); op.execFiles().clear();
op.execFilesStrings(List.of("foo", "bar"));
assertThat(op.execFiles()).contains(foo, bar);
}
}
op = op.classFiles(foo.toPath(), bar.toPath()); @Nested
assertThat(op.classFiles()).as("Path...").contains(foo, bar); @DisplayName("Source Files Tests")
op.classFiles().clear(); class SourceFilesTests {
private final File bar = new File("bar");
private final File foo = new File("foo");
private final JacocoReportOperation op = new JacocoReportOperation();
op = op.classFilesStrings(List.of("foo", "bar")); @Test
assertThat(op.classFiles()).as("List(String...)").contains(foo, bar); void sourceFilesAsFileArray() {
op.classFiles().clear(); op.sourceFiles().clear();
op.sourceFiles(foo, bar);
assertThat(op.sourceFiles()).as("File...").contains(foo, bar);
}
op = op.classFiles(List.of(foo, bar)); @Test
assertThat(op.classFiles()).as("File...").contains(foo, bar); void sourceFilesAsFileList() {
op.classFiles().clear(); op.sourceFiles().clear();
op.sourceFiles(List.of(foo, bar));
assertThat(op.sourceFiles()).as("File...").contains(foo, bar);
}
op = op.classFilesPaths(List.of(foo.toPath(), bar.toPath())); @Test
assertThat(op.classFiles()).as("Path...").contains(foo, bar); void sourceFilesAsPathList() {
op.classFiles().clear(); op.sourceFiles().clear();
} op.sourceFilesPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.sourceFiles()).as("Path...").contains(foo, bar);
}
@Test @Test
void testExecFiles() { void sourceFilesAsStringArray() {
var foo = new File("foo"); op.sourceFiles().clear();
var bar = new File("bar"); op.sourceFiles("foo", "bar");
assertThat(op.sourceFiles()).as("String...").contains(foo, bar);
}
var op = new JacocoReportOperation().execFiles("foo", "bar"); @Test
assertThat(op.execFiles()).as("String...").contains(foo, bar); void sourceFilesAsStringList() {
op.execFiles().clear(); op.sourceFiles().clear();
op.sourceFilesStrings(List.of("foo", "bar"));
assertThat(op.sourceFiles()).as("List(String...)").contains(foo, bar);
}
op = op.execFiles(foo, bar); @Test
assertThat(op.execFiles()).as("File...").contains(foo, bar); void sourceFilesPathArray() {
op.execFiles().clear(); op.sourceFiles().clear();
op.sourceFiles(foo.toPath(), bar.toPath());
op = op.execFiles(foo.toPath(), bar.toPath()); assertThat(op.sourceFiles()).as("Path...").contains(foo, bar);
assertThat(op.execFiles()).as("Path...").contains(foo, bar); }
op.execFiles().clear(); }
op = op.execFilesStrings(List.of("foo", "bar"));
assertThat(op.execFiles()).as("List(String...)").contains(foo, bar);
op.execFiles().clear();
op = op.execFiles(List.of(foo, bar));
assertThat(op.execFiles()).as("File...").contains(foo, bar);
op.execFiles().clear();
op = op.execFilesPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.execFiles()).as("Path...").contains(foo, bar);
op.execFiles().clear();
}
@Test
void testSourceFiles() {
var foo = new File("foo");
var bar = new File("bar");
var op = new JacocoReportOperation().sourceFiles("foo", "bar");
assertThat(op.sourceFiles()).as("String...").contains(foo, bar);
op.sourceFiles().clear();
op = op.sourceFiles(foo, bar);
assertThat(op.sourceFiles()).as("File...").contains(foo, bar);
op.sourceFiles().clear();
op = op.sourceFiles(foo.toPath(), bar.toPath());
assertThat(op.sourceFiles()).as("Path...").contains(foo, bar);
op.sourceFiles().clear();
op = op.sourceFilesStrings(List.of("foo", "bar"));
assertThat(op.sourceFiles()).as("List(String...)").contains(foo, bar);
op.sourceFiles().clear();
op = op.sourceFiles(List.of(foo, bar));
assertThat(op.sourceFiles()).as("File...").contains(foo, bar);
op.sourceFiles().clear();
op = op.sourceFilesPaths(List.of(foo.toPath(), bar.toPath()));
assertThat(op.sourceFiles()).as("Path...").contains(foo, bar);
op.sourceFiles().clear();
} }
} }