diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0eb01c03c42..114b83f08a5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,11 +1,12 @@ [versions] aspectj-version = "1.9.24" byteBuddy-version = "1.17.7" -gsonVersion = "2.13.2" -guavaVersion = "33.4.8-jre" +gson-version = "2.13.2" +guava-version = "33.4.8-jre" jakarta-version = "3.0.0" junit4-version = "4.13.2" -paranamerVersion = "2.8.3" +mockito-version = "5.18.0" +paranamer-version = "2.8.3" slf4j-version = "2.0.17" spring-version = "6.2.11" androidx-test-version = "1.7.0" @@ -22,8 +23,8 @@ aspectj-jrt = { module = "org.aspectj:aspectjrt", version.ref = "aspectj-version aspectj-jweaver = { module = "org.aspectj:aspectjweaver", version.ref = "aspectj-version" } byteBuddy = { module = "net.bytebuddy:byte-buddy", version.ref = "byteBuddy-version" } byteBuddy-agent = { module = "net.bytebuddy:byte-buddy-agent", version.ref = "byteBuddy-version" } -gson = { module = "com.google.code.gson:gson", version.ref = "gsonVersion" } -guava = { module = "com.google.guava:guava", version.ref = "guavaVersion" } +gson = { module = "com.google.code.gson:gson", version.ref = "gson-version" } +guava = { module = "com.google.guava:guava", version.ref = "guava-version" } hypersql-database = { module = "org.hsqldb:hsqldb", version = "2.7.4" } jakarta-annotation = { module = "jakarta.annotation:jakarta.annotation-api", version.ref = "jakarta-version" } junit-bom = { module = "org.junit:junit-bom", version = "5.13.4" } @@ -32,7 +33,8 @@ junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher junit4 = { module = "junit:junit", version.ref = "junit4-version" } junit4-dataprovider = { module = "com.tngtech.java:junit-dataprovider", version = "1.13.1" } junit4-params = { module = "pl.pragmatists:JUnitParams", version = "1.1.1" } -paranamer = { module = "com.thoughtworks.paranamer:paranamer", version.ref = "paranamerVersion" } +mockito = { module = "org.mockito:mockito-core", version.ref = "mockito-version" } +paranamer = { module = "com.thoughtworks.paranamer:paranamer", version.ref = "paranamer-version" } publish = { module = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin", version.ref = "vanniktech-version" } quickcheck = { module = "net.java.quickcheck:quickcheck", version = "0.6" } slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j-version" } diff --git a/jgiven-asciidoc-report/README.md b/jgiven-asciidoc-report/README.md new file mode 100644 index 00000000000..6e0f5736a46 --- /dev/null +++ b/jgiven-asciidoc-report/README.md @@ -0,0 +1,5 @@ +# AsciiDoc Report + +This plug-in will generate test reports in the [AsciiDoc](https://asciidoc.org/) format. +It thus combines the simplicity of plain text with lean markup elements for structure, links etc. +Easily convertible to formats like HTML or PDF. diff --git a/jgiven-asciidoc-report/build.gradle b/jgiven-asciidoc-report/build.gradle new file mode 100644 index 00000000000..44076a4943c --- /dev/null +++ b/jgiven-asciidoc-report/build.gradle @@ -0,0 +1,10 @@ +plugins { + id 'java-library' + id 'jgiven-publishing' +} + +dependencies { + implementation libs.guava + implementation libs.slf4j.api + implementation project(':jgiven-core') +} diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocBlockConverter.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocBlockConverter.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocBlockConverter.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocBlockConverter.java diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfig.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfig.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfig.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfig.java diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java similarity index 85% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java index 9d2797c504e..4c37d558533 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java +++ b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGenerator.java @@ -12,8 +12,6 @@ import com.tngtech.jgiven.report.model.ReportStatistics; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.net.URL; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; @@ -101,7 +99,7 @@ private void writeFeatureFiles() { completeReportModel.getAllReportModels().stream() .sorted(Comparator.comparing(AsciiDocReportGenerator::byFeatureName)) .forEach(reportModelFile -> { - final String featureFileName = Files.getNameWithoutExtension( + final var featureFileName = Files.getNameWithoutExtension( reportModelFile.file().getName()) + ".asciidoc"; writeAsciiDocBlocksToFile(new File(featuresDir, featureFileName), collectReportBlocks(reportModelFile, featureFileName)); @@ -111,7 +109,7 @@ private void writeFeatureFiles() { private List collectReportBlocks(final ReportModelFile reportModelFile, final String featureFileName) { featureFiles.add(featureFileName); - final ReportStatistics statistics = completeReportModel.getStatistics(reportModelFile); + final var statistics = completeReportModel.getStatistics(reportModelFile); if (statistics.numFailedScenarios > 0) { failedScenarioFiles.add(featureFileName); } @@ -122,14 +120,14 @@ private List collectReportBlocks(final ReportModelFile reportModelFile, abortedScenarioFiles.add(featureFileName); } - final AsciiDocReportModelVisitor visitor = new AsciiDocReportModelVisitor(blockConverter, statistics); + final var visitor = new AsciiDocReportModelVisitor(blockConverter, statistics); reportModelFile.model().accept(visitor); return visitor.getResult(); } private void writeIndexFileForAllScenarios() { - final AsciiDocSnippetGenerator snippetGenerator = new AsciiDocSnippetGenerator( + final var snippetGenerator = new AsciiDocSnippetGenerator( "All Scenarios", "scenarios in total", this.featureFiles, "", this.completeReportModel.getTotalStatistics().numScenarios); @@ -138,8 +136,8 @@ private void writeIndexFileForAllScenarios() { } private void writeIndexFileForFailedScenarios() { - final String scenarioKind = "failed"; - final AsciiDocSnippetGenerator snippetGenerator = new AsciiDocSnippetGenerator( + final var scenarioKind = "failed"; + final var snippetGenerator = new AsciiDocSnippetGenerator( "Failed Scenarios", "failed scenarios", this.failedScenarioFiles, scenarioKind, this.completeReportModel.getTotalStatistics().numFailedScenarios); @@ -148,8 +146,8 @@ private void writeIndexFileForFailedScenarios() { } private void writeIndexFileForPendingScenarios() { - final String scenarioKind = "pending"; - final AsciiDocSnippetGenerator snippetGenerator = new AsciiDocSnippetGenerator( + final var scenarioKind = "pending"; + final var snippetGenerator = new AsciiDocSnippetGenerator( "Pending Scenarios", "pending scenarios", this.pendingScenarioFiles, scenarioKind, this.completeReportModel.getTotalStatistics().numPendingScenarios); @@ -158,8 +156,8 @@ private void writeIndexFileForPendingScenarios() { } private void writeIndexFileForAbortedScenarios() { - final String scenarioKind = "aborted"; - final AsciiDocSnippetGenerator snippetGenerator = new AsciiDocSnippetGenerator( + final var scenarioKind = "aborted"; + final var snippetGenerator = new AsciiDocSnippetGenerator( "Aborted Scenarios", "aborted scenarios", this.abortedScenarioFiles, scenarioKind, this.completeReportModel.getTotalStatistics().numAbortedScenarios); @@ -176,7 +174,7 @@ private void writeTotalStatisticsFile() { completeReportModel::getStatistics, MultimapBuilder.hashKeys().arrayListValues()::build)); - final String statisticsBlock = blockConverter.convertStatisticsBlock( + final var statisticsBlock = blockConverter.convertStatisticsBlock( featureStatistics, completeReportModel.getTotalStatistics()); writeAsciiDocBlocksToFile(new File(targetDir, "totalStatistics.asciidoc"), @@ -184,11 +182,11 @@ private void writeTotalStatisticsFile() { } private void writeIndexFileForFullReport(final String reportTitle) { - final URL resourceUrl = Resources.getResource(this.getClass(), "index.asciidoc"); + final var resourceUrl = Resources.getResource(this.getClass(), "index.asciidoc"); try { - final List indexLines = Resources.readLines(resourceUrl, Charset.defaultCharset()); + final var indexLines = Resources.readLines(resourceUrl, Charset.defaultCharset()); - try (PrintWriter writer = PrintWriterUtil.getPrintWriter(new File(targetDir, "index.asciidoc"))) { + try (var writer = PrintWriterUtil.getPrintWriter(new File(targetDir, "index.asciidoc"))) { writer.println("= " + reportTitle); indexLines.forEach(writer::println); } @@ -212,7 +210,7 @@ private static String byFeatureName(ReportModelFile modelFile) { } private static void writeAsciiDocBlocksToFile(final File file, final List asciiDocBlocks) { - try (final PrintWriter writer = PrintWriterUtil.getPrintWriter(file)) { + try (final var writer = PrintWriterUtil.getPrintWriter(file)) { for (final String block : asciiDocBlocks) { writer.println(block); writer.println(); diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitor.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitor.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitor.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitor.java diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGenerator.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGenerator.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGenerator.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGenerator.java diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/MetadataMapper.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/MetadataMapper.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/MetadataMapper.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/MetadataMapper.java diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java b/jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java similarity index 100% rename from jgiven-core/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java rename to jgiven-asciidoc-report/src/main/java/com/tngtech/jgiven/report/asciidoc/TagMapper.java diff --git a/jgiven-core/src/main/resources/com/tngtech/jgiven/report/asciidoc/index.asciidoc b/jgiven-asciidoc-report/src/main/resources/com/tngtech/jgiven/report/asciidoc/index.asciidoc similarity index 100% rename from jgiven-core/src/main/resources/com/tngtech/jgiven/report/asciidoc/index.asciidoc rename to jgiven-asciidoc-report/src/main/resources/com/tngtech/jgiven/report/asciidoc/index.asciidoc diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocFeatureBlockConverterTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocFeatureBlockConverterTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocFeatureBlockConverterTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocFeatureBlockConverterTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfigTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfigTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfigTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportConfigTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGeneratorTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGeneratorTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGeneratorTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportGeneratorTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitorTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitorTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitorTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocReportModelVisitorTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioBlockConverterTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioBlockConverterTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioBlockConverterTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioBlockConverterTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioCaseBlockConverterTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioCaseBlockConverterTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioCaseBlockConverterTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocScenarioCaseBlockConverterTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGeneratorTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGeneratorTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGeneratorTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocSnippetGeneratorTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocStepBlockConverterTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocStepBlockConverterTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocStepBlockConverterTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocStepBlockConverterTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocTableBlockConverterTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocTableBlockConverterTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocTableBlockConverterTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/AsciiDocTableBlockConverterTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/MetadataMapperTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/MetadataMapperTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/MetadataMapperTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/MetadataMapperTest.java diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java b/jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java similarity index 100% rename from jgiven-core/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java rename to jgiven-asciidoc-report/src/test/java/com/tngtech/jgiven/report/asciidoc/TagMapperTest.java diff --git a/jgiven-core/build.gradle b/jgiven-core/build.gradle index 65f650f34e6..30b2b215c8d 100644 --- a/jgiven-core/build.gradle +++ b/jgiven-core/build.gradle @@ -13,6 +13,7 @@ dependencies { implementation libs.byteBuddy implementation 'org.fusesource.jansi:jansi:2.4.2' + testImplementation libs.mockito testImplementation 'com.github.stefanbirkner:system-rules:1.19.0' } diff --git a/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java b/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java index 453fef97453..19cbcfc6c88 100644 --- a/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java +++ b/jgiven-core/src/main/java/com/tngtech/jgiven/report/ReportGenerator.java @@ -2,17 +2,18 @@ import com.tngtech.jgiven.exception.JGivenInstallationException; import com.tngtech.jgiven.exception.JGivenInternalDefectException; -import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; import com.tngtech.jgiven.report.config.ConfigOptionParser; import com.tngtech.jgiven.report.text.PlainTextReportGenerator; - import java.util.Arrays; /** * This is an interface to create a report based on command line flags */ public class ReportGenerator { - /** + private static final String ASCIIDOC_GENERATOR_FQCN = "com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator"; + private static final String HTML5_REPORT_GENERATOR_FQCN = "com.tngtech.jgiven.report.html5.Html5ReportGenerator"; + + /** * to create a custom report, extend this enum with the name of your choice */ public enum Format { @@ -43,39 +44,32 @@ public String formatName() { * Starts the respective report (default is HTML5) */ public void generate( String... args ) { - Format format = ConfigOptionParser.getFormat( args ); + var format = ConfigOptionParser.getFormat( args ); switch( format ) { case ASCIIDOC: - new AsciiDocReportGenerator().generateFromCommandLine( args ); + loadReportGenerator(ASCIIDOC_GENERATOR_FQCN).generateFromCommandLine(args); break; case TEXT: new PlainTextReportGenerator().generateFromCommandLine( args ); break; - case HTML: - case HTML5: + case HTML, HTML5: default: - ReportGenerator.generateHtml5Report().generateFromCommandLine( args ); + loadReportGenerator(HTML5_REPORT_GENERATOR_FQCN).generateFromCommandLine(args); break; } } - /** - * Searches the Html5ReportGenerator in Java path and instantiates the report - */ - public static AbstractReportGenerator generateHtml5Report() { - AbstractReportGenerator report; + private static AbstractReportGenerator loadReportGenerator(String fqcn) { try { - Class aClass = ReportGenerator.class.getClassLoader() - .loadClass( "com.tngtech.jgiven.report.html5.Html5ReportGenerator" ); - report = (AbstractReportGenerator) aClass.getDeclaredConstructor().newInstance(); + Class aClass = ReportGenerator.class.getClassLoader().loadClass(fqcn); + return (AbstractReportGenerator) aClass.getDeclaredConstructor().newInstance(); } catch( ClassNotFoundException e ) { - throw new JGivenInstallationException( "The JGiven HTML5 Report Generator seems not to be on the classpath.\n" - + "Ensure that you have a dependency to jgiven-html5-report." ); + throw new JGivenInstallationException( "The requested JGiven report generator seems not to be on the classpath.\n" + + "Ensure that you have a dependency to the corresponding plugin." ); } catch( Exception e ) { - throw new JGivenInternalDefectException( "The HTML5 Report Generator could not be instantiated.", e ); + throw new JGivenInternalDefectException( "The report generator could not be instantiated.", e ); } - return report; - } + } public static void main( String... args ) { new ReportGenerator().generate( args ); diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportConfigArgumentTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportConfigArgumentTest.java new file mode 100644 index 00000000000..c4801ff473c --- /dev/null +++ b/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportConfigArgumentTest.java @@ -0,0 +1,29 @@ +package com.tngtech.jgiven.report; + +import com.tngtech.jgiven.report.config.ConfigOption; +import java.io.File; +import java.util.List; +import java.util.Map; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ReportConfigArgumentTest { + + @Test + public void testArgumentParsing() { + var testConfig = new AbstractReportConfig("--sourceDir=source/dir", "--targetDir=target/dir") { + + @Override + public void useConfigMap(Map configMap) { + } + + @Override + public void additionalConfigOptions(List configOptions) { + } + }; + + assertThat(testConfig.getSourceDir()).isEqualTo(new File("source/dir")); + assertThat(testConfig.getTargetDir()).isEqualTo(new File("target/dir")); + } +} diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorArgumentTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorArgumentTest.java deleted file mode 100644 index f5f6cf9ab7a..00000000000 --- a/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorArgumentTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.tngtech.jgiven.report; - -import java.io.File; - -import com.tngtech.jgiven.report.asciidoc.AsciiDocReportConfig; -import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; -import org.assertj.core.api.Assertions; -import org.junit.Test; - -public class ReportGeneratorArgumentTest { - - @Test - public void testArgumentParsing() { - - AsciiDocReportGenerator asciiReport = new AsciiDocReportGenerator(); - - asciiReport.setConfig( asciiReport.createReportConfig( "--sourceDir=source/dir", "--targetDir=target/dir" ) ); - - Assertions.assertThat( asciiReport.config.getSourceDir() ).isEqualTo( new File( "source/dir" ) ); - Assertions.assertThat( asciiReport.config.getTargetDir() ).isEqualTo( new File( "target/dir" ) ); - } -} diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorTest.java deleted file mode 100644 index bed3db993a3..00000000000 --- a/jgiven-core/src/test/java/com/tngtech/jgiven/report/ReportGeneratorTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.tngtech.jgiven.report; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import com.tngtech.jgiven.exception.JGivenWrongUsageException; -import com.tngtech.jgiven.report.asciidoc.AsciiDocReportConfig; -import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; -import org.assertj.core.api.Assertions; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -public class ReportGeneratorTest { - - @Rule - public final TemporaryFolder tmpFolder = new TemporaryFolder(); - - @Test( expected = JGivenWrongUsageException.class ) - public void wrong_json_files_are_handled_gracefully() throws Exception { - File folder = tmpFolder.newFolder(); - - Files.asCharSink( new File( folder, "wrong.json" ), Charsets.UTF_8 ).write( "no json"); - - AsciiDocReportGenerator asciiReport = new AsciiDocReportGenerator(); - - AsciiDocReportConfig config = new AsciiDocReportConfig(); - config.setSourceDir( tmpFolder.getRoot() ); - config.setTargetDir( tmpFolder.getRoot() ); - - asciiReport.setConfig( config ); - asciiReport.loadReportModel(); - asciiReport.generate(); - } -} diff --git a/jgiven-core/src/test/java/com/tngtech/jgiven/report/json/ReportModelReaderTest.java b/jgiven-core/src/test/java/com/tngtech/jgiven/report/json/ReportModelReaderTest.java new file mode 100644 index 00000000000..a8e85bf47e3 --- /dev/null +++ b/jgiven-core/src/test/java/com/tngtech/jgiven/report/json/ReportModelReaderTest.java @@ -0,0 +1,39 @@ +package com.tngtech.jgiven.report.json; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; +import com.tngtech.jgiven.exception.JGivenWrongUsageException; +import com.tngtech.jgiven.report.AbstractReportConfig; +import java.io.File; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class ReportModelReaderTest { + + @Rule + public final TemporaryFolder tmpFolder = new TemporaryFolder(); + + @Mock + private AbstractReportConfig config; + + @Test + public void wrong_json_files_are_handled_gracefully() throws Exception { + var folder = tmpFolder.newFolder(); + + Files.asCharSink( new File( folder, "wrong.json" ), Charsets.UTF_8 ).write( "no json"); + + when(config.getSourceDir()).thenReturn(tmpFolder.getRoot()); + var reportModelReader = new ReportModelReader(config); + + assertThatThrownBy(reportModelReader::readDirectory).isInstanceOf(JGivenWrongUsageException.class) + .hasMessageContaining("Error while reading file"); + } +} diff --git a/jgiven-gradle-plugin/build.gradle b/jgiven-gradle-plugin/build.gradle index 11b3736d426..4f448c4188d 100644 --- a/jgiven-gradle-plugin/build.gradle +++ b/jgiven-gradle-plugin/build.gradle @@ -8,6 +8,7 @@ plugins { dependencies { implementation localGroovy() //we're a gradle plugin, we want to use the same groovy version as gradle implementation project(':jgiven-core') + implementation project(':jgiven-asciidoc-report') implementation project(':jgiven-html5-report') implementation(platform(libs.junit.bom)) implementation(libs.jakarta.annotation) diff --git a/jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/internal/AbstractJGivenReportImpl.java b/jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/internal/AbstractJGivenReportImpl.java index 849da1df5c8..0288124fee4 100644 --- a/jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/internal/AbstractJGivenReportImpl.java +++ b/jgiven-gradle-plugin/src/main/java/com/tngtech/jgiven/gradle/internal/AbstractJGivenReportImpl.java @@ -8,11 +8,14 @@ import com.tngtech.jgiven.report.asciidoc.AsciiDocReportConfig; import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; import com.tngtech.jgiven.report.html5.Html5ReportConfig; +import com.tngtech.jgiven.report.html5.Html5ReportGenerator; import com.tngtech.jgiven.report.text.PlainTextReportConfig; import com.tngtech.jgiven.report.text.PlainTextReportGenerator; import groovy.lang.Closure; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; +import java.io.File; +import org.gradle.api.NonNullApi; import org.gradle.api.Task; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.provider.Property; @@ -20,8 +23,7 @@ import org.gradle.api.tasks.Internal; import org.gradle.util.internal.ConfigureUtil; -import java.io.File; - +@NonNullApi public abstract class AbstractJGivenReportImpl implements JGivenReport { private File customCssFile; @@ -41,6 +43,7 @@ public AbstractJGivenReportImpl( String name, Task task, String relativeEntryPat this.getRequired().convention(false); } + @Override public AbstractReportGenerator createGenerator() { AbstractReportConfig conf; AbstractReportGenerator generator; @@ -56,7 +59,7 @@ public AbstractReportGenerator createGenerator() { case HTML: case HTML5: default: - Html5ReportConfig customConf = new Html5ReportConfig(); + var customConf = new Html5ReportConfig(); customConf.setShowThumbnails( isThumbnailsAreShown() ); if (getCustomCssFile() != null) { customConf.setCustomCss( getCustomCssFile() ); @@ -65,7 +68,7 @@ public AbstractReportGenerator createGenerator() { customConf.setCustomJs( getCustomJsFile() ); } conf = customConf; - generator = ReportGenerator.generateHtml5Report(); + generator = new Html5ReportGenerator(); break; } if( getTitle() != null ) { diff --git a/jgiven-junit/build.gradle b/jgiven-junit/build.gradle index 4ec400442d5..13b43bef442 100644 --- a/jgiven-junit/build.gradle +++ b/jgiven-junit/build.gradle @@ -11,8 +11,8 @@ dependencies { implementation project(':jgiven-html5-report') testImplementation libs.bundles.junit4 + testImplementation libs.mockito testImplementation "com.googlecode.junit-toolbox:junit-toolbox:2.4" - testImplementation "org.mockito:mockito-core:5.19.0" } test.finalizedBy(jgivenHtml5Report) diff --git a/jgiven-maven-plugin/build.gradle b/jgiven-maven-plugin/build.gradle index aa93c21bcc7..dcdd074a8b8 100644 --- a/jgiven-maven-plugin/build.gradle +++ b/jgiven-maven-plugin/build.gradle @@ -9,6 +9,7 @@ description = 'JGiven Maven Mojo' dependencies { implementation project(':jgiven-core') + implementation project(':jgiven-asciidoc-report') implementation project(':jgiven-html5-report') implementation "org.apache.maven.plugin-tools:maven-plugin-tools-api:3.15.1" implementation "org.apache.maven.plugin-tools:maven-plugin-annotations:3.15.1" diff --git a/jgiven-maven-plugin/src/main/java/com/tngtech/jgiven/maven/JGivenReportMojo.java b/jgiven-maven-plugin/src/main/java/com/tngtech/jgiven/maven/JGivenReportMojo.java index 3c0a10cfe49..4710ce92821 100644 --- a/jgiven-maven-plugin/src/main/java/com/tngtech/jgiven/maven/JGivenReportMojo.java +++ b/jgiven-maven-plugin/src/main/java/com/tngtech/jgiven/maven/JGivenReportMojo.java @@ -1,21 +1,20 @@ package com.tngtech.jgiven.maven; import com.tngtech.jgiven.report.AbstractReportConfig; -import com.tngtech.jgiven.report.AbstractReportGenerator; import com.tngtech.jgiven.report.ReportGenerator; import com.tngtech.jgiven.report.asciidoc.AsciiDocReportConfig; import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; import com.tngtech.jgiven.report.html5.Html5ReportConfig; +import com.tngtech.jgiven.report.html5.Html5ReportGenerator; import com.tngtech.jgiven.report.text.PlainTextReportConfig; import com.tngtech.jgiven.report.text.PlainTextReportGenerator; +import java.io.File; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; - @Mojo(name = "report", defaultPhase = LifecyclePhase.VERIFY, threadSafe = true) public class JGivenReportMojo extends AbstractMojo { @@ -88,7 +87,7 @@ public JGivenReportMojo(File buildDirectory, File outputDirectory, File sourceDi @Override public void execute() throws MojoExecutionException { - ReportGenerator.Format parsedFormat = ReportGenerator.Format.fromStringOrNull(format); + var parsedFormat = ReportGenerator.Format.fromStringOrNull(format); selectOutputDirectory(parsedFormat); try { if (!outputDirectory.exists() && !outputDirectory.mkdirs()) { @@ -105,28 +104,33 @@ public void execute() throws MojoExecutionException { getLog().info("Generating " + parsedFormat + " reports to " + outputDirectory + "..."); AbstractReportConfig config; - AbstractReportGenerator generator; - - switch (parsedFormat) { - case ASCIIDOC: + var generator = switch (parsedFormat) { + case ASCIIDOC -> { config = new AsciiDocReportConfig(); - generator = new AsciiDocReportGenerator(); - break; - case TEXT: + yield new AsciiDocReportGenerator(); + } + case TEXT -> { config = new PlainTextReportConfig(); - generator = new PlainTextReportGenerator(); - break; - case HTML: - case HTML5: - default: + yield new PlainTextReportGenerator(); + } + case HTML, HTML5 -> { Html5ReportConfig customConf = new Html5ReportConfig(); customConf.setShowThumbnails(thumbnailsAreShown); customConf.setCustomCss(customCssFile); customConf.setCustomJs(customJsFile); config = customConf; - generator = ReportGenerator.generateHtml5Report(); - break; - } + yield new Html5ReportGenerator(); + } + default -> { + Html5ReportConfig customConf = new Html5ReportConfig(); + customConf.setShowThumbnails(thumbnailsAreShown); + customConf.setCustomCss(customCssFile); + customConf.setCustomJs(customJsFile); + config = customConf; + yield new Html5ReportGenerator(); + } + }; + config.setTitle(title); config.setSourceDir(sourceDirectory); config.setTargetDir(outputDirectory); diff --git a/jgiven-testng/build.gradle b/jgiven-testng/build.gradle index 421dc5ff530..e332ece70d2 100644 --- a/jgiven-testng/build.gradle +++ b/jgiven-testng/build.gradle @@ -11,7 +11,7 @@ dependencies { compileOnly libs.testng testImplementation libs.testng - testImplementation "org.mockito:mockito-core:5.19.0" + testImplementation libs.mockito } test.useTestNG() { diff --git a/jgiven-tests/build.gradle b/jgiven-tests/build.gradle index 74178c5402e..857fb7f3fbe 100644 --- a/jgiven-tests/build.gradle +++ b/jgiven-tests/build.gradle @@ -7,6 +7,7 @@ dependencies { implementation project(':jgiven-junit') implementation project(':jgiven-testng') implementation project(':jgiven-junit5') + implementation project(':jgiven-asciidoc-report') implementation project(':jgiven-html5-report') implementation libs.bundles.junit4 implementation platform(libs.junit.bom) diff --git a/jgiven-tests/src/test/java/com/tngtech/jgiven/report/WhenReportGenerator.java b/jgiven-tests/src/test/java/com/tngtech/jgiven/report/WhenReportGenerator.java index 9819e64efbd..5e85ba5bbd8 100644 --- a/jgiven-tests/src/test/java/com/tngtech/jgiven/report/WhenReportGenerator.java +++ b/jgiven-tests/src/test/java/com/tngtech/jgiven/report/WhenReportGenerator.java @@ -9,6 +9,7 @@ import com.tngtech.jgiven.report.asciidoc.AsciiDocReportConfig; import com.tngtech.jgiven.report.asciidoc.AsciiDocReportGenerator; import com.tngtech.jgiven.report.html5.Html5ReportConfig; +import com.tngtech.jgiven.report.html5.Html5ReportGenerator; import com.tngtech.jgiven.report.model.CompleteReportModel; import com.tngtech.jgiven.report.text.PlainTextReportConfig; import com.tngtech.jgiven.report.text.PlainTextReportGenerator; @@ -83,7 +84,7 @@ public SELF the_report_generator_is_executed_with_format( Format format ) { case HTML: case HTML5: default: - ReportGenerator.generateHtml5Report().generateWithConfig( html5ReportConfig ); + new Html5ReportGenerator().generateWithConfig( html5ReportConfig ); } return self(); } diff --git a/jgiven-timing/build.gradle b/jgiven-timing/build.gradle index cefe5b0534e..8cc768f9f8e 100644 --- a/jgiven-timing/build.gradle +++ b/jgiven-timing/build.gradle @@ -13,8 +13,9 @@ dependencies { implementation("com.google.guava:guava:33.4.8-jre") implementation libs.plugins.byteBuddy.plugin implementation libs.byteBuddy.agent + + testImplementation libs.mockito testImplementation("com.google.guava:guava-testlib:33.4.8-jre") - testImplementation 'org.mockito:mockito-inline:5.2.0' } def generatedSourceDir = "generatedSrc/java" diff --git a/settings.gradle b/settings.gradle index 1d17b9f65b2..744279a52c7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -51,6 +51,7 @@ include ':jgiven-core', ':jgiven-spring-junit4', ':jgiven-html-app', ':jgiven-html5-report', + ':jgiven-asciidoc-report', ':jgiven-tests', ':jgiven-examples', ':jgiven-junit5',