From e93921641a9c471a32edf8833a0774a900b4e3e7 Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Fri, 26 Oct 2018 16:56:43 +0200 Subject: [PATCH 1/9] Update bintray repo name --- README.md | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55a5a915f..4c389387a 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ mvn -DwithHistory org.pitest:pitest-maven:mutationCoverage ```xml - bintray-openfasttrack-maven-repo + itsallcode-maven-repo [bintray-username] [bintray-api-key] diff --git a/pom.xml b/pom.xml index d9524ec87..d025ecfc2 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ - bintray-openfasttrack-maven-repo + itsallcode-maven-repo https://api.bintray.com/maven/itsallcode/itsallcode/openfasttrace/;publish=0 From 81e636f2fd909e66fd6a257c28c2ea7911673047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=A4r?= Date: Fri, 26 Oct 2018 19:27:02 +0200 Subject: [PATCH 2/9] Releases from master --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55a5a915f..ef5e961c4 100644 --- a/README.md +++ b/README.md @@ -176,8 +176,8 @@ mvn -DwithHistory org.pitest:pitest-maven:mutationCoverage ```bash mvn deploy ``` - -1. Create a [release](https://github.com/itsallcode/openfasttrace/releases) on GitHub. +1. Merge to `master` branch +1. Create a [release](https://github.com/itsallcode/openfasttrace/releases) of the `master` branch on GitHub. 1. Sign in at [bintray.com](https://bintray.com) 1. Go to the [bintray project page](https://bintray.com/itsallcode/itsallcode/openfasttrace) 1. There should be a notice saying "You have 6 unpublished item(s) for this package". Click the "Publish" link. Binaries will be available for download at [jcenter](https://jcenter.bintray.com/org/itsallcode/openfasttrace/) From 929d2ee45e2b7e2058bf7a2d804dbe68c873937d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=A4r?= Date: Fri, 26 Oct 2018 19:32:57 +0200 Subject: [PATCH 3/9] Corrected capitalization --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ef5e961c4..1dcb3735e 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ mvn -DwithHistory org.pitest:pitest-maven:mutationCoverage 1. Merge to `master` branch 1. Create a [release](https://github.com/itsallcode/openfasttrace/releases) of the `master` branch on GitHub. 1. Sign in at [bintray.com](https://bintray.com) -1. Go to the [bintray project page](https://bintray.com/itsallcode/itsallcode/openfasttrace) -1. There should be a notice saying "You have 6 unpublished item(s) for this package". Click the "Publish" link. Binaries will be available for download at [jcenter](https://jcenter.bintray.com/org/itsallcode/openfasttrace/) +1. Go to the [Bintray project page](https://bintray.com/itsallcode/itsallcode/openfasttrace) +1. There should be a notice saying "You have 6 unpublished item(s) for this package". Click the "Publish" link. Binaries will be available for download at [JCenter](https://jcenter.bintray.com/org/itsallcode/openfasttrace/) 1. Publish to Maven Central by clicking the "Sync" button at https://bintray.com/itsallcode/itsallcode/openfasttrace#central. After some time the new version will appear at https://repo1.maven.org/maven2/org/itsallcode/openfasttrace/. From 0c8494d7d84fd86a2997006bd5ee71a1b240b8ee Mon Sep 17 00:00:00 2001 From: redcatbear Date: Fri, 26 Oct 2018 21:26:36 +0200 Subject: [PATCH 4/9] #159: Ported everything to JUnit5. --- .settings/org.eclipse.jdt.core.prefs | 2 + .settings/org.eclipse.jdt.ui.prefs | 4 +- README.md | 6 +- launch/OFT - Run all tests.launch | 33 - pom.xml | 662 +++++++++--------- .../openfasttrace/TestExportSettings.java | 20 +- .../openfasttrace/TestImportSettings.java | 20 +- .../openfasttrace/TestReportSettings.java | 28 +- .../openfasttrace/cli/ITestCliWithFilter.java | 94 ++- .../openfasttrace/cli/TestCliArguments.java | 52 +- .../openfasttrace/cli/TestCliExit.java | 25 +- .../openfasttrace/cli/TestCliStarter.java | 424 ++++++----- .../cli/TestCommandLineInterpreter.java | 62 +- .../core/TestChecksumCalculator.java | 12 +- .../openfasttrace/core/TestItemStatus.java | 18 +- .../core/TestLegacySpecificationItemId.java | 26 +- .../core/TestLinkedItemIndex.java | 18 +- .../core/TestLinkedSpecificationItem.java | 64 +- .../openfasttrace/core/TestLinker.java | 30 +- .../openfasttrace/core/TestLocation.java | 33 +- .../openfasttrace/core/TestNewline.java | 23 +- .../core/TestSpecificationItem.java | 47 +- .../core/TestSpecificationItemId.java | 39 +- .../openfasttrace/core/TestTracedLink.java | 10 +- .../openfasttrace/core/TestTracer.java | 14 +- .../TestInitializingServiceLoader.java | 12 +- .../specobject/TestSpecobjectExporter.java | 12 +- .../importer/ImporterFactoryTestBase.java | 36 +- .../importer/TestImportFilterSettings.java | 12 +- .../importer/TestImporterContext.java | 21 +- .../importer/TestImporterFactoryLoader.java | 29 +- .../importer/TestImporterService.java | 16 +- .../importer/TestLineReader.java | 47 +- .../importer/TestMultiFileImporter.java | 24 +- .../TestSpecificationListBuilder.java | 26 +- .../importer/input/TestRealFileInput.java | 39 +- .../importer/input/TestStreamInput.java | 22 +- .../importer/input/TestZipEntryInput.java | 54 +- .../importer/markdown/MarkdownAsserts.java | 2 +- .../markdown/TestMarkdownImporter.java | 26 +- .../markdown/TestMarkdownImporterFactory.java | 2 +- .../TestSpecobjectImportExport.java | 6 +- .../specobject/TestSpecobjectImporter.java | 24 +- .../TestSpecobjectImporterFactory.java | 2 +- .../importer/tag/TestTagImporter.java | 50 +- .../importer/tag/TestTagImporterFactory.java | 2 +- .../tag/TestTagImporterFactoryWithConfig.java | 51 +- .../tag/TestTagImporterWithConfig.java | 44 +- .../tag/config/DescribedPathMatcherTest.java | 40 +- .../importer/tag/config/TestPathConfig.java | 28 +- .../importer/zip/ITZipFileImporter.java | 41 +- .../zip/TestZipFileImporterFactory.java | 22 +- .../matcher/MatcherTestBase.java | 13 +- .../TestSpecificationItemIdMatcher.java | 12 +- .../matcher/TestSpecificationItemMatcher.java | 26 +- .../openfasttrace/mode/AbstractOftTest.java | 12 +- .../mode/ITestOftAsConverter.java | 17 +- .../mode/ITestOftAsReporter.java | 32 +- .../mode/ITestReporterWithFilter.java | 31 +- .../report/TestReportException.java | 10 +- .../report/TestReportFormat.java | 17 +- .../report/TestReportService.java | 57 +- .../report/html/TestHtmlReport.java | 14 +- .../html/TestHtmlReportCssInlining.java | 38 +- .../report/plaintext/TestPlainTextReport.java | 36 +- .../view/TestAbstractViewableContainer.java | 14 +- .../view/html/AbstractTestHtmlRenderer.java | 6 +- .../report/view/html/TestHtmlSection.java | 10 +- .../view/html/TestHtmlSpecificationItem.java | 20 +- .../report/view/html/TestHtmlView.java | 10 +- .../report/view/html/TestHtmlViewFactory.java | 8 +- .../view/html/TestMarkdownConverter.java | 38 +- .../view/html/TestOriginLinkFormatter.java | 24 +- .../openfasttrace/testutil/OsDetector.java | 8 +- 74 files changed, 1455 insertions(+), 1454 deletions(-) delete mode 100644 launch/OFT - Run all tests.launch diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index f4d834dae..966ab73d2 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -61,6 +61,8 @@ org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=next_line org.eclipse.jdt.core.formatter.brace_position_for_switch=next_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=next_line +org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false +org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs index 6d88ef0d1..f578da5b5 100644 --- a/.settings/org.eclipse.jdt.ui.prefs +++ b/.settings/org.eclipse.jdt.ui.prefs @@ -59,8 +59,8 @@ cleanup_profile=_ursusminor.de cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -formatter_profile=_ursusminor.de -formatter_settings_version=13 +formatter_profile=_itsallcode style +formatter_settings_version=14 org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.importorder=java;javax;org;com; org.eclipse.jdt.ui.ondemandthreshold=4 diff --git a/README.md b/README.md index 55a5a915f..c5f553aed 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,9 @@ The list below show all build time dependencies in alphabetical order. Note that | [Apache Maven](https://maven.apache.org/) | Build tool | Apache License 2.0 | | [Equals Verifier](https://github.com/jqno/equalsverifier) | Automatic contract checker for `equals()` and `hash()` | Apache License 2.0 | | [Hamcrest Auto Matcher](https://github.com/itsallcode/hamcrest-auto-matcher) | Speed-up for building Hamcrest matchers | GNU General Public License V3 | -| [JUnit](https://junit.org/junit4/index.html) | Unit testing framework | Eclipse Public License 1.0 | +| [JUnit](https://junit.org/junit5) | Unit testing framework | Eclipse Public License 1.0 | | [Mockito](http://site.mockito.org/) | Mocking framework | MIT License | -| [System rules](https://stefanbirkner.github.io/system-rules/) | JUnit rules for testing `STDOUT`, `STDIN` and `STDERR` | Common Public License 1.0 | +| [JUnit5 System Extensions](https://github.com/itsallcode/junit5-system-extensions) | JUnit extension for testing `System.x` calls | Eclipse Public License 2.0 | | [Pitest](http://pitest.org/) | Mutation testing | Apache License 2.0 | ### Essential Build Steps @@ -117,7 +117,7 @@ The list below show all build time dependencies in alphabetical order. Note that ### Using Eclipse -Import as a Maven project using *File > Import... > Maven > Existing Maven Projects* +Import as a Maven project using *"File" → "Import..." → "Maven" → "Existing Maven Projects"* ### Configure Logging diff --git a/launch/OFT - Run all tests.launch b/launch/OFT - Run all tests.launch deleted file mode 100644 index 245ab39d0..000000000 --- a/launch/OFT - Run all tests.launch +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index 924173cfc..6745bce51 100644 --- a/pom.xml +++ b/pom.xml @@ -1,323 +1,341 @@ - - 4.0.0 - org.itsallcode - openfasttrace - 2.0.0 - OpenFastTrace - Free requirement tracking suite - https://github.com/itsallcode/openfasttrace - - - GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - repo - - - - - redcatbear - https://github.com/redcatbear - itsallcode - https://github.com/itsallcode - - - sascha15432 - https://github.com/sascha15432 - itsallcode - https://github.com/itsallcode - - - kaklakariada - https://github.com/kaklakariada - itsallcode - https://github.com/itsallcode - github@chp1.net - - - - scm:git:https://github.com/itsallcode/openfasttrace.git - scm:git:https://github.com/itsallcode/openfasttrace.git - https://github.com/itsallcode/openfasttrace - - - - - jcenter - http://jcenter.bintray.com/ - - - - - - bintray-openfasttrack-maven-repo - https://api.bintray.com/maven/itsallcode/itsallcode/openfasttrace/;publish=0 - - - - - - - - junit - junit - 4.12 - test - - - org.hamcrest - hamcrest-all - 1.3 - test - - - org.mockito - mockito-core - 2.23.0 - test - - - com.github.stefanbirkner - system-rules - 1.18.0 - test - - - com.github.kaklakariada - hamcrest-auto-matcher - 0.4.3 - test - - - nl.jqno.equalsverifier - equalsverifier - 2.4.6 - test - - - - UTF-8 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - org.itsallcode.openfasttrace.cli.CliStarter - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.21.0 - - - ${basedir}/src/test/resources/logging.properties - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - - attach-javadocs - - jar - - - - - UTF-8 - - true - false - false - - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - - - prepare-agent - - - - report - test - - report - - - - - - org.codehaus.mojo - license-maven-plugin - 1.16 - - false - true - gpl_v3 - itsallcode.org - 2016 - - - test/resources/specobject/*.xml - - **/*.css - **/*.html - - true - true - true - true - UTF-8 - false - - - - check-file-header - - check-file-header - - validate - - - add-third-party-licenses - - add-third-party - third-party-report - download-licenses - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - trace - - java - - - - - org.itsallcode.openfasttrace.cli.CliStarter - trace -s doc src/main/java src/test/java - - - - org.pitest - pitest-maven - 1.4.0 - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.codehaus.mojo - - - license-maven-plugin - - - [1.8,) - - - - check-file-header - - add-third-party - - - - - - - - - - - - com.github.jeluard - plantuml-maven-plugin - 1.2 - - - ${basedir}/model/diagrams - - **/*.plantuml - - - svg - ${basedir}/doc/images/uml - - - - net.sourceforge.plantuml - plantuml - 8059 - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.21.0 - - - + + 4.0.0 + org.itsallcode + openfasttrace + 2.0.0 + OpenFastTrace + Free requirement tracking suite + https://github.com/itsallcode/openfasttrace + + 1.8 + 5.3.1 + 1.3.1 + UTF-8 + + + + GNU General Public License v3.0 + https://www.gnu.org/licenses/gpl-3.0.html + repo + + + + + redcatbear + https://github.com/redcatbear + itsallcode + https://github.com/itsallcode + + + sascha15432 + https://github.com/sascha15432 + itsallcode + https://github.com/itsallcode + + + kaklakariada + https://github.com/kaklakariada + itsallcode + https://github.com/itsallcode + github@chp1.net + + + + scm:git:https://github.com/itsallcode/openfasttrace.git + scm:git:https://github.com/itsallcode/openfasttrace.git + https://github.com/itsallcode/openfasttrace + + + + jcenter + http://jcenter.bintray.com/ + + + + + bintray-openfasttrack-maven-repo + https://api.bintray.com/maven/itsallcode/itsallcode/openfasttrace/;publish=0 + + + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.platform + junit-platform-launcher + ${junit.platform.version} + test + + + org.junit-pioneer + junit-pioneer + 0.2.2 + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.mockito + mockito-junit-jupiter + 2.23.0 + test + + + org.itsallcode + junit5-system-extensions + 1.0.1 + test + + + com.github.kaklakariada + hamcrest-auto-matcher + 0.4.3 + test + + + nl.jqno.equalsverifier + equalsverifier + 2.4.6 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + org.itsallcode.openfasttrace.cli.CliStarter + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.21.0 + + + ${basedir}/src/test/resources/logging.properties + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + + attach-javadocs + + jar + + + + + UTF-8 + + true + false + false + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + + prepare-agent + + + + report + test + + report + + + + + + org.codehaus.mojo + license-maven-plugin + 1.16 + + false + true + gpl_v3 + itsallcode.org + 2016 + + + test/resources/specobject/*.xml + + **/*.css + **/*.html + + true + true + true + true + UTF-8 + false + + + + check-file-header + + check-file-header + + validate + + + add-third-party-licenses + + add-third-party + third-party-report + download-licenses + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + trace + + java + + + + + org.itsallcode.openfasttrace.cli.CliStarter + trace -s doc src/main/java src/test/java + + + + org.pitest + pitest-maven + 1.4.0 + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.codehaus.mojo + + + license-maven-plugin + + + [1.8,) + + + + check-file-header + + add-third-party + + + + + + + + + + + + com.github.jeluard + plantuml-maven-plugin + 1.2 + + + ${basedir}/model/diagrams + + **/*.plantuml + + + svg + ${basedir}/doc/images/uml + + + + net.sourceforge.plantuml + plantuml + 8059 + + + + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.21.0 + + + diff --git a/src/test/java/org/itsallcode/openfasttrace/TestExportSettings.java b/src/test/java/org/itsallcode/openfasttrace/TestExportSettings.java index 731b26c9d..cc6eb0449 100644 --- a/src/test/java/org/itsallcode/openfasttrace/TestExportSettings.java +++ b/src/test/java/org/itsallcode/openfasttrace/TestExportSettings.java @@ -23,44 +23,44 @@ */ import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.itsallcode.openfasttrace.core.Newline; import org.itsallcode.openfasttrace.exporter.ExporterConstants; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestExportSettings +class TestExportSettings { private ExportSettings.Builder builder; - @Before - public void before() + @BeforeEach + void beforeEach() { this.builder = ExportSettings.builder(); } @Test - public void testDefaultOutputFormat() + void testDefaultOutputFormat() { assertThat(this.builder.build().getOutputFormat(), equalTo(ExporterConstants.DEFAULT_OUTPUT_FORMAT)); } @Test - public void testDefaultNewline() + void testDefaultNewline() { assertThat(this.builder.build().getNewline(), equalTo(Newline.UNIX)); } @Test - public void testBuildWithOutputFormat() + void testBuildWithOutputFormat() { assertThat(this.builder.outputFormat("foo").build().getOutputFormat(), equalTo("foo")); } @Test - public void testBuildWithNewline() + void testBuildWithNewline() { assertThat(this.builder.newline(Newline.OLDMAC).build().getNewline(), equalTo(Newline.OLDMAC)); diff --git a/src/test/java/org/itsallcode/openfasttrace/TestImportSettings.java b/src/test/java/org/itsallcode/openfasttrace/TestImportSettings.java index b209b4d0c..dd8951398 100644 --- a/src/test/java/org/itsallcode/openfasttrace/TestImportSettings.java +++ b/src/test/java/org/itsallcode/openfasttrace/TestImportSettings.java @@ -25,43 +25,43 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.collection.IsEmptyIterable.emptyIterableOf; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import org.itsallcode.openfasttrace.importer.tag.config.PathConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * This class implements a parameter object to control the settings of OFT's * export mode. */ -public class TestImportSettings +class TestImportSettings { @Test - public void testInputListEmptyByDefault() + void testInputListEmptyByDefault() { assertThat(ImportSettings.createDefault().getInputs(), emptyIterableOf(Path.class)); } @Test - public void testDefaultFilter() + void testDefaultFilter() { assertThat(ImportSettings.createDefault().getFilters(), equalTo(FilterSettings.createAllowingEverything())); } @Test - public void testDefaultPathConfigs() + void testDefaultPathConfigs() { assertThat(ImportSettings.createDefault().getPathConfigs(), emptyIterableOf(PathConfig.class)); } @Test - public void testAddInputList() + void testAddInputList() { final Path[] expectedInputs = { Paths.get("/a/path"), Paths.get("/another/path") }; assertThat(ImportSettings.builder().addInputs(Arrays.asList(expectedInputs)).build() @@ -69,7 +69,7 @@ public void testAddInputList() } @Test - public void testAddInputArray() + void testAddInputArray() { final Path[] expectedInputs = { Paths.get("/a/path"), Paths.get("/another/path") }; assertThat(ImportSettings.builder().addInputs(expectedInputs).build().getInputs(), @@ -77,7 +77,7 @@ public void testAddInputArray() } @Test - public void testBuildWithFilter() + void testBuildWithFilter() { final String[] expectedTags = { "a", "b" }; final FilterSettings filter = new FilterSettings.Builder() @@ -87,7 +87,7 @@ public void testBuildWithFilter() } @Test - public void testBuildWithPathConfigs() + void testBuildWithPathConfigs() { final List expectedPathConfigs = new ArrayList<>(); final PathConfig.Builder builder = PathConfig.builder(); diff --git a/src/test/java/org/itsallcode/openfasttrace/TestReportSettings.java b/src/test/java/org/itsallcode/openfasttrace/TestReportSettings.java index 270d50bce..20e731e9f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/TestReportSettings.java +++ b/src/test/java/org/itsallcode/openfasttrace/TestReportSettings.java @@ -23,70 +23,70 @@ */ import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.itsallcode.openfasttrace.ReportSettings.Builder; import org.itsallcode.openfasttrace.core.Newline; import org.itsallcode.openfasttrace.report.ReportVerbosity; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestReportSettings +class TestReportSettings { private Builder builder; - @Before - public void before() + @BeforeEach + void beforeEach() { this.builder = ReportSettings.builder(); } @Test - public void testDefaultVerbosity() + void testDefaultVerbosity() { assertThat(this.builder.build().getReportVerbosity(), equalTo(ReportVerbosity.FAILURE_DETAILS)); } @Test - public void testOriginNotShownByDefault() + void testOriginNotShownByDefault() { assertThat(this.builder.build().showOrigin(), equalTo(false)); } @Test - public void testDefaultOutputFormat() + void testDefaultOutputFormat() { assertThat(this.builder.build().getOutputFormat(), equalTo("plain")); } @Test - public void testDefaultNewline() + void testDefaultNewline() { assertThat(this.builder.build().getNewline(), equalTo(Newline.UNIX)); } @Test - public void testBuildWithVerbosity() + void testBuildWithVerbosity() { assertThat(this.builder.verbosity(ReportVerbosity.ALL).build().getReportVerbosity(), equalTo(ReportVerbosity.ALL)); } @Test - public void testBuildWithOriginShown() + void testBuildWithOriginShown() { assertThat(this.builder.showOrigin(true).build().showOrigin(), equalTo(true)); } @Test - public void testBuildWithOutputFormat() + void testBuildWithOutputFormat() { assertThat(this.builder.outputFormat("html").build().getOutputFormat(), equalTo("html")); } @Test - public void testBuildWithNewline() + void testBuildWithNewline() { assertThat(this.builder.newline(Newline.OLDMAC).build().getNewline(), equalTo(Newline.OLDMAC)); diff --git a/src/test/java/org/itsallcode/openfasttrace/cli/ITestCliWithFilter.java b/src/test/java/org/itsallcode/openfasttrace/cli/ITestCliWithFilter.java index 0d5344c0a..a52cbceb5 100644 --- a/src/test/java/org/itsallcode/openfasttrace/cli/ITestCliWithFilter.java +++ b/src/test/java/org/itsallcode/openfasttrace/cli/ITestCliWithFilter.java @@ -1,6 +1,7 @@ package org.itsallcode.openfasttrace.cli; -import static org.hamcrest.core.IsNot.not; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; /*- * #%L @@ -25,19 +26,25 @@ */ import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; +import static org.itsallcode.junit.sysextensions.AssertExit.assertExitWithStatus; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import org.itsallcode.io.CapturingOutputStream; +import org.itsallcode.junit.sysextensions.ExitGuard; +import org.itsallcode.junit.sysextensions.SystemOutGuard; import org.itsallcode.openfasttrace.testutil.AbstractFileBasedTest; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.ExpectedSystemExit; -import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; +@ExtendWith(TempDirectory.class) +@ExtendWith(ExitGuard.class) +@ExtendWith(SystemOutGuard.class) public class ITestCliWithFilter extends AbstractFileBasedTest { public static final String SPECIFICATION = String.join(System.lineSeparator(), // @@ -51,70 +58,59 @@ public class ITestCliWithFilter extends AbstractFileBasedTest "Tags: tag2", // "`impl~d~4`"); - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - @Rule - public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Rule - public final ExpectedSystemExit exit = ExpectedSystemExit.none(); - private File specFile; - @Before - public void before() throws IOException + @BeforeEach + void beforeEach(@TempDir final Path tempDir, final CapturingOutputStream stream) + throws IOException { - this.specFile = this.tempFolder.newFile("spec.md"); + this.specFile = tempDir.resolve("spec.md").toFile(); writeTextFile(this.specFile, SPECIFICATION); - this.exit.expectSystemExitWithStatus(0); + stream.capture(); } // [itest->dsn~filtering-by-tags-during-import~1] @Test - public void testWithoutFilter() + void testWithoutFilter(final CapturingOutputStream stream) { - this.exit.checkAssertionAfterwards(() -> { - final String stdOut = this.systemOutRule.getLog(); - assertThat(stdOut, containsString("a<")); - assertThat(stdOut, containsString("b<")); - assertThat(stdOut, containsString("c<")); - }); - runWithArguments("convert", this.specFile.toString()); + assertExitWithStatus(0, () -> runWithArguments("convert", this.specFile.toString())); + final String stdOut = stream.getCapturedData(); + assertThat(stdOut, containsString("a<")); + assertThat(stdOut, containsString("b<")); + assertThat(stdOut, containsString("c<")); } // [itest->dsn~filtering-by-tags-during-import~1] @Test - public void testFilterWithAtLeastOneMatchingTag() + void testFilterWithAtLeastOneMatchingTag(final CapturingOutputStream stream) { - this.exit.checkAssertionAfterwards(() -> { - final String stdOut = this.systemOutRule.getLog(); - assertThat(stdOut, not(containsString("a<"))); - assertThat(stdOut, containsString("b<")); - assertThat(stdOut, not(containsString("c<"))); - }); - runWithArguments("convert", "-t", "tag1", this.specFile.toString()); + assertExitWithStatus(0, + () -> runWithArguments("convert", "-t", "tag1", this.specFile.toString())); + final String stdOut = stream.getCapturedData(); + assertThat(stdOut, not(containsString("a<"))); + assertThat(stdOut, containsString("b<")); + assertThat(stdOut, not(containsString("c<"))); } // [itest->dsn~filtering-by-tags-during-import~1] @Test - public void testFilterWithEmptyTagListFiltersOutEverything() + void testFilterWithEmptyTagListFiltersOutEverything(final CapturingOutputStream stream) { - this.exit.checkAssertionAfterwards(() -> { - final String stdOut = this.systemOutRule.getLog(); - assertThat(stdOut, not(containsString(""))); - }); - runWithArguments("convert", "-t", "", this.specFile.toString()); + assertExitWithStatus(0, + () -> runWithArguments("convert", "-t", "", this.specFile.toString())); + final String stdOut = stream.getCapturedData(); + assertThat(stdOut, not(containsString(""))); } // [itest->dsn~filtering-by-tags-or-no-tags-during-import~1] @Test - public void testFilterWithAtLeastOneMatchingTagOrNoTags() + void testFilterWithAtLeastOneMatchingTagOrNoTags(final CapturingOutputStream stream) { - this.exit.checkAssertionAfterwards(() -> { - final String stdOut = this.systemOutRule.getLog(); - assertThat(stdOut, containsString("a<")); - assertThat(stdOut, containsString("b<")); - assertThat(stdOut, not(containsString("c<"))); - }); - runWithArguments("convert", "-t", "_,tag1", this.specFile.toString()); + assertExitWithStatus(0, + () -> runWithArguments("convert", "-t", "_,tag1", this.specFile.toString())); + final String stdOut = stream.getCapturedData(); + assertThat(stdOut, containsString("a<")); + assertThat(stdOut, containsString("b<")); + assertThat(stdOut, not(containsString("c<"))); } } \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliArguments.java b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliArguments.java index 17d0f25f1..7030f17ef 100644 --- a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliArguments.java +++ b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliArguments.java @@ -25,7 +25,7 @@ import static java.util.Arrays.asList; import static java.util.Collections.emptyList; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.nio.file.Paths; @@ -35,37 +35,37 @@ import org.itsallcode.openfasttrace.exporter.ExporterConstants; import org.itsallcode.openfasttrace.report.ReportConstants; import org.itsallcode.openfasttrace.report.ReportVerbosity; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestCliArguments +class TestCliArguments { private static final String AFTER_SETTER = "after setter"; private static final String BEFORE_SETTER = "before setter"; private CliArguments arguments; - @Before - public void testSetUp() + @BeforeEach + void testSetUp() { this.arguments = new CliArguments(); } @Test - public void testGetCommandWithUnnamedValuesNull() + void testGetCommandWithUnnamedValuesNull() { this.arguments.setUnnamedValues(null); assertThat(this.arguments.getCommand().isPresent(), is(false)); } @Test - public void testGetCommandWithUnnamedValuesEmpty() + void testGetCommandWithUnnamedValuesEmpty() { this.arguments.setUnnamedValues(emptyList()); assertThat(this.arguments.getCommand().isPresent(), is(false)); } @Test - public void testSetOutputFormat() + void testSetOutputFormat() { final String value = "foobar"; this.arguments.setOutputFormat(value); @@ -91,7 +91,7 @@ public void getStandardOutputFormatForReport() } @Test - public void testSetO() + void testSetO() { final String value = "foobar"; this.arguments.setO(value); @@ -104,7 +104,7 @@ private void assertAfterSetter(final String value, final String outputFormat) } @Test - public void testSetOutputFile() + void testSetOutputFile() { final String value = "/tmp/foobar"; final String expectedPath = Paths.get(value).toString(); @@ -114,7 +114,7 @@ public void testSetOutputFile() } @Test - public void testSetF() + void testSetF() { final String value = "/tmp/foobar"; final String expectedPath = Paths.get(value).toString(); @@ -124,7 +124,7 @@ public void testSetF() } @Test - public void testSetReportVerbositiy() + void testSetReportVerbositiy() { final ReportVerbosity value = ReportVerbosity.QUIET; assertThat(BEFORE_SETTER, this.arguments.getReportVerbosity(), @@ -134,7 +134,7 @@ public void testSetReportVerbositiy() } @Test - public void testSetV() + void testSetV() { final ReportVerbosity value = ReportVerbosity.QUIET; assertThat(BEFORE_SETTER, this.arguments.getReportVerbosity(), @@ -144,7 +144,7 @@ public void testSetV() } @Test - public void testSetNewline() + void testSetNewline() { final Newline value = Newline.OLDMAC; this.arguments.setNewline(value); @@ -152,7 +152,7 @@ public void testSetNewline() } @Test - public void testSetN() + void testSetN() { final Newline value = Newline.OLDMAC; this.arguments.setN(value); @@ -161,14 +161,14 @@ public void testSetN() // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testWantedArtifactTypesEmptyByDefault() + void testWantedArtifactTypesEmptyByDefault() { assertThat(BEFORE_SETTER, this.arguments.getWantedArtifactTypes(), emptyIterable()); } // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testSetIngnoreArtifactTypes() + void testSetIngnoreArtifactTypes() { final String value = "impl,utest"; this.arguments.setWantedArtifactTypes(value); @@ -178,7 +178,7 @@ public void testSetIngnoreArtifactTypes() // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testSetA() + void testSetA() { final String value = "impl,utest"; this.arguments.setA(value); @@ -188,14 +188,14 @@ public void testSetA() // [utest->dsn~filtering-by-tags-during-import~1] @Test - public void testWantedTagsEmptyByDefault() + void testWantedTagsEmptyByDefault() { assertThat(BEFORE_SETTER, this.arguments.getWantedTags(), emptyIterable()); } // [utest->dsn~filtering-by-tags-during-import~1] @Test - public void testSetWantedTags() + void testSetWantedTags() { final String value = "client,server"; this.arguments.setWantedTags(value); @@ -205,7 +205,7 @@ public void testSetWantedTags() // [utest->dsn~filtering-by-tags-during-import~1] @Test - public void testSetd() + void testSetd() { final String value = "client,server"; this.arguments.setT(value); @@ -215,7 +215,7 @@ public void testSetd() // [utest->dsn~filtering-by-tags-or-no-tags-during-import~1] @Test - public void testSetWantedTagsIncludingNone() + void testSetWantedTagsIncludingNone() { final String value = "_,client,server"; this.arguments.setWantedTags(value); @@ -228,7 +228,7 @@ public void testSetWantedTagsIncludingNone() // [utest->dsn~reporting.html.specification-item-origin~1] // [utest->dsn~reporting.html.linked-specification-item-origin~1] @Test - public void testShowOriginDisabledByDefault() + void testShowOriginDisabledByDefault() { assertThat(this.arguments.getShowOrigin(), is(false)); } @@ -238,7 +238,7 @@ public void testShowOriginDisabledByDefault() // [utest->dsn~reporting.html.specification-item-origin~1] // [utest->dsn~reporting.html.linked-specification-item-origin~1] @Test - public void testSetShowOrigin() + void testSetShowOrigin() { this.arguments.setShowOrigin(true); assertThat(this.arguments.getShowOrigin(), is(true)); @@ -249,7 +249,7 @@ public void testSetShowOrigin() // [utest->dsn~reporting.html.specification-item-origin~1] // [utest->dsn~reporting.html.linked-specification-item-origin~1] @Test - public void testSetS() + void testSetS() { this.arguments.setS(true); assertThat(this.arguments.getShowOrigin(), is(true)); diff --git a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliExit.java b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliExit.java index 54e7c5363..2af42a7f7 100644 --- a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliExit.java +++ b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliExit.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.cli; +import static org.itsallcode.junit.sysextensions.AssertExit.assertExitWithStatus; + /*- * #%L \* OpenFastTrace @@ -26,27 +28,21 @@ import java.util.Arrays; import java.util.List; -import org.itsallcode.openfasttrace.cli.CliArguments; -import org.itsallcode.openfasttrace.cli.CliStarter; -import org.itsallcode.openfasttrace.cli.ExitStatus; +import org.itsallcode.junit.sysextensions.ExitGuard; import org.itsallcode.openfasttrace.cli.commands.TraceCommand; -import org.junit.Rule; - - -import org.junit.Test; -import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; -public class TestCliExit +@ExtendWith(ExitGuard.class) +class TestCliExit { private static final String TEST_RESOURCES_MARKDOWN = "src/test/resources/markdown"; private static final String SAMPLE_DESIGN = TEST_RESOURCES_MARKDOWN + "/sample_design.md"; private static final String SAMPLE_SYSTEM_REQUIREMENTS = TEST_RESOURCES_MARKDOWN + "/sample_system_requirements.md"; - @Rule - public final ExpectedSystemExit exit = ExpectedSystemExit.none(); @Test - public void testCliExitCode_Ok() + void testCliExitCode_Ok() { assertExitStatusForTracedFiles(ExitStatus.OK, SAMPLE_SYSTEM_REQUIREMENTS, SAMPLE_DESIGN); } @@ -65,12 +61,11 @@ private void assertExitStatusForCommandWithFiles(final ExitStatus expectedStatus values.add(command); values.addAll(Arrays.asList(files)); arguments.setUnnamedValues(values); - this.exit.expectSystemExitWithStatus(expectedStatus.getCode()); - new CliStarter(arguments).run(); + assertExitWithStatus(expectedStatus.getCode(), () -> new CliStarter(arguments).run()); } @Test - public void testCliExitCode_Failure() + void testCliExitCode_Failure() { assertExitStatusForTracedFiles(ExitStatus.FAILURE, SAMPLE_SYSTEM_REQUIREMENTS); } diff --git a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliStarter.java b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliStarter.java index f075583c4..a488142ae 100644 --- a/src/test/java/org/itsallcode/openfasttrace/cli/TestCliStarter.java +++ b/src/test/java/org/itsallcode/openfasttrace/cli/TestCliStarter.java @@ -21,29 +21,38 @@ * . * #L% */ +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.itsallcode.junit.sysextensions.AssertExit.assertExitWithStatus; +import static org.junit.jupiter.api.Assertions.assertAll; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; - -import java.io.*; +import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.Assertion; -import org.junit.contrib.java.lang.system.ExpectedSystemExit; -import org.junit.rules.TemporaryFolder; - -public class TestCliStarter +import org.itsallcode.io.Capturable; +import org.itsallcode.junit.sysextensions.ExitGuard; +import org.itsallcode.junit.sysextensions.SystemErrGuard; +import org.itsallcode.junit.sysextensions.SystemErrGuard.SysErr; +import org.itsallcode.junit.sysextensions.SystemOutGuard; +import org.itsallcode.junit.sysextensions.SystemOutGuard.SysOut; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; +import org.opentest4j.MultipleFailuresError; + +@ExtendWith(TempDirectory.class) +@ExtendWith(ExitGuard.class) +@ExtendWith(SystemOutGuard.class) +@ExtendWith(SystemErrGuard.class) +// [itest->dsn~cli.tracing.exit-status~1] +class TestCliStarter { - private static final String NEWLINE = "\n"; - private static final String CARRIAGE_RETURN = "\r"; private static final String REQM2_PREAMBLE = ""; private static final String ILLEGAL_COMMAND = "illegal"; private static final String NEWLINE_PARAMETER = "--newline"; @@ -53,315 +62,298 @@ public class TestCliStarter private static final String REPORT_VERBOSITY_PARAMETER = "--report-verbosity"; private static final String OUTPUT_FORMAT_PARAMETER = "--output-format"; private static final String WANTED_ARTIFACT_TYPES_PARAMETER = "--wanted-artifact-types"; - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + private static final String CARRIAGE_RETURN = "\r"; + private static final String NEWLINE = "\n"; private Path docDir; private Path outputFile; - @Rule - public final ExpectedSystemExit exit = ExpectedSystemExit.none(); - private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - private final ByteArrayOutputStream error = new ByteArrayOutputStream(); - - @Before - public void setUp() throws UnsupportedEncodingException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws UnsupportedEncodingException { this.docDir = Paths.get("src", "test", "resources", "markdown").toAbsolutePath(); - this.outputFile = this.tempFolder.getRoot().toPath().resolve("stream.txt"); - System.setOut(new PrintStream(this.outputStream, true, "UTF-8")); - System.setErr(new PrintStream(this.error, true, "UTF-8")); + this.outputFile = tempDir.resolve("stream.txt"); } @Test - public void testNoArguments() + void testNoArguments(@SysErr final Capturable err) { - expectCliExitOnErrorThatStartsWith(ExitStatus.CLI_ERROR, "oft: Missing command"); - runCliStarter(); + assertExitWithError(() -> runCliStarter(), ExitStatus.CLI_ERROR, "oft: Missing command", + err); + } + private void assertExitWithError(final Runnable runnable, final ExitStatus status, + final String message, final Capturable stream) throws MultipleFailuresError + { + stream.capture(); + assertAll( // + () -> assertExitWithStatus(status.getCode(), runnable), + () -> assertThat(stream.getCapturedData(), startsWith(message)) // + ); } // [itest->dsn~cli.command-selection~1] @Test - public void testIllegalCommand() + void testIllegalCommand(@SysErr final Capturable err) { - - expectCliExitOnErrorThatStartsWith(ExitStatus.CLI_ERROR, - "oft: '" + ILLEGAL_COMMAND + "' is not an OFT command."); - runCliStarter(ILLEGAL_COMMAND); + assertExitWithError(() -> runCliStarter(ILLEGAL_COMMAND), ExitStatus.CLI_ERROR, + "oft: '" + ILLEGAL_COMMAND + "' is not an OFT command.", err); } // [itest->dsn~cli.command-selection~1] @Test - public void testConvertWithoutExplicitInputs() + void testConvertWithoutExplicitInputs(@SysOut final Capturable out) + { + assertExitOkWithStdOutStart(() -> runCliStarter(CONVERT_COMMAND), REQM2_PREAMBLE, out); + + } + + private void assertExitOkWithStdOutStart(final Runnable runnable, final String outputStart, + final Capturable out) throws MultipleFailuresError { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(false); - assertStdOutStartsWith(REQM2_PREAMBLE); - }); - runCliStarter(CONVERT_COMMAND); + out.capture(); + assertAll(() -> { + assertExitWithStatus(ExitStatus.OK.getCode(), runnable); + }, () -> assertOutputFileExists(false), // + () -> { + assertThat(out.getCapturedData(), startsWith(outputStart)); + }); } @Test - public void testConvertUnknownExporter() + void testConvertUnknownExporter(@SysErr final Capturable err) { - expectCliExitOnErrorThatStartsWith(ExitStatus.CLI_ERROR, - "oft: export format 'illegal' is not supported."); - runCliStarter(CONVERT_COMMAND, this.docDir.toString(), OUTPUT_FORMAT_PARAMETER, "illegal", + final Runnable runnable = () -> runCliStarter( // + CONVERT_COMMAND, this.docDir.toString(), // + OUTPUT_FORMAT_PARAMETER, "illegal", // OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + assertExitWithError(runnable, ExitStatus.CLI_ERROR, + "oft: export format 'illegal' is not supported.", err); } // [itest->dsn~cli.conversion.output-format~1] @Test - public void testConvertToSpecobjectFile() throws IOException + void testConvertToSpecobjectFile() throws IOException { - expectStandardFileExportResult(); - runCliStarter(CONVERT_COMMAND, this.docDir.toString(), // + final Runnable runnable = () -> runCliStarter( // + CONVERT_COMMAND, this.docDir.toString(), // OUTPUT_FORMAT_PARAMETER, "specobject", // OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + assertExitOkWithOutputFileStart(runnable, REQM2_PREAMBLE + " assertExitWithStatus(ExitStatus.OK.getCode(), runnable), // + () -> assertOutputFileExists(true), // + () -> assertOutputFileContentStartsWith(fileStart) // + ); } // [itest->dsn~cli.conversion.default-output-format~1] @Test - public void testConvertDefaultOutputFormat() throws IOException + void testConvertDefaultOutputFormat(@SysOut final Capturable out) throws IOException { - expectCliExitStatusWithAssertions(ExitStatus.OK, () -> { - assertOutputFileExists(false); - assertStdOutStartsWith(REQM2_PREAMBLE); - }); - runCliStarter(CONVERT_COMMAND, this.docDir.toString()); + final Runnable runnable = () -> runCliStarter(CONVERT_COMMAND, this.docDir.toString()); + assertExitOkWithStdOutStart(runnable, REQM2_PREAMBLE, out); } // [itest->dsn~cli.input-file-selection~1] @Test - public void testConvertDefaultOutputFormatIntoFile() throws IOException + void testConvertDefaultOutputFormatIntoFile() throws IOException { - expectStandardFileExportResult(); - runCliStarter(CONVERT_COMMAND, this.docDir.toString(), OUTPUT_FILE_PARAMETER, - this.outputFile.toString()); + final Runnable runnable = () -> runCliStarter(CONVERT_COMMAND, this.docDir.toString(), + OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + assertExitOkWithOutputFileStart(runnable, REQM2_PREAMBLE); } // [itest->dsn~cli.default-input~1] @Test - public void testConvertDefaultInputDir() throws IOException + void testConvertDefaultInputDir() throws IOException { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(true); - assertThat(getOutputFileContent().length(), greaterThan(10000)); - }); - runCliStarter(CONVERT_COMMAND, OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + final Runnable runnable = () -> runCliStarter( // + CONVERT_COMMAND, // + OUTPUT_FILE_PARAMETER, this.outputFile.toString() // + ); + assertExitOkWithOutputFileOfLength(runnable, 10000); } @Test - public void testTraceNoArguments() + void testTraceNoArguments() { - expectCliExitWithAssertions(() -> { - assertOutputFileExists(false); - }); - runCliStarter(TRACE_COMMAND); + assertAll( // + () -> assertExitWithStatus(ExitStatus.OK.getCode(), + () -> runCliStarter(TRACE_COMMAND)), + () -> assertOutputFileExists(false) // + ); } // [itest->dsn~cli.command-selection~1] @Test - public void testTrace() throws IOException + void testTrace() throws IOException { - expectStandardReportFileResult(); - runCliStarter(TRACE_COMMAND, this.docDir.toString(), // - OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, // + OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // + this.docDir.toString() // + ); + assertExitOkWithOutputFileStart(runnable, "ok - 5 total"); } @Test - public void testTraceWithReportVerbosityMinimal() throws IOException + void testTraceWithReportVerbosityMinimal() throws IOException { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(true); - assertOutputFileContentStartsWith("ok"); - }); - runCliStarter(TRACE_COMMAND, this.docDir.toString(), // + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, this.docDir.toString(), // OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // - REPORT_VERBOSITY_PARAMETER, "MINIMAL"); + REPORT_VERBOSITY_PARAMETER, "MINIMAL" // + ); + assertExitOkWithOutputFileStart(runnable, "ok"); } @Test - public void testTraceWithReportVerbosityQuietToStdOut() throws IOException + void testTraceWithReportVerbosityQuietToStdOut(@SysOut final Capturable out) throws IOException { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(false); - assertStdOutEmpty(); - }); - runCliStarter(TRACE_COMMAND, this.docDir.toString(), // - REPORT_VERBOSITY_PARAMETER, "QUIET"); + final Runnable runnable = () -> runCliStarter(// + TRACE_COMMAND, this.docDir.toString(), // + REPORT_VERBOSITY_PARAMETER, "QUIET" // + ); + out.capture(); + assertAll( // + () -> assertExitWithStatus(ExitStatus.OK.getCode(), runnable), // + () -> assertOutputFileExists(false), + () -> assertThat(out.getCapturedData(), isEmptyOrNullString()) // + ); } @Test - public void testTraceWithReportVerbosityQuietToFileMustBeRejected() throws IOException + void testTraceWithReportVerbosityQuietToFileMustBeRejected(@SysErr final Capturable err) + throws IOException { - expectCliExitOnErrorThatStartsWith(ExitStatus.CLI_ERROR, "oft: combining stream"); - runCliStarter(TRACE_COMMAND, this.docDir.toString(), // + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, this.docDir.toString(), // OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // - REPORT_VERBOSITY_PARAMETER, "QUIET"); + REPORT_VERBOSITY_PARAMETER, "QUIET" // + ); + assertExitWithError(runnable, ExitStatus.CLI_ERROR, "oft: combining stream", err); } @Test // [itest->dsn~cli.default-input~1] - public void testTraceDefaultInputDir() throws IOException + void testTraceDefaultInputDir() throws IOException { - expectCliExitWithAssertions(() -> { - assertOutputFileExists(true); - assertThat(getOutputFileContent().length(), greaterThan(400)); - }); - runCliStarter(TRACE_COMMAND, OUTPUT_FILE_PARAMETER, this.outputFile.toString()); + final Runnable runnable = () -> runCliStarter(// + TRACE_COMMAND, // + OUTPUT_FILE_PARAMETER, this.outputFile.toString() // + ); + assertExitOkWithOutputFileOfLength(runnable, 400); } - private void expectStandardFileExportResult() + private void assertExitOkWithOutputFileOfLength(final Runnable runnable, final int length) + throws MultipleFailuresError { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(true); - assertOutputFileContentStartsWith(REQM2_PREAMBLE + " assertExitOkWithOutputFileStart(runnable, REQM2_PREAMBLE), // + () -> assertOutputFileLength(length) // + ); } - // [itest->dsn~cli.tracing.output-format~1]] - public void testTraceOutputFormatPlain() throws IOException + private void assertOutputFileLength(final int length) { - expectCliExitWithAssertions(() -> { - assertOutputFileExists(true); - assertThat(getOutputFileContent().length(), greaterThan(1000)); - }); - runCliStarter(TRACE_COMMAND, OUTPUT_FILE_PARAMETER, this.outputFile.toString(), - OUTPUT_FORMAT_PARAMETER, "plain"); + assertThat(getOutputFileContent().length(), greaterThan(length)); } - @Test - public void testTraceMacNewlines() throws IOException + // [itest->dsn~cli.tracing.output-format~1]] + void testTraceOutputFormatPlain() throws IOException { - expectCliExitOkWithAssertions(() -> { - assertThat(Files.exists(this.outputFile), equalTo(true)); - assertThat("Has old Mac newlines", getOutputFileContent().contains(CARRIAGE_RETURN), - equalTo(true)); - assertThat("Has no Unix newlines", getOutputFileContent().contains(NEWLINE), - equalTo(false)); - }); - runCliStarter(TRACE_COMMAND, OUTPUT_FILE_PARAMETER, this.outputFile.toString(), - this.docDir.toString(), NEWLINE_PARAMETER, "OLDMAC"); - } - - @Test - // [itest->dsn~cli.default-newline-format~1] - public void testTraceDefaultNewlines() throws IOException - { - expectCliExitOkWithAssertions(() -> { - assertThat(Files.exists(this.outputFile), equalTo(true)); - assertThat("Has native platform line separator", - getOutputFileContent().contains(System.lineSeparator()), equalTo(true)); - switch (System.lineSeparator()) - { - case NEWLINE: - assertThat("Has no carriage returns", - getOutputFileContent().contains(CARRIAGE_RETURN), equalTo(false)); - break; - - case CARRIAGE_RETURN: - assertThat("Has no newlines", getOutputFileContent().contains(NEWLINE), - equalTo(false)); - break; - - case NEWLINE + CARRIAGE_RETURN: - assertThat("Has no newline without carriage return and vice-versa", - getOutputFileContent().matches("\n[^\r]|[^\n]\r"), equalTo(false)); - break; - } - }); - runCliStarter(TRACE_COMMAND, OUTPUT_FILE_PARAMETER, this.outputFile.toString(), - this.docDir.toString()); + final Runnable runnable = () -> runCliStarter(TRACE_COMMAND, OUTPUT_FILE_PARAMETER, + this.outputFile.toString(), OUTPUT_FORMAT_PARAMETER, "plain"); + assertExitOkWithOutputFileOfLength(runnable, 1000); } @Test - public void testTraceWithFilteredArtifactType() throws IOException - { - expectReducedReportFileResult(); - runCliStarter(TRACE_COMMAND, this.docDir.toString(), // - OUTPUT_FILE_PARAMETER, this.outputFile.toString(), WANTED_ARTIFACT_TYPES_PARAMETER, - "feat,req"); - } - - private void expectReducedReportFileResult() + void testTraceMacNewlines() throws IOException { - final int expectedNumber = 3; - expectCliExitOkWithNumberOfItems(expectedNumber); + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, // + OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // + NEWLINE_PARAMETER, "OLDMAC", // + this.docDir.toString() // + ); + assertAll( // + () -> assertExitWithStatus(ExitStatus.OK.getCode(), runnable), // + () -> assertOutputFileExists(true), // + () -> assertOutputFileContainsOldMacNewlines(), // + () -> assertOutputFileContainsNoUnixNewlines() // + ); } - private void expectStandardReportFileResult() + private void assertOutputFileContainsOldMacNewlines() { - final int expectedNumber = 5; - expectCliExitOkWithNumberOfItems(expectedNumber); + assertThat("Has old Mac newlines", getOutputFileContent().contains(CARRIAGE_RETURN), + equalTo(true)); } - private void expectCliExitOkWithNumberOfItems(final int expectedNumber) + private void assertOutputFileContainsNoUnixNewlines() { - expectCliExitOkWithAssertions(() -> { - assertOutputFileExists(true); - assertOutputFileContentStartsWith("ok - " + expectedNumber + " total"); - }); + assertThat("Has no Unix newlines", getOutputFileContent().contains(NEWLINE), + equalTo(false)); } - private void expectCliExitOkWithAssertions(final ExitAssertable assertions) + @Test + // [itest->dsn~cli.default-newline-format~1] + void testTraceDefaultNewlines() throws IOException { - expectCliExitStatusWithAssertions(ExitStatus.OK, assertions); - } + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, // + OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // + this.docDir.toString() // + ); + assertAll( // + () -> assertExitWithStatus(ExitStatus.OK.getCode(), runnable), // + () -> assertOutputFileExists(true), // + () -> assertPlatformNewlines(), // + () -> assertNoOffendingNewlines() // + ); - // [itest->dsn~cli.tracing.exit-status~1] - private void expectCliExitStatusWithAssertions(final ExitStatus status, - final ExitAssertable assertions) - { - this.exit.expectSystemExitWithStatus(status.getCode()); - this.exit.checkAssertionAfterwards(new Assertion() - { - @Override - public void checkAssertion() throws Exception - { - assertions.doAsserts(); - } - }); } - private void expectCliExitWithAssertions(final ExitAssertable assertions) + private void assertPlatformNewlines() { - this.exit.expectSystemExit(); - this.exit.checkAssertionAfterwards(new Assertion() - { - @Override - public void checkAssertion() throws Exception - { - assertions.doAsserts(); - } - }); + assertThat("Has native platform line separator", + getOutputFileContent().contains(System.lineSeparator()), equalTo(true)); } - private void expectCliExitOnErrorThatStartsWith(final ExitStatus status, - final String expectedError) + private void assertNoOffendingNewlines() { - this.exit.expectSystemExitWithStatus(status.getCode()); - this.exit.checkAssertionAfterwards(new Assertion() + switch (System.lineSeparator()) { - @Override - public void checkAssertion() throws Exception - { - assertThat(TestCliStarter.this.error.toString(), startsWith(expectedError)); - } - }); - } - - private void assertStdOutStartsWith(final String content) - { - assertThat(TestCliStarter.this.outputStream.toString(), startsWith(content)); + case NEWLINE: + assertThat("Has no carriage returns", getOutputFileContent().contains(CARRIAGE_RETURN), + equalTo(false)); + break; + case CARRIAGE_RETURN: + assertThat("Has no newlines", getOutputFileContent().contains(NEWLINE), equalTo(false)); + break; + case NEWLINE + CARRIAGE_RETURN: + assertThat("Has no newline without carriage return and vice-versa", + getOutputFileContent().matches("\n[^\r]|[^\n]\r"), equalTo(false)); + break; + } } - private void assertStdOutEmpty() + @Test + void testTraceWithFilteredArtifactType() throws IOException { - assertThat("STDOUT stream is empty", TestCliStarter.this.outputStream.toString(), - equalTo("")); + final Runnable runnable = () -> runCliStarter( // + TRACE_COMMAND, this.docDir.toString(), // + OUTPUT_FILE_PARAMETER, this.outputFile.toString(), // + WANTED_ARTIFACT_TYPES_PARAMETER, "feat,req" + // + ); + assertExitOkWithOutputFileStart(runnable, "ok - 3 total"); } private void assertOutputFileContentStartsWith(final String content) diff --git a/src/test/java/org/itsallcode/openfasttrace/cli/TestCommandLineInterpreter.java b/src/test/java/org/itsallcode/openfasttrace/cli/TestCommandLineInterpreter.java index c0b36c155..39bf8722b 100644 --- a/src/test/java/org/itsallcode/openfasttrace/cli/TestCommandLineInterpreter.java +++ b/src/test/java/org/itsallcode/openfasttrace/cli/TestCommandLineInterpreter.java @@ -23,104 +23,100 @@ */ import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.List; import org.itsallcode.openfasttrace.cli.CommandLineArgumentsStub.StubEnum; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; /** * Tests for {@link CommandLineInterpreter} */ -public class TestCommandLineInterpreter +class TestCommandLineInterpreter { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Test - public void testGetNamedStringParamter() + void testGetNamedStringParamter() { final CommandLineArgumentsStub stub = parseArguments("-a", "value_a"); assertThat(stub.getA(), equalTo("value_a")); } @Test - public void testGetLongNamedStringParamter() + void testGetLongNamedStringParamter() { final CommandLineArgumentsStub stub = parseArguments("--the-long-parameter", "value_a"); assertThat(stub.getTheLongParameter(), equalTo("value_a")); } @Test - public void testGetNamedStringParamterCaseIndependent() + void testGetNamedStringParamterCaseIndependent() { final CommandLineArgumentsStub stub = parseArguments("-A", "value_a"); assertThat(stub.getA(), equalTo("value_a")); } @Test - public void testMissingValueForStringParameter() + void testMissingValueForStringParameter() { expectParseException(new CommandLineArgumentsStub(), asList("-a"), "No value for argument 'a'"); } @Test - public void testUnexpectedArgumentName() + void testUnexpectedArgumentName() { expectParseException(new CommandLineArgumentsStub(), asList("--unexpected"), "Unexpected parameter 'unexpected' is not allowed"); } @Test - public void testUnexpectedSingleCharacterArgumentName() + void testUnexpectedSingleCharacterArgumentName() { expectParseException(new CommandLineArgumentsStub(), asList("-u"), "Unexpected parameter 'u' is not allowed"); } @Test - public void testGetNamedBooleanParamter() + void testGetNamedBooleanParamter() { final CommandLineArgumentsStub stub = parseArguments("-b"); assertThat(stub.isB(), equalTo(true)); } @Test - public void testGetNamedBooleanBoxedParamter() + void testGetNamedBooleanBoxedParamter() { final CommandLineArgumentsStub stub = parseArguments("-d"); assertThat(stub.isD(), equalTo(true)); } @Test - public void testGetNamedEnumParamter() + void testGetNamedEnumParamter() { final CommandLineArgumentsStub stub = parseArguments("-c", "VALUE1"); assertThat(stub.getC(), equalTo(StubEnum.VALUE1)); } @Test - public void testGetNamedEnumParamterLowercase() + void testGetNamedEnumParamterLowercase() { final CommandLineArgumentsStub stub = parseArguments("-c", "value1"); assertThat(stub.getC(), equalTo(StubEnum.VALUE1)); } @Test - public void testInvalidEnumParamter() + void testInvalidEnumParamter() { expectParseException(new CommandLineArgumentsStub(), asList("-c", "INVALID_VALUE"), "Cannot convert value 'INVALID_VALUE' to enum org.itsallcode.openfasttrace.cli.CommandLineArgumentsStub$StubEnum"); } @Test - public void testGetUnnamedParamters() + void testGetUnnamedParamters() { final String[] args = { "value_1", "value_2" }; final CommandLineArgumentsStub stub = parseArguments(args); @@ -128,14 +124,14 @@ public void testGetUnnamedParamters() } @Test - public void testNoSetterForUnnamedParameters() + void testNoSetterForUnnamedParameters() { expectParseException(new CliArgsWithoutUnnamedParameters(), asList("value_1", "value_2"), "Unnamed arguments '[value_1, value_2]' are not allowed"); } @Test - public void testSetterWithoutArgument() + void testSetterWithoutArgument() { expectParseException(new CliArgsWithNoArgSetter(), asList("--invalid"), "Unsupported argument count for setter 'public void org.itsallcode.openfasttrace.cli.TestCommandLineInterpreter$CliArgsWithNoArgSetter.setInvalid()'." @@ -143,7 +139,7 @@ public void testSetterWithoutArgument() } @Test - public void testSetterWithTooManyArguments() + void testSetterWithTooManyArguments() { expectParseException(new CliArgsMultiArgSetter(), asList("--invalid"), "Unsupported argument count for setter 'public void org.itsallcode.openfasttrace.cli.TestCommandLineInterpreter$CliArgsMultiArgSetter.setInvalid(java.lang.String,int)'." @@ -151,21 +147,21 @@ public void testSetterWithTooManyArguments() } @Test - public void testSetterWithUnsupportedArgumentType() + void testSetterWithUnsupportedArgumentType() { expectParseException(new CliArgsUnsupportedSetterArg(), asList("--invalid", "3.14"), "Type 'float' not supported for converting argument '3.14'"); } @Test - public void testArgumentFollowedByArgument() + void testArgumentFollowedByArgument() { expectParseException(new CommandLineArgumentsStub(), asList("-a", "--unexpected"), "No value for argument 'a'"); } @Test - public void testCombinedParameters() + void testCombinedParameters() { final CommandLineArgumentsStub stub = parseArguments("-a", "value_a", "value_1", "-b", "value_2", "-c", "VALUE2"); @@ -176,7 +172,7 @@ public void testCombinedParameters() } @Test - public void testCombinedParametersWithDifferentOrder() + void testCombinedParametersWithDifferentOrder() { final CommandLineArgumentsStub stub = parseArguments("-a", "value_a", "value_1", "-b", "value_2", "value_3", "-c", "VALUE2"); @@ -187,7 +183,7 @@ public void testCombinedParametersWithDifferentOrder() } @Test - public void testChainedSingleCharacterParameters() + void testChainedSingleCharacterParameters() { final CommandLineArgumentsStub stub = parseArguments("-bda", "value_a", "value_1", "value_2"); @@ -198,7 +194,7 @@ public void testChainedSingleCharacterParameters() } @Test - public void testChainedSingleCharacterParametersMustFailIfNonBooleanMisplaced() + void testChainedSingleCharacterParametersMustFailIfNonBooleanMisplaced() { final CommandLineArgumentsStub stub = new CommandLineArgumentsStub(); expectParseException(stub, asList("-bad", "value_a"), "No value for argument 'a'"); @@ -217,9 +213,11 @@ private CommandLineArgumentsStub parseArguments(final String... args) private void expectParseException(final Object argumentsReceiver, final List arguments, final String expectedExceptionMessage) { - this.thrown.expect(CliException.class); - this.thrown.expectMessage(expectedExceptionMessage); - new CommandLineInterpreter(arguments.toArray(new String[0]), argumentsReceiver).parse(); + assertThrows(CliException.class, + () -> new CommandLineInterpreter(arguments.toArray(new String[0]), + argumentsReceiver).parse(), + expectedExceptionMessage); + } private static class CliArgsWithoutUnnamedParameters diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestChecksumCalculator.java b/src/test/java/org/itsallcode/openfasttrace/core/TestChecksumCalculator.java index 33bbeaefe..b4c2b98dd 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestChecksumCalculator.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestChecksumCalculator.java @@ -23,27 +23,27 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.itsallcode.openfasttrace.importer.ChecksumCalculator; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestChecksumCalculator +class TestChecksumCalculator { @Test - public void testCalculateCrc32OfEmptyString() + void testCalculateCrc32OfEmptyString() { assertThat(ChecksumCalculator.calculateCrc32(""), equalTo(0L)); } @Test - public void testCalculateCrc32OfSimpleString() + void testCalculateCrc32OfSimpleString() { assertThat(ChecksumCalculator.calculateCrc32("abcd"), equalTo(3984772369L)); } @Test - public void testCalculateCrc32OfUtf8String() + void testCalculateCrc32OfUtf8String() { assertThat(ChecksumCalculator.calculateCrc32("äöüÖÄÜß"), equalTo(2866547662L)); } diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestItemStatus.java b/src/test/java/org/itsallcode/openfasttrace/core/TestItemStatus.java index 85abc0989..d549bee93 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestItemStatus.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestItemStatus.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L * OpenFastTrace @@ -23,15 +25,15 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestItemStatus +class TestItemStatus { @Test - public void testParseString() + void testParseString() { assertThat(ItemStatus.parseString("approved"), equalTo(ItemStatus.APPROVED)); assertThat(ItemStatus.parseString("Approved"), equalTo(ItemStatus.APPROVED)); @@ -40,9 +42,9 @@ public void testParseString() assertThat(ItemStatus.parseString("ReJeCtEd"), equalTo(ItemStatus.REJECTED)); } - @Test(expected = IllegalArgumentException.class) - public void testParseUnknownStringThrowsException() + @Test + void testParseUnknownStringThrowsException() { - ItemStatus.parseString("Unkown"); + assertThrows(IllegalArgumentException.class, () -> ItemStatus.parseString("Unkown")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestLegacySpecificationItemId.java b/src/test/java/org/itsallcode/openfasttrace/core/TestLegacySpecificationItemId.java index 513dc49d4..f6476330f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestLegacySpecificationItemId.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestLegacySpecificationItemId.java @@ -23,23 +23,23 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestLegacySpecificationItemId +class TestLegacySpecificationItemId { private SpecificationItemId.Builder builder; - @Before + @BeforeEach public void prepareEachTest() { this.builder = new SpecificationItemId.Builder(); } @Test - public void testBuildInferingArtifactTypeFromShortNamePrefix() + void testBuildInferingArtifactTypeFromShortNamePrefix() { final SpecificationItemId id = this.builder.name("foo:bar").revision(1).build(); assertIdParts(id, "foo", "bar", 1); @@ -54,21 +54,21 @@ private void assertIdParts(final SpecificationItemId id, final String expectedAr } @Test - public void testBuildInferingArtifactTypeFromLongNamePrefix() + void testBuildInferingArtifactTypeFromLongNamePrefix() { final SpecificationItemId id = this.builder.name("foo~foo:bar").revision(1).build(); assertIdParts(id, "foo", "bar", 1); } @Test - public void testBuildnferingArtifactTypeWithoutPrefixResultsInUnknown() + void testBuildnferingArtifactTypeWithoutPrefixResultsInUnknown() { final SpecificationItemId id = this.builder.name("bar").revision(1).build(); assertIdParts(id, SpecificationItemId.UNKONWN_ARTIFACT_TYPE, "bar", 1); } @Test - public void testBuildCleaningUpNameWherePrefixEqualsArtifactType() + void testBuildCleaningUpNameWherePrefixEqualsArtifactType() { final SpecificationItemId id = this.builder.artifactType("foo").name("foo:bar").revision(1) .build(); @@ -76,7 +76,7 @@ public void testBuildCleaningUpNameWherePrefixEqualsArtifactType() } @Test - public void testBuildCleaningUpNameWhereLongPrefixEqualsArtifactType() + void testBuildCleaningUpNameWhereLongPrefixEqualsArtifactType() { final SpecificationItemId id = this.builder.artifactType("foo").name("foo~foo:bar") .revision(1).build(); @@ -84,7 +84,7 @@ public void testBuildCleaningUpNameWhereLongPrefixEqualsArtifactType() } @Test - public void testBuildCleaningUpNameWherePrefixNotEqualArtifactType() + void testBuildCleaningUpNameWherePrefixNotEqualArtifactType() { final SpecificationItemId id = this.builder.artifactType("baz").name("foo~foo:bar") .revision(1).build(); @@ -92,14 +92,14 @@ public void testBuildCleaningUpNameWherePrefixNotEqualArtifactType() } @Test - public void testBuildInferingArtifactTypeAndCleaningUpNameWherePrefixPartsDontMatch() + void testBuildInferingArtifactTypeAndCleaningUpNameWherePrefixPartsDontMatch() { final SpecificationItemId id = this.builder.name("baz~foo:bar").revision(1).build(); assertIdParts(id, "baz", "bar", 1); } @Test - public void testParsingLegacyId() + void testParsingLegacyId() { final SpecificationItemId id = SpecificationItemId.parseId("req:dep-a, v1"); assertIdParts(id, "req", "dep-a", 1); diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java b/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java index de6f51b6d..33e2e948c 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java @@ -25,18 +25,18 @@ import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import org.itsallcode.openfasttrace.core.LinkedItemIndex.SpecificationItemIdWithoutVersion; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import nl.jqno.equalsverifier.EqualsVerifier; -public class TestLinkedItemIndex +class TestLinkedItemIndex { private final static SpecificationItemId DUPLICATE_ID_1 = SpecificationItemId.createId("type", "name", 42); @@ -51,7 +51,7 @@ public class TestLinkedItemIndex private SpecificationItem duplicateIdItem1Mock, duplicateIdItem2Mock, uniqueIdItemMock, duplicateIdIgnoringVersionItemMock; - @Before + @BeforeEach public void prepareTest() { MockitoAnnotations.initMocks(this); @@ -69,7 +69,7 @@ public void equalsSpecificationItemIdWithoutVersionContract() } @Test - public void testEmptyIndex() + void testEmptyIndex() { final LinkedItemIndex index = createIndex(); assertThat(index.size(), equalTo(0)); @@ -82,7 +82,7 @@ private LinkedItemIndex createIndex(final SpecificationItem... items) } @Test - public void testNonEmptyIndex() + void testNonEmptyIndex() { final LinkedItemIndex index = createIndex(this.duplicateIdItem1Mock, this.uniqueIdItemMock); assertThat(index.size(), equalTo(2)); @@ -92,7 +92,7 @@ public void testNonEmptyIndex() // [utest->dsn~tracing.tracing.duplicate-items~1] @Test - public void testDuplicateId() + void testDuplicateId() { final LinkedItemIndex index = createIndex(this.duplicateIdItem1Mock, this.duplicateIdItem2Mock); @@ -109,7 +109,7 @@ public void testDuplicateId() } @Test - public void testDuplicateVersionId() + void testDuplicateVersionId() { final LinkedItemIndex index = createIndex(this.duplicateIdItem1Mock, this.duplicateIdIgnoringVersionItemMock, this.uniqueIdItemMock); diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java b/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java index c1b5c5767..6a884f98b 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java @@ -25,20 +25,20 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.itsallcode.openfasttrace.core.SampleArtifactTypes.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; // [utest->dsn~linked-specification-item~1] -public class TestLinkedSpecificationItem +class TestLinkedSpecificationItem { private LinkedSpecificationItem linkedItem; private LinkedSpecificationItem coveredLinkedItem; @@ -47,7 +47,7 @@ public class TestLinkedSpecificationItem @Mock private SpecificationItem itemMock, coveredItemMock, otherItemMock; - @Before + @BeforeEach public void prepareAllTests() { MockitoAnnotations.initMocks(this); @@ -61,13 +61,13 @@ public void prepareAllTests() } @Test - public void testCreateLinkedSpecificationItem() + void testCreateLinkedSpecificationItem() { assertThat(this.linkedItem.getItem(), equalTo(this.itemMock)); } @Test - public void testLinkWithStatus() + void testLinkWithStatus() { this.linkedItem.addLinkToItemWithStatus(this.linkedItem, LinkStatus.COVERS); assertThat(this.linkedItem.getLinksByStatus(LinkStatus.COVERS), @@ -75,7 +75,7 @@ public void testLinkWithStatus() } @Test - public void testGetCoveredArtifactTypes() + void testGetCoveredArtifactTypes() { this.linkedItem.addCoveredArtifactType(UMAN); this.linkedItem.addCoveredArtifactType(REQ); @@ -83,7 +83,7 @@ public void testGetCoveredArtifactTypes() } @Test - public void testGetUncoveredArtifactTypes() + void testGetUncoveredArtifactTypes() { when(this.itemMock.getNeedsArtifactTypes()).thenReturn(Arrays.asList(UMAN, REQ)); this.linkedItem.addCoveredArtifactType(UMAN); @@ -91,14 +91,14 @@ public void testGetUncoveredArtifactTypes() } @Test - public void testGetOverCoveredArtifactTypes() + void testGetOverCoveredArtifactTypes() { this.linkedItem.addOverCoveredArtifactType(REQ); assertThat(this.linkedItem.getOverCoveredArtifactTypes(), containsInAnyOrder(REQ)); } @Test - public void testIsCoveredShallow_Ok() + void testIsCoveredShallow_Ok() { when(this.itemMock.getNeedsArtifactTypes()).thenReturn(Arrays.asList(UMAN, IMPL)); this.linkedItem.addCoveredArtifactType(UMAN); @@ -107,7 +107,7 @@ public void testIsCoveredShallow_Ok() } @Test - public void testIsCoveredShallow_NotOk_WrongCoverage() + void testIsCoveredShallow_NotOk_WrongCoverage() { when(this.itemMock.getNeedsArtifactTypes()).thenReturn(Arrays.asList(UMAN, IMPL)); this.linkedItem.addCoveredArtifactType(UMAN); @@ -116,7 +116,7 @@ public void testIsCoveredShallow_NotOk_WrongCoverage() } @Test - public void testIsCoveredShallow_NotOk_MissingCoverage() + void testIsCoveredShallow_NotOk_MissingCoverage() { when(this.itemMock.getNeedsArtifactTypes()).thenReturn(Arrays.asList(UMAN, IMPL)); this.linkedItem.addCoveredArtifactType(UMAN); @@ -125,7 +125,7 @@ public void testIsCoveredShallow_NotOk_MissingCoverage() // [utest->dsn~tracing.deep-coverage~1] @Test - public void testGetDeepCoverageStatus_Covered() + void testGetDeepCoverageStatus_Covered() { prepareCoverThis(); assertThat(this.linkedItem.getDeepCoverageStatus(), equalTo(DeepCoverageStatus.COVERED)); @@ -143,7 +143,7 @@ private void prepareCoverThis() // [utest->dsn~tracing.deep-coverage~1] @Test - public void testGetDeepCoverageStatus_MissingCoverage() + void testGetDeepCoverageStatus_MissingCoverage() { when(this.itemMock.getNeedsArtifactTypes()).thenReturn(Arrays.asList(DSN)); this.linkedItem.addCoveredArtifactType(DSN); @@ -155,7 +155,7 @@ public void testGetDeepCoverageStatus_MissingCoverage() // [utest->dsn~tracing.defect-items~2] @Test - public void testIsDefect_False() + void testIsDefect_False() { prepareCoverThis(); prepareCoverOther(); @@ -170,7 +170,7 @@ private void prepareCoverOther() // [utest->dsn~tracing.defect-items~2] @Test - public void testIsDefect_TrueBecauseOfDuplicates() + void testIsDefect_TrueBecauseOfDuplicates() { this.linkedItem.addLinkToItemWithStatus(this.otherLinkedItem, LinkStatus.DUPLICATE); assertThat(this.linkedItem.isDefect(), equalTo(true)); @@ -178,7 +178,7 @@ public void testIsDefect_TrueBecauseOfDuplicates() // [utest->dsn~tracing.defect-items~2] @Test - public void testIsDefect_TrueBecauseOfBadLink() + void testIsDefect_TrueBecauseOfBadLink() { for (final LinkStatus status : LinkStatus.values()) { @@ -192,7 +192,7 @@ public void testIsDefect_TrueBecauseOfBadLink() @Test // [utest->dsn~tracing.defect-items~2] - public void testIsDefect_FalseBecauseRejected() + void testIsDefect_FalseBecauseRejected() { final LinkedSpecificationItem item = new LinkedSpecificationItem(this.itemMock); when(this.itemMock.getStatus()).thenReturn(ItemStatus.REJECTED); @@ -201,7 +201,7 @@ public void testIsDefect_FalseBecauseRejected() } @Test - public void testCountOutgoingLinks() + void testCountOutgoingLinks() { linkToNewItemsWithStatus(LinkStatus.COVERS, LinkStatus.PREDATED, LinkStatus.OUTDATED, LinkStatus.UNWANTED, LinkStatus.ORPHANED, LinkStatus.AMBIGUOUS); @@ -225,7 +225,7 @@ private void linkToNewItemWithStatus(final LinkStatus status) } @Test - public void testCountIncomingLinks() + void testCountIncomingLinks() { linkToNewItemsWithStatus(LinkStatus.COVERED_SHALLOW, LinkStatus.COVERED_PREDATED, LinkStatus.COVERED_OUTDATED, LinkStatus.COVERED_UNWANTED); @@ -235,7 +235,7 @@ public void testCountIncomingLinks() } @Test - public void testCountDuplicateLinks() + void testCountDuplicateLinks() { this.linkedItem.addLinkToItemWithStatus(this.coveredLinkedItem, LinkStatus.COVERS); this.linkedItem.addLinkToItemWithStatus(this.linkedItem, LinkStatus.DUPLICATE); @@ -245,7 +245,7 @@ public void testCountDuplicateLinks() // [utest->dsn~tracing.link-cycle~1] @Test - public void testGetDeepCoverageStatus_CylceIfSelfLink() + void testGetDeepCoverageStatus_CylceIfSelfLink() { this.linkedItem.addLinkToItemWithStatus(this.linkedItem, LinkStatus.COVERS); assertThat(this.linkedItem.getDeepCoverageStatus(), equalTo(DeepCoverageStatus.CYCLE)); @@ -253,7 +253,7 @@ public void testGetDeepCoverageStatus_CylceIfSelfLink() // [utest->dsn~tracing.link-cycle~1] @Test - public void testGetDeepCoverageStatus_DeepCylce() + void testGetDeepCoverageStatus_DeepCylce() { this.linkedItem.addLinkToItemWithStatus(this.otherLinkedItem, LinkStatus.COVERS); this.otherLinkedItem.addLinkToItemWithStatus(this.linkedItem, LinkStatus.COVERS); @@ -261,7 +261,7 @@ public void testGetDeepCoverageStatus_DeepCylce() } @Test - public void testGetTitleWithFallback_HasTitle() + void testGetTitleWithFallback_HasTitle() { final String expectedReturn = "title"; when(this.itemMock.getTitle()).thenReturn(expectedReturn); @@ -270,14 +270,14 @@ public void testGetTitleWithFallback_HasTitle() } @Test - public void testGetTitle() + void testGetTitle() { when(this.itemMock.getTitle()).thenReturn("title"); assertThat(this.linkedItem.getTitle(), equalTo("title")); } @Test - public void testGetTitleWithFallback_HasNoTitle() + void testGetTitleWithFallback_HasNoTitle() { when(this.itemMock.getTitle()).thenReturn(null); when(this.itemMock.getId()).thenReturn(SpecificationItemId.parseId("foo~id-name~1")); @@ -285,7 +285,7 @@ public void testGetTitleWithFallback_HasNoTitle() } @Test - public void testGetTitleWithFallback_HasEmptyTitle() + void testGetTitleWithFallback_HasEmptyTitle() { when(this.itemMock.getTitle()).thenReturn(""); when(this.itemMock.getId()).thenReturn(SpecificationItemId.parseId("foo~id-name~1")); @@ -293,7 +293,7 @@ public void testGetTitleWithFallback_HasEmptyTitle() } @Test - public void testGetTitleWithFallback_HasNothing() + void testGetTitleWithFallback_HasNothing() { when(this.itemMock.getTitle()).thenReturn(""); when(this.itemMock.getId()).thenReturn(null); @@ -301,7 +301,7 @@ public void testGetTitleWithFallback_HasNothing() } @Test - public void testGetTracedLinks() + void testGetTracedLinks() { this.linkedItem.addLinkToItemWithStatus(this.coveredLinkedItem, LinkStatus.COVERS); this.linkedItem.addLinkToItemWithStatus(this.linkedItem, LinkStatus.ORPHANED); @@ -312,13 +312,13 @@ public void testGetTracedLinks() } @Test - public void testHasLinks_InitiallyFalse() + void testHasLinks_InitiallyFalse() { assertThat(this.linkedItem.hasLinks(), equalTo(false)); } @Test - public void testHasLinks() + void testHasLinks() { this.linkedItem.addLinkToItemWithStatus(this.otherLinkedItem, LinkStatus.AMBIGUOUS); assertThat(this.linkedItem.hasLinks(), equalTo(true)); diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java b/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java index 416471d41..c46029a1f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java @@ -1,5 +1,6 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; @@ -30,19 +31,18 @@ import static org.itsallcode.openfasttrace.core.SampleArtifactTypes.REQ; import static org.itsallcode.openfasttrace.core.SampleArtifactTypes.UTEST; import static org.itsallcode.openfasttrace.core.SpecificationItemId.createId; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.util.*; import java.util.stream.Collectors; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestLinker +class TestLinker { // [utest->dsn~tracing.outgoing-coverage-link-status~3] @Test - public void testDetectOutgoingLinkStatusCovered() + void testDetectOutgoingLinkStatusCovered() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "covered", 1) // @@ -87,7 +87,7 @@ private Optional findLinkedItem(final SpecificationItem // [utest->dsn~tracing.outgoing-coverage-link-status~3] @Test - public void testDetectOutgoingLinkStatusOrphaned() + void testDetectOutgoingLinkStatusOrphaned() { final SpecificationItem orphan = new SpecificationItem.Builder() // .id(IMPL, "orphan", 1) // @@ -99,7 +99,7 @@ public void testDetectOutgoingLinkStatusOrphaned() // [utest->dsn~tracing.outgoing-coverage-link-status~3] @Test - public void testDetectOutgoingLinkStatusOutdated() + void testDetectOutgoingLinkStatusOutdated() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "this-is-newer-than-link", 2) // @@ -118,7 +118,7 @@ public void testDetectOutgoingLinkStatusOutdated() // [utest->dsn~tracing.outgoing-coverage-link-status~3] @Test - public void testDetectOutgoingLinkStatusPredated() + void testDetectOutgoingLinkStatusPredated() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "this-is-older-than-link", 1) // @@ -137,7 +137,7 @@ public void testDetectOutgoingLinkStatusPredated() // [utest->dsn~tracing.outgoing-coverage-link-status~3] @Test - public void testDetectOutgoingLinkStatusAmbiguous() + void testDetectOutgoingLinkStatusAmbiguous() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "covered", 1) // @@ -157,7 +157,7 @@ public void testDetectOutgoingLinkStatusAmbiguous() // [utest->dsn~tracing.tracing.duplicate-items~1] @Test - public void testDetectOutgoingLinkStatusDuplicate() + void testDetectOutgoingLinkStatusDuplicate() { final SpecificationItem original = new SpecificationItem.Builder() // .id(REQ, "covered", 1) // @@ -172,7 +172,7 @@ public void testDetectOutgoingLinkStatusDuplicate() // [utest->dsn~tracing.incoming-coverage-link-status~1] @Test - public void testDetectIncomingLinkStatusCoveredShallow() + void testDetectIncomingLinkStatusCoveredShallow() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "covered", 1) // @@ -250,7 +250,7 @@ private StringBuilder createDebugInfoFromLinksWithStatus( // [utest->dsn~tracing.incoming-coverage-link-status~1] @Test - public void testDetectIncomingLinkStatusUnwanted() + void testDetectIncomingLinkStatusUnwanted() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "covered", 1) // @@ -269,7 +269,7 @@ public void testDetectIncomingLinkStatusUnwanted() // [utest->dsn~tracing.incoming-coverage-link-status~1] @Test - public void testDetectIncomingLinkStatusCoveredOutdated() + void testDetectIncomingLinkStatusCoveredOutdated() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "newer", 2) // @@ -285,7 +285,7 @@ public void testDetectIncomingLinkStatusCoveredOutdated() // [utest->dsn~tracing.incoming-coverage-link-status~1] @Test - public void testDetectIncomingLinkStatusCoveredPredated() + void testDetectIncomingLinkStatusCoveredPredated() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "older", 1) // @@ -301,7 +301,7 @@ public void testDetectIncomingLinkStatusCoveredPredated() // [utest->dsn~tracing.needed-coverage-status~1] @Test - public void testCoverageForDifferentArtifactTypes() + void testCoverageForDifferentArtifactTypes() { final SpecificationItem covered = new SpecificationItem.Builder() // .id(REQ, "to-be-covered", 42) // diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestLocation.java b/src/test/java/org/itsallcode/openfasttrace/core/TestLocation.java index ede74e833..0d45b561e 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestLocation.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestLocation.java @@ -1,7 +1,8 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; /*- * #%L @@ -25,40 +26,40 @@ * #L% */ -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class TestLocation +class TestLocation { private static final String PATH = "path"; @Test - public void testEqualsAndHashContract() + void testEqualsAndHashContract() { EqualsVerifier.forClass(Location.class).verify(); } - @Test(expected = IllegalArgumentException.class) - public void testCreateLocationWithNegativeLineFails() + @Test + void testCreateLocationWithNegativeLineFails() { - Location.create(PATH, -1); + assertThrows(IllegalArgumentException.class, () -> Location.create(PATH, -1)); } - @Test(expected = IllegalArgumentException.class) - public void testCreateLocationWithNegativeLineFails2() + @Test + void testCreateLocationWithNegativeLineFails2() { - Location.create(PATH, -1, 1); + assertThrows(IllegalArgumentException.class, () -> Location.create(PATH, -1, 1)); } - @Test(expected = IllegalArgumentException.class) - public void testCreateLocationWithNegativeColumnFails() + @Test + void testCreateLocationWithNegativeColumnFails() { - Location.create(PATH, 1, -1); + assertThrows(IllegalArgumentException.class, () -> Location.create(PATH, 1, -1)); } @Test - public void testBuilder() + void testBuilder() { final String expectedPath = "expected"; final int expectedLine = 4007; @@ -71,7 +72,7 @@ public void testBuilder() } @Test - public void testIsComplete() + void testIsComplete() { final Location.Builder builder = new Location.Builder().path("a"); assertThat("builder with path set to null is complete", builder.isCompleteEnough(), @@ -79,7 +80,7 @@ public void testIsComplete() } @Test - public void testIsNotCompleteEnoughWithoutPath() + void testIsNotCompleteEnoughWithoutPath() { final Location.Builder builderA = new Location.Builder().path(""); final Location.Builder builderB = new Location.Builder(); diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestNewline.java b/src/test/java/org/itsallcode/openfasttrace/core/TestNewline.java index 9bd26bebf..1fb6a6daf 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestNewline.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestNewline.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L \* OpenFastTrace @@ -23,34 +25,33 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.itsallcode.openfasttrace.core.Newline; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestNewline +class TestNewline { @Test - public void testUnix() + void testUnix() { assertThat(Newline.fromRepresentation("\n"), equalTo(Newline.UNIX)); } @Test - public void testWindows() + void testWindows() { assertThat(Newline.fromRepresentation("\r\n"), equalTo(Newline.WINDOWS)); } @Test - public void testOldMac() + void testOldMac() { assertThat(Newline.fromRepresentation("\r"), equalTo(Newline.OLDMAC)); } - @Test(expected = IllegalArgumentException.class) - public void testUnknown() + @Test + void testUnknownThrowsException() { - Newline.fromRepresentation("unknown"); + assertThrows(IllegalArgumentException.class, () -> Newline.fromRepresentation("unknown")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java b/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java index 30ebf83d2..a8b931fb2 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java @@ -1,5 +1,6 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.emptyIterable; @@ -26,7 +27,7 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Arrays; import java.util.List; @@ -34,11 +35,11 @@ import org.itsallcode.openfasttrace.core.SpecificationItem.Builder; import org.itsallcode.openfasttrace.matcher.SpecificationItemIdMatcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class TestSpecificationItem +class TestSpecificationItem { private static final String NOT_NEEDED_ARTIFACT_TYPE = "not_needed"; private static final String NEEDED_ARTIFACT_TYPE = "needed"; @@ -65,7 +66,7 @@ private static List parseIds(final String... ids) // [utest.requirement_format~1] @Test - public void testBuildSimpleSpecificationItem() + void testBuildSimpleSpecificationItem() { final SpecificationItem.Builder builder = createSimpleItem(); final SpecificationItem item = builder.build(); @@ -90,7 +91,7 @@ private void assertSimpleItemComplete(final SpecificationItem item) // [utest->dsn~specification-item~3] @Test - public void testBuildComplexSpecificationItem() + void testBuildComplexSpecificationItem() { final SpecificationItem.Builder builder = createSimpleItem(); for (final SpecificationItemId coveredId : COVERED_IDS) @@ -118,7 +119,7 @@ private void assertRelationsComplete(final SpecificationItem item) } @Test - public void testBuildSpecificationItemFromSeparateIdParts() + void testBuildSpecificationItemFromSeparateIdParts() { final SpecificationItem.Builder builder = createTestItemBuilder(); final SpecificationItem item = builder.build(); @@ -126,7 +127,7 @@ public void testBuildSpecificationItemFromSeparateIdParts() } @Test - public void testNeedsCoverageByArtifactType() + void testNeedsCoverageByArtifactType() { final SpecificationItem.Builder builder = createTestItemBuilder(); builder.addNeedsArtifactType(NEEDED_ARTIFACT_TYPE); @@ -137,7 +138,7 @@ public void testNeedsCoverageByArtifactType() // [utest->dsn~specification-item~3] @Test - public void testNeedsCoverage() + void testNeedsCoverage() { final SpecificationItem.Builder builder = createTestItemBuilder(); assertThat(builder.build().needsCoverage(), equalTo(false)); @@ -147,33 +148,33 @@ public void testNeedsCoverage() // [utest->dsn~specification-item~3] @Test - public void testLocationIsNullByDefault() + void testLocationIsNullByDefault() { assertThat(createTestItemBuilder().build().getLocation(), equalTo(null)); } @Test - public void testLocationBuilder() + void testLocationBuilder() { final Location there = Location.create("there", 7); assertThat(createTestItemBuilder().location(there).build().getLocation(), equalTo(there)); } @Test - public void testLocationBuilderFromComponents() + void testLocationBuilderFromComponents() { assertThat(createTestItemBuilder().location("here", 42).build().getLocation(), equalTo(Location.create("here", 42))); } @Test - public void testEqualsAndHashContract() + void testEqualsAndHashContract() { EqualsVerifier.forClass(SpecificationItem.class).verify(); } @Test - public void testCoverageBuilderWithIdParts() + void testCoverageBuilderWithIdParts() { final SpecificationItem item = createTestItemBuilder() // .addCoveredId("foo", "bar", 3) // @@ -188,7 +189,7 @@ private Builder createTestItemBuilder() } @Test - public void testDependencyBuilderWithIdParts() + void testDependencyBuilderWithIdParts() { final SpecificationItem item = createTestItemBuilder().addDependOnId("foo", "bar", 3) // .build(); @@ -197,14 +198,14 @@ public void testDependencyBuilderWithIdParts() // [utest->dsn~specification-item~3] @Test - public void testDefaultStatusIsApproved() + void testDefaultStatusIsApproved() { assertThat(createTestItemBuilder().build().getStatus(), equalTo(ItemStatus.APPROVED)); } // [utest->dsn~specification-item~3] @Test - public void testBuildWithStatus() + void testBuildWithStatus() { assertThat(createTestItemBuilder().status(ItemStatus.REJECTED).build().getStatus(), equalTo(ItemStatus.REJECTED)); @@ -212,36 +213,36 @@ public void testBuildWithStatus() // [utest->dsn~specification-item~3] @Test - public void testByDefaultTagListIsEmpty() + void testByDefaultTagListIsEmpty() { assertThat(createTestItemBuilder().build().getTags(), emptyIterable()); } // [utest->dsn~specification-item~3] @Test - public void testTagBuilder() + void testTagBuilder() { assertThat(createTestItemBuilder().addTag("the_tag").build().getTags(), containsInAnyOrder("the_tag")); } // [utest->dsn~specification-item~3] - @Test(expected = IllegalStateException.class) - public void testBuildingWithOutIdThrowsExepction() + @Test + void testBuildingWithOutIdThrowsExepction() { - new SpecificationItem.Builder().build(); + assertThrows(IllegalStateException.class, () -> new SpecificationItem.Builder().build()); } // [utest->dsn~specification-item~3] @Test - public void testForwardsIsFalseByDefault() + void testForwardsIsFalseByDefault() { assertThat(createSimpleItem().build().isForwarding(), equalTo(false)); } // [utest->dsn~specification-item~3] @Test - public void testSetForwards() + void testSetForwards() { assertThat(createSimpleItem().forwards(true).build().isForwarding(), equalTo(true)); } diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItemId.java b/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItemId.java index f3746ed17..d75f6a4b5 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItemId.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItemId.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.core; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L * OpenFastTrace @@ -25,11 +27,11 @@ import static org.hamcrest.Matchers.equalTo; import static org.itsallcode.openfasttrace.core.SpecificationItemId.createId; import static org.itsallcode.openfasttrace.core.SpecificationItemId.parseId; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import org.itsallcode.openfasttrace.core.SpecificationItemId.Builder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; @@ -37,14 +39,14 @@ * [utest->dsn~md.specification-item-id-format~2] */ // [utest->dsn~specification-item-id~1] -public class TestSpecificationItemId +class TestSpecificationItemId { private static final int REVISION = 1; private static final String NAME = "foo"; private static final String ARTIFACT_TYPE_FEATURE = "feat"; @Test - public void testCreateId() + void testCreateId() { final SpecificationItemId id = createId(ARTIFACT_TYPE_FEATURE, NAME, REVISION); assertThat(id, equalTo(new Builder().artifactType(ARTIFACT_TYPE_FEATURE).name(NAME) @@ -52,7 +54,7 @@ public void testCreateId() } @Test - public void testCreateIdWithoutRevision() + void testCreateIdWithoutRevision() { final SpecificationItemId id = createId(ARTIFACT_TYPE_FEATURE, NAME); assertThat(id, equalTo(new Builder().artifactType(ARTIFACT_TYPE_FEATURE).name(NAME) @@ -60,7 +62,7 @@ public void testCreateIdWithoutRevision() } @Test - public void testParseId_singleDigitRevision() + void testParseId_singleDigitRevision() { final SpecificationItemId id = parseId("feat~foo~1"); assertThat(id.getArtifactType(), equalTo(ARTIFACT_TYPE_FEATURE)); @@ -69,7 +71,7 @@ public void testParseId_singleDigitRevision() } @Test - public void testParseId_multipleFragmentName() + void testParseId_multipleFragmentName() { final SpecificationItemId id = parseId("feat~foo.bar_zoo.baz-narf~1"); assertThat(id.getArtifactType(), equalTo(ARTIFACT_TYPE_FEATURE)); @@ -78,7 +80,7 @@ public void testParseId_multipleFragmentName() } @Test - public void testParseId_multipleDigitRevision() + void testParseId_multipleDigitRevision() { final SpecificationItemId id = parseId("feat~foo~999"); assertThat(id.getArtifactType(), equalTo(ARTIFACT_TYPE_FEATURE)); @@ -86,14 +88,15 @@ public void testParseId_multipleDigitRevision() assertThat(id.getRevision(), equalTo(999)); } - @Test(expected = IllegalStateException.class) - public void testParseIdFailsForWildcardRevision() + @Test + void testParseIdFailsForWildcardRevision() { - parseId("feat~foo~" + SpecificationItemId.REVISION_WILDCARD); + assertThrows(IllegalStateException.class, + () -> parseId("feat~foo~" + SpecificationItemId.REVISION_WILDCARD)); } @Test - public void testParseId_mustFailForIllegalIds() + void testParseId_mustFailForIllegalIds() { final String[] negatives = { "feat.foo~1", "foo~1", "req~foo", "req1~foo~1", "req.r~foo~1", "req~1foo~1", "req~.foo~1", "req~foo~-1" }; @@ -119,7 +122,7 @@ private void assertParsingExceptionOnIllegalSpecificationItemId(final String sam } @Test - public void testToRevisionWildcard() + void testToRevisionWildcard() { final SpecificationItemId id = parseId("feat~foo~999"); assertThat(id.toRevisionWildcard().getRevision(), @@ -127,7 +130,7 @@ public void testToRevisionWildcard() } @Test - public void testToString() + void testToString() { final Builder builder = new Builder(); builder.artifactType("dsn").name("dummy").revision(3); @@ -135,7 +138,7 @@ public void testToString() } @Test - public void testToStringRevisionWildcard() + void testToStringRevisionWildcard() { final Builder builder = new Builder(); builder.artifactType("dsn").name("dummy").revisionWildcard(); @@ -143,7 +146,7 @@ public void testToStringRevisionWildcard() equalTo("dsn~dummy~" + SpecificationItemId.REVISION_WILDCARD)); } - public void testCreate_WithRevisionWildcard() + void testCreate_WithRevisionWildcard() { final SpecificationItemId id = createId(ARTIFACT_TYPE_FEATURE, NAME); assertThat(id.getArtifactType(), equalTo(ARTIFACT_TYPE_FEATURE)); @@ -152,7 +155,7 @@ public void testCreate_WithRevisionWildcard() } @Test - public void testEqualsAndHashContract() + void testEqualsAndHashContract() { EqualsVerifier.forClass(SpecificationItemId.class).verify(); } diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestTracedLink.java b/src/test/java/org/itsallcode/openfasttrace/core/TestTracedLink.java index d0b63df26..0c5b0e658 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestTracedLink.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestTracedLink.java @@ -23,17 +23,17 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class TestTracedLink +class TestTracedLink { @Test - public void testEqualsAndHashContract() + void testEqualsAndHashContract() { EqualsVerifier.forClass(TracedLink.class) // .withPrefabValues(LinkedSpecificationItem.class, @@ -50,7 +50,7 @@ private LinkedSpecificationItem createPrefabricatedLinkedSpecificationItem( } @Test - public void testTracedLink() + void testTracedLink() { final LinkedSpecificationItem other = mock(LinkedSpecificationItem.class); final LinkStatus status = LinkStatus.AMBIGUOUS; diff --git a/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java b/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java index d45f61ff6..acc4e917c 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java @@ -25,17 +25,17 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestTracer +class TestTracer { private static final SpecificationItemId ID_A = SpecificationItemId.parseId("req~a~1"); private static final SpecificationItemId ID_B = SpecificationItemId.parseId("dsn~b~2"); @@ -43,7 +43,7 @@ public class TestTracer @Mock LinkedSpecificationItem aMock, bMock, cMock; - @Before + @BeforeEach public void prepareTest() { MockitoAnnotations.initMocks(this); @@ -53,7 +53,7 @@ public void prepareTest() } @Test - public void testNoneDefect_Ok() + void testNoneDefect_Ok() { when(this.aMock.isDefect()).thenReturn(false); when(this.bMock.isDefect()).thenReturn(false); @@ -73,7 +73,7 @@ private Trace traceItems(final LinkedSpecificationItem... items) } @Test - public void testNoneDefect_NotOk() + void testNoneDefect_NotOk() { when(this.aMock.isDefect()).thenReturn(false); when(this.bMock.isDefect()).thenReturn(true); diff --git a/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java b/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java index 6dc2e58fc..7a4fd4c65 100644 --- a/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java +++ b/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java @@ -24,7 +24,7 @@ import static java.util.stream.Collectors.toList; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import java.util.stream.StreamSupport; @@ -38,15 +38,15 @@ import org.itsallcode.openfasttrace.importer.specobject.SpecobjectImporterFactory; import org.itsallcode.openfasttrace.importer.tag.TagImporterFactory; import org.itsallcode.openfasttrace.importer.zip.ZipFileImporterFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for {@link InitializingServiceLoader} */ -public class TestInitializingServiceLoader +class TestInitializingServiceLoader { @Test - public void testNoServicesRegistered() + void testNoServicesRegistered() { final Object context = new Object(); final InitializingServiceLoader voidServiceLoader = InitializingServiceLoader @@ -59,7 +59,7 @@ public void testNoServicesRegistered() @SuppressWarnings("unchecked") @Test - public void testImporterFactoriesRegistered() + void testImporterFactoriesRegistered() { final ImporterContext context = new ImporterContext(null); final List services = getRegisteredServices(ImporterFactory.class, @@ -76,7 +76,7 @@ public void testImporterFactoriesRegistered() } @Test - public void testExporterFactoriesRegistered() + void testExporterFactoriesRegistered() { final ExporterContext context = new ExporterContext(); final List services = getRegisteredServices(ExporterFactory.class, diff --git a/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java b/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java index 2505fb692..11e2d4606 100644 --- a/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java @@ -24,7 +24,7 @@ import static java.util.Arrays.asList; import static org.itsallcode.openfasttrace.matcher.MultilineTextMatcher.matchesAllLines; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -34,16 +34,16 @@ import org.itsallcode.openfasttrace.core.*; import org.itsallcode.openfasttrace.testutil.xml.IndentingXMLStreamWriter; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link SpecobjectExporter} */ -public class TestSpecobjectExporter +class TestSpecobjectExporter { // [itest->dsn~conversion.reqm2-export~1] @Test - public void testExportSimpleSpecObjectWithMandatoryElements() + void testExportSimpleSpecObjectWithMandatoryElements() throws IOException, XMLStreamException { final SpecificationItem item = new SpecificationItem.Builder() // @@ -66,7 +66,7 @@ public void testExportSimpleSpecObjectWithMandatoryElements() } @Test - public void testExportSpecObjectWithOptionalElements() throws IOException, XMLStreamException + void testExportSpecObjectWithOptionalElements() throws IOException, XMLStreamException { final SpecificationItem item = new SpecificationItem.Builder() // .id(SpecificationItemId.createId("req", "me", 2)) // @@ -115,7 +115,7 @@ public void testExportSpecObjectWithOptionalElements() throws IOException, XMLSt } @Test - public void testExportTwoSpecObjects() throws IOException, XMLStreamException + void testExportTwoSpecObjects() throws IOException, XMLStreamException { final SpecificationItem itemA = new SpecificationItem.Builder() // .id(SpecificationItemId.createId("foo", "bar", 1)) // diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/ImporterFactoryTestBase.java b/src/test/java/org/itsallcode/openfasttrace/importer/ImporterFactoryTestBase.java index fcac4f280..9d76a87a1 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/ImporterFactoryTestBase.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/ImporterFactoryTestBase.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.importer; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L \* OpenFastTrace @@ -24,7 +26,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import java.nio.file.Path; @@ -33,10 +35,8 @@ import org.itsallcode.openfasttrace.ImportSettings; import org.itsallcode.openfasttrace.importer.input.InputFile; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -48,12 +48,10 @@ */ public abstract class ImporterFactoryTestBase { - @Rule - public ExpectedException thrown = ExpectedException.none(); @Mock protected ImporterContext contextMock; - @Before + @BeforeEach public void initMocks() { MockitoAnnotations.initMocks(this); @@ -61,24 +59,25 @@ public void initMocks() } @Test - public void testSupportedFileNames() + void testSupportedFileNames() { assertSupported(getSupportedFilenames(), true); } @Test - public void testUnsupportedFileNames() + void testUnsupportedFileNames() { assertSupported(getUnsupportedFilenames(), false); } @Test - public void testCreateImporterThrowsExceptionForMissingFile() + void testCreateImporterThrowsExceptionForMissingFile() { final Path supportedPath = Paths.get("dir", getSupportedFilenames().get(0)); - this.thrown.expect(ImporterException.class); - this.thrown.expectMessage("Error reading \"" + supportedPath + "\""); - createAndInitialize().createImporter(InputFile.forPath(supportedPath), null).runImport(); + assertThrows(ImporterException.class, // + () -> createAndInitialize().createImporter(InputFile.forPath(supportedPath), null) + .runImport(), // + "Error reading \"" + supportedPath + "\""); } private T createAndInitialize() @@ -89,7 +88,7 @@ private T createAndInitialize() } @Test - public void testInit() + void testInit() { final T factory = createFactory(); factory.init(this.contextMock); @@ -97,13 +96,12 @@ public void testInit() } @Test - public void testMissingContextThrowsException() + void testMissingContextThrowsException() { final T factory = createFactory(); factory.init(null); - this.thrown.expect(NullPointerException.class); - this.thrown.expectMessage(equalTo("Context was not initialized")); - factory.getContext(); + assertThrows(NullPointerException.class, () -> factory.getContext(), + "Context was not initialized"); } private void assertSupported(final List filenames, final boolean expectedResult) diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestImportFilterSettings.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestImportFilterSettings.java index b11c0146d..361770070 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestImportFilterSettings.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestImportFilterSettings.java @@ -24,26 +24,26 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Arrays; import java.util.HashSet; import org.itsallcode.openfasttrace.FilterSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; import nl.jqno.equalsverifier.EqualsVerifier; -public class TestImportFilterSettings +class TestImportFilterSettings { @Test - public void testFilterUnsetIfEmpty() + void testFilterUnsetIfEmpty() { assertFilterSet(new FilterSettings.Builder().build(), false); } @Test - public void testBuilder() + void testBuilder() { final String[] expectedArtifactTypes = { "foo", "bar" }; final FilterSettings filterSettings = new FilterSettings.Builder() // @@ -59,7 +59,7 @@ private void assertFilterSet(final FilterSettings filterSettings, final boolean } @Test - public void testEqualsAndHashContract() + void testEqualsAndHashContract() { EqualsVerifier.forClass(FilterSettings.class).verify(); } diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterContext.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterContext.java index 239984a5e..9c62dadfe 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterContext.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterContext.java @@ -24,14 +24,15 @@ import static org.hamcrest.CoreMatchers.sameInstance; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.itsallcode.openfasttrace.ImportSettings; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestImporterContext +class TestImporterContext { @Mock private ImportSettings settingsMock; @@ -40,27 +41,27 @@ public class TestImporterContext private ImporterContext context; - @Before - public void setup() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); this.context = new ImporterContext(this.settingsMock); } @Test - public void testGetImporterConfig() + void testGetImporterConfig() { assertThat(this.context.getImportSettings(), sameInstance(this.settingsMock)); } - @Test(expected = NullPointerException.class) - public void testGetImporterServiceNullByDefault() + @Test + void testGetImporterServiceNullByDefault() { - this.context.getImporterService(); + assertThrows(NullPointerException.class, () -> this.context.getImporterService()); } @Test - public void testGetImporterService() + void testGetImporterService() { this.context.setImporterService(this.importerServiceMock); assertThat(this.context.getImporterService(), sameInstance(this.importerServiceMock)); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterFactoryLoader.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterFactoryLoader.java index bcfbfc452..20f47afde 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterFactoryLoader.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterFactoryLoader.java @@ -23,8 +23,9 @@ */ import static java.util.Arrays.asList; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.when; @@ -32,15 +33,15 @@ import org.itsallcode.openfasttrace.core.serviceloader.InitializingServiceLoader; import org.itsallcode.openfasttrace.importer.input.InputFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; /** * Test for {@link ImporterFactoryLoader} */ -public class TestImporterFactoryLoader +class TestImporterFactoryLoader { @Mock private InitializingServiceLoader serviceLoaderMock; @@ -56,8 +57,8 @@ public class TestImporterFactoryLoader private ImporterFactoryLoader loader; private InputFile file; - @Before - public void setUp() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); @@ -69,32 +70,32 @@ public void setUp() when(this.unsupportedFactory.supportsFile(same(this.file))).thenReturn(false); } - @Test(expected = ImporterException.class) - public void testNoFactoryRegistered() + @Test + void testNoFactoryRegisteredThrowsException() { simulateFactories(); - this.loader.getImporterFactory(this.file); + assertThrows(ImporterException.class, () -> this.loader.getImporterFactory(this.file)); } @Test - public void testMatchingFactoryFoundOnlyOneAvailable() + void testMatchingFactoryFoundOnlyOneAvailable() { simulateFactories(this.supportedFactory1); assertFactoryFound(this.supportedFactory1); } @Test - public void testMatchingFactoryFoundTwoAvailable() + void testMatchingFactoryFoundTwoAvailable() { simulateFactories(this.supportedFactory1, this.unsupportedFactory); assertFactoryFound(this.supportedFactory1); } - @Test(expected = ImporterException.class) - public void testMultipleMatchingFactoriesFound() + @Test + void testMultipleMatchingFactoriesFoundThrowsException() { simulateFactories(this.supportedFactory1, this.supportedFactory1); - this.loader.getImporterFactory(this.file); + assertThrows(ImporterException.class, () -> this.loader.getImporterFactory(this.file)); } private void assertFactoryFound(final ImporterFactory expectedFactory) diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterService.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterService.java index 99de953bd..f3c305c9f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterService.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestImporterService.java @@ -25,7 +25,7 @@ */ import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -37,14 +37,14 @@ import org.itsallcode.openfasttrace.core.SpecificationItem; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.testutil.OsDetector; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.*; /** * Test for {@link ImporterService} */ -public class TestImporterService +class TestImporterService { @Mock private ImporterFactoryLoader factoryLoaderMock; @@ -64,8 +64,8 @@ public class TestImporterService private InputFile file; private ImporterService importerService; - @Before - public void setUp() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); this.importerService = new ImporterService(this.factoryLoaderMock, @@ -78,7 +78,7 @@ public void setUp() } @Test - public void testImportWindows() + void testImportWindows() { OsDetector.assumeRunningOnWindows(); runImporter(); @@ -86,7 +86,7 @@ public void testImportWindows() } @Test - public void testImportUnix() + void testImportUnix() { OsDetector.assumeRunningOnUnix(); runImporter(); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestLineReader.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestLineReader.java index 8b90d571d..b09f295cb 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestLineReader.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestLineReader.java @@ -34,91 +34,90 @@ import org.itsallcode.openfasttrace.importer.LineReader.LineConsumer; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestLineReader +@ExtendWith(TempDirectory.class) +class TestLineReader { private static final Path DUMMY_FILE = Paths.get("dummy"); private static final String TEST_CONTENT_LINE_1 = "testContent äöüß"; - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + @Mock private LineConsumer consumerMock; @Mock private BufferedReader readerMock; + private Path tempDir; - @Before - public void setUp() + @BeforeEach + void beforeEach(@TempDir final Path tempDir) { MockitoAnnotations.initMocks(this); + this.tempDir = tempDir; } @Test - public void testCreateForPathAndCharset() throws IOException + void testCreateForPathAndCharset() throws IOException { - final Path tempFile = this.tempFolder.newFile().toPath(); + final Path tempFile = this.tempDir.resolve("test"); Files.write(tempFile, TEST_CONTENT_LINE_1.getBytes(StandardCharsets.UTF_8)); - LineReader.create(InputFile.forPath(tempFile)).readLines(this.consumerMock); - assertLinesRead(TEST_CONTENT_LINE_1); } @Test - public void testCreateForPathAndReaderReader() throws IOException + void testCreateForPathAndReaderReader() throws IOException { - final Path tempFile = this.tempFolder.newFile().toPath(); + final Path tempFile = this.tempDir.resolve("test"); Files.write(tempFile, TEST_CONTENT_LINE_1.getBytes(StandardCharsets.UTF_8)); - LineReader.create(StreamInput.forReader(DUMMY_FILE, Files.newBufferedReader(tempFile))) .readLines(this.consumerMock); - assertLinesRead(TEST_CONTENT_LINE_1); } @Test - public void testReadLinesEmptyFile() + void testReadLinesEmptyFile() { readContent(""); assertLinesRead(); } @Test - public void testReadLinesSingleLine() + void testReadLinesSingleLine() { readContent("line1"); assertLinesRead("line1"); } @Test - public void testReadLinesSingleLineWithTrailingNewline() + void testReadLinesSingleLineWithTrailingNewline() { readContent("line1\n"); assertLinesRead("line1"); } @Test - public void testReadLinesTwoLinesWithCR() + void testReadLinesTwoLinesWithCR() { readContent("line1\nline2"); assertLinesRead("line1", "line2"); } @Test - public void testReadLinesTwoLinesWithLF() + void testReadLinesTwoLinesWithLF() { readContent("line1\rline2"); assertLinesRead("line1", "line2"); } @Test - public void testReadLinesTwoLinesWithLFCR() + void testReadLinesTwoLinesWithLFCR() { readContent("line1\r\nline2"); assertLinesRead("line1", "line2"); @@ -142,4 +141,4 @@ private void assertLinesRead(final String... expectedLines) } inOrder.verifyNoMoreInteractions(); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestMultiFileImporter.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestMultiFileImporter.java index d53d7d8b4..64800bfcb 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestMultiFileImporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestMultiFileImporter.java @@ -24,7 +24,7 @@ import static java.util.Arrays.asList; import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.same; import static org.mockito.Mockito.times; @@ -38,15 +38,15 @@ import org.itsallcode.openfasttrace.core.SpecificationItem; import org.itsallcode.openfasttrace.importer.input.InputFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.mockito.internal.hamcrest.HamcrestArgumentMatcher; import com.github.hamstercommunity.matcher.auto.AutoMatcher; -public class TestMultiFileImporter +class TestMultiFileImporter { private static final Path FOLDER = Paths.get("src/test/resources/markdown"); private static final Path PATH2 = FOLDER.resolve("sample_system_requirements.md"); @@ -66,8 +66,8 @@ public class TestMultiFileImporter private MultiFileImporter multiFileImporter; - @Before - public void setup() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); this.multiFileImporter = new MultiFileImporter(this.specItemBuilderMock, @@ -75,7 +75,7 @@ public void setup() } @Test - public void testImportSingleFile() + void testImportSingleFile() { expectFileImported(FILE1); this.multiFileImporter.importFile(FILE1); @@ -83,7 +83,7 @@ public void testImportSingleFile() } @Test - public void testImportAnySingleFile() + void testImportAnySingleFile() { expectFileImported(FILE1); this.multiFileImporter.importAny(asList(PATH1)); @@ -91,14 +91,14 @@ public void testImportAnySingleFile() } @Test - public void testImportAnyNonExistingFile() + void testImportAnyNonExistingFile() { this.multiFileImporter.importAny(asList(NON_EXISTING_FILE)); verify(this.importerMock, times(0)).runImport(); } @Test - public void testImportAnyFolderFile() + void testImportAnyFolderFile() { expectFileImported(FILE1); expectFileImported(FILE2); @@ -108,7 +108,7 @@ public void testImportAnyFolderFile() // [itest->dsn~input-directory-recursive-traversal~1] @Test - public void testRecursiveDir() + void testRecursiveDir() { expectFileImported(FILE1); expectFileImported(FILE2); @@ -117,7 +117,7 @@ public void testRecursiveDir() } @Test - public void testGetImportedItems() + void testGetImportedItems() { final List expected = new ArrayList<>(); when(this.specItemBuilderMock.build()).thenReturn(expected); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/TestSpecificationListBuilder.java b/src/test/java/org/itsallcode/openfasttrace/importer/TestSpecificationListBuilder.java index 748305b2e..a8c160449 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/TestSpecificationListBuilder.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/TestSpecificationListBuilder.java @@ -25,7 +25,7 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.*; import java.util.stream.Collectors; @@ -34,9 +34,9 @@ import org.itsallcode.openfasttrace.core.ItemStatus; import org.itsallcode.openfasttrace.core.SpecificationItem; import org.itsallcode.openfasttrace.core.SpecificationItemId; -import org.junit.Test;; +import org.junit.jupiter.api.Test;; -public class TestSpecificationListBuilder +class TestSpecificationListBuilder { private static final String DESCRIPTION = "description"; @@ -44,7 +44,7 @@ public class TestSpecificationListBuilder private final static SpecificationItemId ID = SpecificationItemId.parseId("feat~id~1"); @Test - public void testBuildBasicItem() + void testBuildBasicItem() { final SpecificationListBuilder builder = createBasicListBuilder(); builder.appendDescription(DESCRIPTION); @@ -65,7 +65,7 @@ private SpecificationListBuilder createBasicListBuilder() } @Test - public void testBuildWithStatus() + void testBuildWithStatus() { final SpecificationListBuilder builder = createBasicListBuilder(); builder.setStatus(ItemStatus.DRAFT); @@ -74,7 +74,7 @@ public void testBuildWithStatus() } @Test - public void testBuildWithTags() + void testBuildWithTags() { final SpecificationListBuilder builder = createBasicListBuilder(); builder.addTag("foo"); @@ -85,7 +85,7 @@ public void testBuildWithTags() // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testFilterArtifactOfType() + void testFilterArtifactOfType() { final SpecificationListBuilder builder = createListBuilderFilteringByArtifactTypes("dsn"); builder.beginSpecificationItem(); @@ -111,7 +111,7 @@ private SpecificationListBuilder createListBuilderFilteringByArtifactTypes( // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testFilterNeededArtifactType() + void testFilterNeededArtifactType() { final SpecificationListBuilder builder = createListBuilderFilteringByArtifactTypes("dsn", "utest", "itest"); @@ -128,7 +128,7 @@ public void testFilterNeededArtifactType() // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testFilterCoversLinkWithArtifactType() + void testFilterCoversLinkWithArtifactType() { final SpecificationItemId acceptedId = SpecificationItemId.createId("utest", "accept", 2); final SpecificationItemId rejectedId = SpecificationItemId.createId("impl", "reject", 3); @@ -146,7 +146,7 @@ public void testFilterCoversLinkWithArtifactType() // [utest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testFilterDependsLinkWithArtifactType() + void testFilterDependsLinkWithArtifactType() { final SpecificationItemId acceptedId = SpecificationItemId.createId("utest", "accept", 2); final SpecificationItemId rejectedId = SpecificationItemId.createId("impl", "reject", 3); @@ -163,7 +163,7 @@ public void testFilterDependsLinkWithArtifactType() } @Test - public void testDuplicateIdNotIgnored() + void testDuplicateIdNotIgnored() { final SpecificationListBuilder builder = SpecificationListBuilder.create(); builder.beginSpecificationItem(); @@ -177,7 +177,7 @@ public void testDuplicateIdNotIgnored() // [utest->dsn~filtering-by-tags-during-import~1] @Test - public void testFilterSpecificationItemsByTags() + void testFilterSpecificationItemsByTags() { final Set wantedTags = new HashSet<>(); wantedTags.add("client"); @@ -212,7 +212,7 @@ private void addItemWithTags(final SpecificationListBuilder builder, final Strin // [utest->dsn~filtering-by-tags-or-no-tags-during-import~1] @Test - public void testFilterSpecificationItemsByTagsIncludingNoTags() + void testFilterSpecificationItemsByTagsIncludingNoTags() { final Set wantedTags = new HashSet<>(); wantedTags.add("client"); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestRealFileInput.java b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestRealFileInput.java index df658aa0c..0e768d00b 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestRealFileInput.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestRealFileInput.java @@ -24,7 +24,7 @@ import static java.util.stream.Collectors.joining; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.nio.charset.Charset; @@ -33,19 +33,26 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; -public class TestRealFileInput +@ExtendWith(TempDirectory.class) +class TestRealFileInput { private static final String CONTENT = "file content 1\nabcöäüßÖÄÜ!\"§$%&/()=?`´'#+*~-_,.;:<>|^°"; + private Path tempDir; - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); + @BeforeEach + void beforeEach(@TempDir final Path tempDir) + { + this.tempDir = tempDir; + } @Test - public void testRelativeFileGetPath() throws IOException + void testRelativeFileGetPath() throws IOException { final Path path = Paths.get("blah"); final InputFile inputFile = InputFile.forPath(path); @@ -54,7 +61,7 @@ public void testRelativeFileGetPath() throws IOException } @Test - public void testAbsoluteFileGetPath() throws IOException + void testAbsoluteFileGetPath() throws IOException { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = InputFile.forPath(path); @@ -63,7 +70,7 @@ public void testAbsoluteFileGetPath() throws IOException } @Test - public void testRelativeFileToPath() throws IOException + void testRelativeFileToPath() throws IOException { final Path path = Paths.get("blah"); final InputFile inputFile = InputFile.forPath(path); @@ -71,7 +78,7 @@ public void testRelativeFileToPath() throws IOException } @Test - public void testAbsoluteFileToPath() throws IOException + void testAbsoluteFileToPath() throws IOException { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = InputFile.forPath(path); @@ -79,14 +86,14 @@ public void testAbsoluteFileToPath() throws IOException } @Test - public void testIsRealFileTrue() throws IOException + void testIsRealFileTrue() throws IOException { final InputFile inputFile = InputFile.forPath(Paths.get("blah")); assertThat(inputFile.isRealFile(), equalTo(true)); } @Test - public void testReadWithDefaultEncoding() throws IOException + void testReadWithDefaultEncoding() throws IOException { final InputFile inputFile = InputFile .forPath(writeTempFile(CONTENT, StandardCharsets.UTF_8)); @@ -99,7 +106,7 @@ private String readContent(final InputFile inputFile) throws IOException } @Test - public void testReadWithIsoEncoding() throws IOException + void testReadWithIsoEncoding() throws IOException { final InputFile inputFile = InputFile.forPath( writeTempFile(CONTENT, StandardCharsets.ISO_8859_1), StandardCharsets.ISO_8859_1); @@ -107,7 +114,7 @@ public void testReadWithIsoEncoding() throws IOException } @Test - public void testReadWithUtf8Encoding() throws IOException + void testReadWithUtf8Encoding() throws IOException { final InputFile inputFile = InputFile .forPath(writeTempFile(CONTENT, StandardCharsets.UTF_8), StandardCharsets.UTF_8); @@ -116,7 +123,7 @@ public void testReadWithUtf8Encoding() throws IOException private Path writeTempFile(final String content, final Charset charset) throws IOException { - final Path path = this.tempFolder.newFile().toPath(); + final Path path = this.tempDir.resolve("test"); Files.write(path, content.getBytes(charset)); return path; } diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestStreamInput.java b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestStreamInput.java index f3e4f67c8..04eaca2dc 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestStreamInput.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestStreamInput.java @@ -24,7 +24,8 @@ import static java.util.stream.Collectors.joining; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.BufferedReader; import java.io.IOException; @@ -32,14 +33,14 @@ import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestStreamInput +class TestStreamInput { private static final String CONTENT = "file content 1\nabcöäüßÖÄÜ!\"§$%&/()=?`´'#+*~-_,.;:<>|^°"; @Test - public void testRelativeFileGetPath() throws IOException + void testRelativeFileGetPath() throws IOException { final Path path = Paths.get("blah"); final InputFile inputFile = StreamInput.forReader(path, null); @@ -48,7 +49,7 @@ public void testRelativeFileGetPath() throws IOException } @Test - public void testAbsoluteFileGetPath() throws IOException + void testAbsoluteFileGetPath() throws IOException { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = StreamInput.forReader(path, null); @@ -56,22 +57,23 @@ public void testAbsoluteFileGetPath() throws IOException assertThat(inputFile.toString(), equalTo(path.toString())); } - @Test(expected = UnsupportedOperationException.class) - public void testToPathUnsupported() throws IOException + @Test + void testToPathUnsupported() throws IOException { final Path path = Paths.get("blah"); - StreamInput.forReader(path, null).toPath(); + assertThrows(UnsupportedOperationException.class, + () -> StreamInput.forReader(path, null).toPath()); } @Test - public void testIsRealFileFalse() throws IOException + void testIsRealFileFalse() throws IOException { final InputFile inputFile = StreamInput.forReader(Paths.get("blah"), null); assertThat(inputFile.isRealFile(), equalTo(false)); } @Test - public void testReadContent() throws IOException + void testReadContent() throws IOException { final InputFile inputFile = StreamInput.forReader(null, new BufferedReader(new StringReader(CONTENT))); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestZipEntryInput.java b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestZipEntryInput.java index d751cd888..e5355e8cd 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/input/TestZipEntryInput.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/input/TestZipEntryInput.java @@ -24,41 +24,43 @@ import static java.util.stream.Collectors.joining; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.zip.*; import org.itsallcode.openfasttrace.importer.ImporterException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; import org.mockito.MockitoAnnotations; -public class TestZipEntryInput +@ExtendWith(TempDirectory.class) +class TestZipEntryInput { + private static final String TEST_ZIP = "test.zip"; private static final String CONTENT = "file content 1\nabcöäüßÖÄÜ!\"§$%&/()=?`´'#+*~-_,.;:<>|^°"; - - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); private File zipFile; private ZipOutputStream zipOutputStream; - @Before - public void setUp() throws IOException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws IOException { MockitoAnnotations.initMocks(this); - this.zipFile = this.tempFolder.newFile(); + this.zipFile = tempDir.resolve(TEST_ZIP).toFile(); this.zipOutputStream = new ZipOutputStream(new FileOutputStream(this.zipFile), StandardCharsets.UTF_8); } @Test - public void testRelativeFileGetPath() throws IOException + void testRelativeFileGetPath() throws IOException { final InputFile inputFile = InputFile.forZipEntry(getZipFile(), new ZipEntry("dir/file")); final String expectedName = this.zipFile.getPath() + "!dir/file"; @@ -72,34 +74,36 @@ private ZipFile getZipFile() throws ZipException, IOException return new ZipFile(this.zipFile); } - @Test(expected = UnsupportedOperationException.class) - public void testToPathUnsupported() throws IOException + @Test + void testToPathUnsupportedThrowsException() throws IOException { - InputFile.forZipEntry(getZipFile(), new ZipEntry("file")).toPath(); + assertThrows(UnsupportedOperationException.class, + () -> InputFile.forZipEntry(getZipFile(), new ZipEntry("file")).toPath()); } - @Test(expected = IllegalArgumentException.class) - public void testCreateZipEntryForDirNotSupported() throws IOException + @Test + void testCreateZipEntryForDirNotSupportedThrowsException() throws IOException { - InputFile.forZipEntry(getZipFile(), new ZipEntry("dir/")); + assertThrows(IllegalArgumentException.class, + () -> InputFile.forZipEntry(getZipFile(), new ZipEntry("dir/"))); } @Test - public void testIsRealFileFalse() throws IOException + void testIsRealFileFalse() throws IOException { final InputFile file = InputFile.forZipEntry(getZipFile(), new ZipEntry("file")); assertThat(file.isRealFile(), equalTo(false)); } - @Test(expected = ImporterException.class) - public void testReadContentEntryDoesNotExist() throws IOException + @Test + void testReadContentEntryDoesNotExistThrowsException() throws IOException { final InputFile inputFile = InputFile.forZipEntry(getZipFile(), new ZipEntry("file")); - assertThat(readContent(inputFile), equalTo(CONTENT)); + assertThrows(ImporterException.class, () -> readContent(inputFile)); } @Test - public void testReadContentUtf8() throws IOException + void testReadContentUtf8() throws IOException { addEntryToZip("file", CONTENT.getBytes(StandardCharsets.UTF_8)); final InputFile inputFile = InputFile.forZipEntry(getZipFile(), new ZipEntry("file")); @@ -107,7 +111,7 @@ public void testReadContentUtf8() throws IOException } @Test - public void testReadContentIso() throws IOException + void testReadContentIso() throws IOException { addEntryToZip("file", CONTENT.getBytes(StandardCharsets.ISO_8859_1)); final InputFile inputFile = InputFile.forZipEntry(getZipFile(), new ZipEntry("file"), diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownAsserts.java b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownAsserts.java index ae2102f8e..df81fbb2f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownAsserts.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/MarkdownAsserts.java @@ -23,7 +23,7 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.regex.Matcher; diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java index b2167d1bb..cf9fb27e3 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporter.java @@ -40,14 +40,14 @@ import org.itsallcode.openfasttrace.importer.Importer; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InOrder; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class TestMarkdownImporter +@ExtendWith(MockitoExtension.class) +class TestMarkdownImporter { private static final String TAG2 = "Tag2"; private static final String TAG1 = "Tag1"; @@ -61,7 +61,7 @@ public class TestMarkdownImporter // [utest~md.specification_item_id_format~1] @Test - public void testIdentifyId() + void testIdentifyId() { assertMatch(MdPattern.ID, "req~foo~1", "a~b~0", "req~test~1", "req~test~999", "req~test.requirement~1", "req~test_underscore~1", @@ -71,14 +71,14 @@ public void testIdentifyId() // [utest->dsn~md.specification-item-title~1] @Test - public void testIdentifyTitle() + void testIdentifyTitle() { assertMatch(MdPattern.TITLE, "#Title", "# Title", "###### Title", "# Title"); assertMismatch(MdPattern.TITLE, "Title", "Title #", " # Title"); } @Test - public void testFindRequirement() + void testFindRequirement() { final String completeItem = createCompleteSpecificationItemInMarkdownFormat(); runImporterOnText(completeItem); @@ -150,7 +150,7 @@ private void assertAllImporterEventsCalled() } @Test - public void testTwoConsecutiveSpecificationItems() + void testTwoConsecutiveSpecificationItems() { runImporterOnText(createTwoConsecutiveItemsInMarkdownFormat()); assertImporterEventsForTwoConsecutiveItemsCalled(); @@ -181,7 +181,7 @@ private void assertImporterEventsForTwoConsecutiveItemsCalled() } @Test - public void testSingleNeeds() + void testSingleNeeds() { final String singleNeedsItem = "`foo~bar~1`\n\nNeeds: " + NEEDS_ARTIFACT_TYPE1; runImporterOnText(singleNeedsItem); @@ -190,7 +190,7 @@ public void testSingleNeeds() // [utest->dsn~md.eb-markdown-id~1] @Test - public void testIdentifyLegacyId() + void testIdentifyLegacyId() { assertMatch(MdPattern.ID, "a:b, v0", "req:test, v1", "req:test,v1", "req:test, v999", "req:test.requirement, v1", "req:test_underscore, v1", @@ -199,7 +199,7 @@ public void testIdentifyLegacyId() } @Test - public void testFindLegacyRequirement() + void testFindLegacyRequirement() { final String completeItem = createCompleteSpecificationItemInLegacyMarkdownFormat(); runImporterOnText(completeItem); @@ -266,7 +266,7 @@ private void assertAllImporterEventsForLegacyItemCalled() // [utest->dsn~md.artifact-forwarding-notation~1] @Test - public void testForwardRequirement() + void testForwardRequirement() { runImporterOnText("arch-->dsn:req~foobar~2\n" // + " * `dsn --> impl, utest,itest : arch~bar.zoo~123`"); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporterFactory.java b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporterFactory.java index 96e5b6f57..ce3621b0d 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporterFactory.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/markdown/TestMarkdownImporterFactory.java @@ -31,7 +31,7 @@ /** * Tests for {@link MarkdownImporterFactory} */ -public class TestMarkdownImporterFactory extends ImporterFactoryTestBase +class TestMarkdownImporterFactory extends ImporterFactoryTestBase { @Override protected MarkdownImporterFactory createFactory() diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java index 62cd53c44..29c092286 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java @@ -33,14 +33,14 @@ import org.itsallcode.openfasttrace.importer.SpecificationListBuilder; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.github.hamstercommunity.matcher.auto.AutoMatcher; -public class TestSpecobjectImportExport +class TestSpecobjectImportExport { @Test - public void testTraceContent() + void testTraceContent() { final String content = "\n" // + "\n" // diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java index 82d4c2e2b..71c9d83ab 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java @@ -38,18 +38,18 @@ import org.itsallcode.openfasttrace.importer.ImportEventListener; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Test for {@link SpecobjectImporter} */ -public class TestSpecobjectImporter +class TestSpecobjectImporter { private static final String PSEUDO_FILENAME = "pseudo_filename"; private static final Location STANDARD_LOCATION = Location.create(PSEUDO_FILENAME, 2); @Test - public void testImportOfMinimalSpecObject() + void testImportOfMinimalSpecObject() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -78,7 +78,7 @@ private ImportEventListener importFromString(final String text) } @Test - public void testImportOfComplexSpecObject() + void testImportOfComplexSpecObject() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -107,7 +107,7 @@ public void testImportOfComplexSpecObject() } @Test - public void testSelectedElementsAreIgnoredDuringImport() + void testSelectedElementsAreIgnoredDuringImport() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -126,7 +126,7 @@ public void testSelectedElementsAreIgnoredDuringImport() } @Test - public void testStripSuperfluousArtifactPrefixFromName() + void testStripSuperfluousArtifactPrefixFromName() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -142,7 +142,7 @@ public void testStripSuperfluousArtifactPrefixFromName() } @Test - public void testTakeOverLocationFromImportedFile() + void testTakeOverLocationFromImportedFile() { final String expectedFileName = "/home/johndoe/openfasttrace/examples/specobject.xml"; final int expectedLine = 42; @@ -163,7 +163,7 @@ public void testTakeOverLocationFromImportedFile() } @Test - public void testImportWithTags() + void testImportWithTags() { final ImportEventListener listenerMock = importFromString( "\n" // @@ -186,7 +186,7 @@ public void testImportWithTags() } @Test - public void testImportWithNeedsCoverage() + void testImportWithNeedsCoverage() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -208,7 +208,7 @@ public void testImportWithNeedsCoverage() } @Test - public void testImportWithDependencies() + void testImportWithDependencies() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -230,7 +230,7 @@ public void testImportWithDependencies() } @Test - public void testImportFulfilledByIsIgnored() + void testImportFulfilledByIsIgnored() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // @@ -258,7 +258,7 @@ public void testImportFulfilledByIsIgnored() } @Test - public void testImportProvidesCoverage() + void testImportProvidesCoverage() { final ImportEventListener listenerMock = importFromString("\n" // + " \n" // diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporterFactory.java b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporterFactory.java index 75cf67848..a803f7305 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporterFactory.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporterFactory.java @@ -33,7 +33,7 @@ /** * Tests for {@link SpecobjectImporterFactory} */ -public class TestSpecobjectImporterFactory +class TestSpecobjectImporterFactory extends ImporterFactoryTestBase { diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporter.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporter.java index 4b8adf311..c63d607f2 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporter.java @@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.BufferedReader; import java.io.StringReader; @@ -39,7 +39,7 @@ import org.itsallcode.openfasttrace.importer.SpecificationListBuilder; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.github.hamstercommunity.matcher.auto.AutoMatcher; @@ -47,7 +47,7 @@ * Test for {@link TagImporter} */ // [utest->dsn~import.full-coverage-tag~1] -public class TestTagImporter +class TestTagImporter { private static final String FILENAME = "testfilename.java"; private static final SpecificationItemId ID1 = id("artifactTypeA", "name1", 1); @@ -66,81 +66,81 @@ public class TestTagImporter private static final String WINDOWS_NEWLINE = CARRIAGE_RETURN + UNIX_NEWLINE; @Test - public void testEmptyString() + void testEmptyString() { assertItems(""); } @Test - public void testNonStringNoTag() + void testNonStringNoTag() { assertItems("non empty string"); } @Test - public void testNonStringMultiLineStringNoTag() + void testNonStringMultiLineStringNoTag() { assertItems("non empty string\nmultiline"); } @Test - public void testSingleTag() + void testSingleTag() { assertItems(tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT), // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagTrailingNewline() + void testSingleTagTrailingNewline() { assertItems(tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + UNIX_NEWLINE, // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataBefore() + void testSingleTagWithDataBefore() { assertItems("data before" + tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT), // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataBeforeWithSpaceSeparator() + void testSingleTagWithDataBeforeWithSpaceSeparator() { assertItems("data before " + tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT), // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataAfter() + void testSingleTagWithDataAfter() { assertItems(tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + "data after", // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataAfterWithSpaceSeparator() + void testSingleTagWithDataAfterWithSpaceSeparator() { assertItems(tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + " data after", // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataBeforeAndAfter() + void testSingleTagWithDataBeforeAndAfter() { assertItems("data before" + tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + "data after", // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testSingleTagWithDataBeforeAndAfterWithSpaceSeparator() + void testSingleTagWithDataBeforeAndAfterWithSpaceSeparator() { assertItems("data before " + tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + " data after", // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1)); } @Test - public void testMultipleTagsPerLineWithSeparatorWithoutSpace() + void testMultipleTagsPerLineWithSeparatorWithoutSpace() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + "separator" @@ -149,7 +149,7 @@ public void testMultipleTagsPerLineWithSeparatorWithoutSpace() } @Test - public void testMultipleTagsPerLineWithSeparatorWithSpace() + void testMultipleTagsPerLineWithSeparatorWithSpace() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + " separator " @@ -158,7 +158,7 @@ public void testMultipleTagsPerLineWithSeparatorWithSpace() } @Test - public void testMultipleTagsPerLineWithSpaceSeparator() + void testMultipleTagsPerLineWithSpaceSeparator() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + " " @@ -167,7 +167,7 @@ public void testMultipleTagsPerLineWithSpaceSeparator() } @Test - public void testMultipleTagsPerLineWithoutSeparator() + void testMultipleTagsPerLineWithoutSeparator() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + "" @@ -176,7 +176,7 @@ public void testMultipleTagsPerLineWithoutSeparator() } @Test - public void testThreeTagsOnOneLine() + void testThreeTagsOnOneLine() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + tag(COVERING_ARTIFACT_TYPE1, ID2_TEXT) @@ -186,7 +186,7 @@ public void testThreeTagsOnOneLine() } @Test - public void testLinesSeparatedWithUnixNewLine() + void testLinesSeparatedWithUnixNewLine() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + UNIX_NEWLINE @@ -195,7 +195,7 @@ public void testLinesSeparatedWithUnixNewLine() } @Test - public void testLinesSeparatedWithWindowsNewLine() + void testLinesSeparatedWithWindowsNewLine() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + WINDOWS_NEWLINE @@ -204,7 +204,7 @@ public void testLinesSeparatedWithWindowsNewLine() } @Test - public void testLinesSeparatedWithCarriageReturn() + void testLinesSeparatedWithCarriageReturn() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + CARRIAGE_RETURN @@ -213,14 +213,14 @@ public void testLinesSeparatedWithCarriageReturn() } @Test - public void testDuplicateId() + void testDuplicateId() { assertItems(tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT), // item(COVERING_ARTIFACT_TYPE1, 1, 0, ID1), item(COVERING_ARTIFACT_TYPE1, 1, 1, ID1)); } @Test - public void testDuplicateIdMultipleLines() + void testDuplicateIdMultipleLines() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + UNIX_NEWLINE @@ -229,7 +229,7 @@ public void testDuplicateIdMultipleLines() } @Test - public void testDifferentArtifactTypes() + void testDifferentArtifactTypes() { assertItems( tag(COVERING_ARTIFACT_TYPE1, ID1_TEXT) + " " diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactory.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactory.java index 89bfd0af6..4186dff85 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactory.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactory.java @@ -33,7 +33,7 @@ * Tests for {@link TagImporterFactory} */ // [utest->dsn~import.full-coverage-tag~1] -public class TestTagImporterFactory extends ImporterFactoryTestBase +class TestTagImporterFactory extends ImporterFactoryTestBase { @Override protected TagImporterFactory createFactory() diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java index 6ad36dacf..1e10a37ad 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java @@ -23,10 +23,10 @@ */ import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import java.io.File; @@ -39,15 +39,17 @@ import org.itsallcode.openfasttrace.importer.*; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.tag.config.PathConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; import org.mockito.Mock; import org.mockito.MockitoAnnotations; // [utest->dsn~import.short-coverage-tag~1] -public class TestTagImporterFactoryWithConfig +@ExtendWith(TempDirectory.class) +class TestTagImporterFactoryWithConfig { private static final String PATH1 = "path1"; private static final String PATH2 = "path2"; @@ -57,66 +59,63 @@ public class TestTagImporterFactoryWithConfig @Mock private ImporterContext contextMock; - @Rule - public TemporaryFolder temp = new TemporaryFolder(); - - @Before - public void setup() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); } @Test - public void testFactoryWithEmptyPathConfigListSupportsNothing() + void testFactoryWithEmptyPathConfigListSupportsNothing() { assertSupportsFile(configure(), PATH1, false); } @Test - public void testFactorySupportsFile() + void testFactorySupportsFile() { assertSupportsFile(configure(glob(PATH1)), PATH1, true); } @Test - public void testFactoryDoesNotSupportFileWithWrongBasePath() + void testFactoryDoesNotSupportFileWithWrongBasePath() { assertSupportsFile(configure(glob("path")), "base1/path", false); } @Test - public void testFactoryDoesNotSupportFileWithWrongPath() + void testFactoryDoesNotSupportFileWithWrongPath() { assertSupportsFile(configure(glob("path")), "base/path1", false); } @Test - public void testFactoryDoesNotSupportsFile() + void testFactoryDoesNotSupportsFile() { assertSupportsFile(configure(glob(PATH1)), PATH2, false); } - @Test(expected = ImporterException.class) - public void testFactoryThrowsExceptionForUnsupportedFile() + @Test + void testFactoryForUnsupportedFileThrowsException() { - final Importer importer = createImporter(configure(glob(PATH1)), Paths.get(PATH2)); - assertThat(importer, instanceOf(TagImporter.class)); + assertThrows(ImporterException.class, + () -> createImporter(configure(glob(PATH1)), Paths.get(PATH2))); } @Test - public void testFactoryCreatesImporterForSupportedFile() throws IOException + void testFactoryCreatesImporterForSupportedFile(@TempDir final Path tempDir) throws IOException { - final File tempFile = this.temp.newFile(); + final File tempFile = tempDir.resolve("test").toFile(); final String glob = tempFile.getAbsolutePath().replace('\\', '/'); final Importer importer = createImporter(configure(glob(glob)), tempFile.toPath()); assertThat(importer, notNullValue()); } - @Test(expected = ImporterException.class) - public void testFactoryThrowsExceptionForMissingFile() throws IOException + @Test + void testFactoryForMissingFileThrowsException() throws IOException { final Importer importer = createImporter(configure(glob(PATH1)), Paths.get(PATH1)); - importer.runImport(); + assertThrows(ImporterException.class, () -> importer.runImport()); } private void assertSupportsFile(final ImportSettings settings, final String path, diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterWithConfig.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterWithConfig.java index 4455ee410..5dbf4e820 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterWithConfig.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterWithConfig.java @@ -1,5 +1,6 @@ package org.itsallcode.openfasttrace.importer.tag; +import static org.junit.jupiter.api.Assertions.assertThrows; /*- * #%L \* OpenFastTrace @@ -35,16 +36,14 @@ import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; import org.itsallcode.openfasttrace.importer.tag.config.PathConfig; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; // [utest->dsn~import.short-coverage-tag~1] -public class TestTagImporterWithConfig +class TestTagImporterWithConfig { private static final String COVERED_ITEM_NAME1 = "covered_name1"; private static final String COVERED_ITEM_NAME2 = "covered_name2"; @@ -54,18 +53,14 @@ public class TestTagImporterWithConfig private static final String COVERED_ITEM_NAME_PREFIX = "prefix."; private static final String INVALID_REVISION = "invalidRevision"; - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Mock private PathConfig configMock; @Mock private ImportEventListener listenerMock; - private InOrder inOrderListener; - @Before - public void setUp() + @BeforeEach + void beforeEach() { MockitoAnnotations.initMocks(this); this.inOrderListener = inOrder(this.listenerMock); @@ -76,21 +71,21 @@ public void setUp() } @Test - public void testEmptyFile() + void testEmptyFile() { runImport(""); verifyZeroInteractions(this.listenerMock); } @Test - public void testFileWithoutMatchingTag() + void testFileWithoutMatchingTag() { runImport("non matching\nfile\n"); verifyZeroInteractions(this.listenerMock); } @Test - public void testFileWithNewTagFormatAlsoSupported() + void testFileWithNewTagFormatAlsoSupported() { final String itemName = "coveredtype~coveredname~1"; // do not inline to // avoid error in @@ -101,7 +96,7 @@ public void testFileWithNewTagFormatAlsoSupported() } @Test - public void testFileWithLegacyTagFormat() + void testFileWithLegacyTagFormat() { runImport("[[" + COVERED_ITEM_NAME1 + ":1]]"); verifyTag(1, SpecificationItemId.createId(COVERED_ITEM_TYPE, COVERED_ITEM_NAME1, 1), @@ -111,7 +106,7 @@ public void testFileWithLegacyTagFormat() } @Test - public void testFileWithLegacyTagFormatTwoTagsInTwoLines() + void testFileWithLegacyTagFormatTwoTagsInTwoLines() { runImport("[[" + COVERED_ITEM_NAME1 + ":1]]\n" // + "[[" + COVERED_ITEM_NAME2 + ":2]]"); @@ -125,7 +120,7 @@ public void testFileWithLegacyTagFormatTwoTagsInTwoLines() } @Test - public void testFileWithLegacyTagFormatTwoTagsInSameLine() + void testFileWithLegacyTagFormatTwoTagsInSameLine() { runImport("[[" + COVERED_ITEM_NAME1 + ":1]]" // + "[[" + COVERED_ITEM_NAME2 + ":2]]"); @@ -139,17 +134,18 @@ public void testFileWithLegacyTagFormatTwoTagsInSameLine() } @Test - public void testNonIntegerRevisionRejected() + void testNonIntegerRevisionRejected() { - this.thrown.expect(ImporterException.class); - this.thrown.expectMessage("Error processing line dummy:1 ([[" + COVERED_ITEM_NAME1 + ":" - + INVALID_REVISION + "]]): Error parsing revision '" + INVALID_REVISION - + "' for item '" + COVERED_ITEM_NAME1 + "'"); - runImport("[[" + COVERED_ITEM_NAME1 + ":" + INVALID_REVISION + "]]"); + final String expectedMessage = "Error processing line dummy:1 ([[" + COVERED_ITEM_NAME1 + + ":" + INVALID_REVISION + "]]): Error parsing revision '" + INVALID_REVISION + + "' for item '" + COVERED_ITEM_NAME1 + "'"; + assertThrows(ImporterException.class, + () -> runImport("[[" + COVERED_ITEM_NAME1 + ":" + INVALID_REVISION + "]]"), + expectedMessage); } @Test - public void testFileWithLegacyTagFormatWithPrefix() + void testFileWithLegacyTagFormatWithPrefix() { when(this.configMock.getCoveredItemNamePrefix()).thenReturn(COVERED_ITEM_NAME_PREFIX); runImport("[[" + COVERED_ITEM_NAME1 + ":1]]"); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/DescribedPathMatcherTest.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/DescribedPathMatcherTest.java index 0e03a111e..b308053e5 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/DescribedPathMatcherTest.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/DescribedPathMatcherTest.java @@ -25,7 +25,7 @@ import static java.util.stream.Collectors.toList; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.nio.file.Path; import java.nio.file.Paths; @@ -34,28 +34,28 @@ import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.testutil.OsDetector; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DescribedPathMatcherTest { private DescribedPathMatcher matcher; - @Before - public void setup() + @BeforeEach + void beforeEach() { this.matcher = null; } @Test - public void testListBasedMatcherWithEmptyListMatchesNothing() + void testListBasedMatcherWithEmptyListMatchesNothing() { createListMatcher(); assertMatches("path", false); } @Test - public void testListBasedMatcherMatchesRelativePath() + void testListBasedMatcherMatchesRelativePath() { createListMatcher("rel/path"); assertMatches("rel/path", true); @@ -68,7 +68,7 @@ public void testListBasedMatcherMatchesRelativePath() } @Test - public void testListBasedMatcherIsCaseInsensitiveUnderWindows() + void testListBasedMatcherIsCaseInsensitiveUnderWindows() { OsDetector.assumeRunningOnWindows(); createListMatcher("rel/path"); @@ -77,7 +77,7 @@ public void testListBasedMatcherIsCaseInsensitiveUnderWindows() } @Test - public void testListBasedMatcherIsCaseSensitiveUnderUnix() + void testListBasedMatcherIsCaseSensitiveUnderUnix() { OsDetector.assumeRunningOnUnix(); createListMatcher("rel/path"); @@ -86,7 +86,7 @@ public void testListBasedMatcherIsCaseSensitiveUnderUnix() } @Test - public void testListBasedMatcherMatchesAbsolutePath() + void testListBasedMatcherMatchesAbsolutePath() { createListMatcher("/abs/path"); assertMatches("/abs/path", true); @@ -95,7 +95,7 @@ public void testListBasedMatcherMatchesAbsolutePath() } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlash() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlash() { createListMatcher("C:/abs/path"); assertMatches("C:/abs/path", true); @@ -104,7 +104,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlash( } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashWindows() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashWindows() { OsDetector.assumeRunningOnWindows(); createListMatcher("C:/abs/path"); @@ -112,7 +112,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashW } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashUnix() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashUnix() { OsDetector.assumeRunningOnUnix(); createListMatcher("C:/abs/path"); @@ -120,7 +120,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithForwardSlashU } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslash() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslash() { createListMatcher("C:\\abs\\path"); assertMatches("C:\\abs\\path", true); @@ -128,7 +128,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslash() } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashUnix() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashUnix() { OsDetector.assumeRunningOnUnix(); createListMatcher("C:\\abs\\path"); @@ -137,7 +137,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashUnix } @Test - public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashWindows() + void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashWindows() { OsDetector.assumeRunningOnWindows(); createListMatcher("C:\\abs\\path"); @@ -146,7 +146,7 @@ public void testListBasedMatcherMatchesAbsoluteWindowsStylePathWithBackslashWind } @Test - public void testListBasedMatcherMatchesMultiplePaths() + void testListBasedMatcherMatchesMultiplePaths() { createListMatcher("path1", "path2"); assertMatches("path1", true); @@ -157,21 +157,21 @@ public void testListBasedMatcherMatchesMultiplePaths() } @Test - public void testListBasedMatcherDescription() + void testListBasedMatcherDescription() { createListMatcher("path1", "path2"); assertDescription("[path1, path2]"); } @Test - public void testPatternMatcherDescription() + void testPatternMatcherDescription() { createPatternMatcher("path"); assertDescription("glob:path"); } @Test - public void testPatternMatcherMatchesGlob() + void testPatternMatcherMatchesGlob() { createPatternMatcher("glob:path/**"); assertMatches("path", false); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/TestPathConfig.java b/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/TestPathConfig.java index 8a304983f..88640cc8b 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/TestPathConfig.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/tag/config/TestPathConfig.java @@ -23,7 +23,7 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.nio.file.Path; import java.nio.file.Paths; @@ -31,24 +31,24 @@ import java.util.List; import org.itsallcode.openfasttrace.importer.input.InputFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestPathConfig +class TestPathConfig { @Test - public void testGlobMatches() + void testGlobMatches() { assertMatches("glob:pattern", "pattern", true); } @Test - public void testGlobUsedByDefault() + void testGlobUsedByDefault() { assertMatches("**/pattern", "blah/blubb/pattern", true); } @Test - public void testGlobWithStarStarMatches() + void testGlobWithStarStarMatches() { assertMatches("glob:**/pattern", "blah/blubb/pattern", true); assertMatches("glob:**/pattern", "/pattern", true); @@ -57,50 +57,50 @@ public void testGlobWithStarStarMatches() } @Test - public void testGlobDoesNotMatch() + void testGlobDoesNotMatch() { assertMatches("glob:pattern", "wrongpattern", false); } @Test - public void testLiteralMatches() + void testLiteralMatches() { assertMatches("regex:pattern", "pattern", true); } @Test - public void testRegexpWithWildCardMatches() + void testRegexpWithWildCardMatches() { assertMatches("regex:.*pattern", "pattern", true); assertMatches("regex:.*pattern", "blubbpattern", true); } @Test - public void testRegexDoesNotMatch() + void testRegexDoesNotMatch() { assertMatches("regex:pattern", "wrongpattern", false); } @Test - public void testGetPatternWithoutPrefix() + void testGetPatternWithoutPrefix() { assertThat(create("pattern").getDescription(), equalTo("glob:pattern")); } @Test - public void testGetPatternWithGlobPrefix() + void testGetPatternWithGlobPrefix() { assertThat(create("glob:pattern").getDescription(), equalTo("glob:pattern")); } @Test - public void testGetPatternWithRegexPrefix() + void testGetPatternWithRegexPrefix() { assertThat(create("regex:pattern").getDescription(), equalTo("regex:pattern")); } @Test - public void testBuilder() + void testBuilder() { final List paths = new ArrayList<>(); final String pattern = "pattern"; diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java b/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java index 673aa57ce..e5008d11a 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java @@ -24,15 +24,17 @@ import static java.util.Collections.emptyList; import static java.util.stream.Collectors.joining; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; import java.io.*; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.zip.ZipEntry; @@ -42,12 +44,14 @@ import org.itsallcode.openfasttrace.importer.MultiFileImporter; import org.itsallcode.openfasttrace.importer.input.InputFile; import org.itsallcode.openfasttrace.importer.input.StreamInput; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; import org.mockito.*; +@ExtendWith(TempDirectory.class) public class ITZipFileImporter { private static final String FILE_CONTENT_STRING = "file content 1\nabcöäüßÖÄÜ!\"§$%&/()=?`´'#+*~-_,.;:<>|^°"; @@ -56,8 +60,6 @@ public class ITZipFileImporter private static final byte[] FILE_CONTENT2 = FILE_CONTENT2_STRING .getBytes(StandardCharsets.UTF_8); - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); @Mock private MultiFileImporter delegateImporterMock; @Captor @@ -67,12 +69,12 @@ public class ITZipFileImporter private ZipOutputStream zipOutputStream; private List actualFileContent; - @Before - public void setUp() throws IOException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws IOException { MockitoAnnotations.initMocks(this); this.actualFileContent = new ArrayList<>(); - this.zipFile = this.tempFolder.newFile(); + this.zipFile = tempDir.resolve("test.zip").toFile(); this.zipOutputStream = new ZipOutputStream(new FileOutputStream(this.zipFile), StandardCharsets.UTF_8); when(this.delegateImporterMock.importFile(any())).thenAnswer(invocation -> { @@ -83,28 +85,29 @@ public void setUp() throws IOException } @Test - public void testImportEmptyZipDoesNothing() throws IOException + void testImportEmptyZipDoesNothing() throws IOException { runImporter(0); } - @Test(expected = UnsupportedOperationException.class) - public void testImportNonRealFile() throws IOException + @Test + void testImportNonRealFile() throws IOException { final InputFile file = StreamInput.forReader(this.zipFile.toPath(), new BufferedReader(new StringReader(""))); - new ZipFileImporter(file, this.delegateImporterMock).runImport(); + assertThrows(UnsupportedOperationException.class, + () -> new ZipFileImporter(file, this.delegateImporterMock).runImport()); } @Test - public void testImportZipWithEmptyDirectoryDoesNothing() throws IOException + void testImportZipWithEmptyDirectoryDoesNothing() throws IOException { addZipEntryDirectory("dir"); runImporter(0); } @Test - public void testImportZipWithFileInRootDir() throws IOException + void testImportZipWithFileInRootDir() throws IOException { addEntryToZip("file", FILE_CONTENT); final List importedFiles = runImporter(1); @@ -112,7 +115,7 @@ public void testImportZipWithFileInRootDir() throws IOException } @Test - public void testImportZipWithFileInSubDir() throws IOException + void testImportZipWithFileInSubDir() throws IOException { addEntryToZip("dir/file", FILE_CONTENT); final List importedFiles = runImporter(1); @@ -120,7 +123,7 @@ public void testImportZipWithFileInSubDir() throws IOException } @Test - public void testImportZipAssertFileContent() throws IOException + void testImportZipAssertFileContent() throws IOException { addEntryToZip("file", FILE_CONTENT); @@ -130,7 +133,7 @@ public void testImportZipAssertFileContent() throws IOException } @Test - public void testImportZipWithMultipleFilesAssertFileContent() throws IOException + void testImportZipWithMultipleFilesAssertFileContent() throws IOException { addEntryToZip("file1", FILE_CONTENT); addEntryToZip("dir/file2", FILE_CONTENT2); diff --git a/src/test/java/org/itsallcode/openfasttrace/importer/zip/TestZipFileImporterFactory.java b/src/test/java/org/itsallcode/openfasttrace/importer/zip/TestZipFileImporterFactory.java index f7049fb4a..45d068d61 100644 --- a/src/test/java/org/itsallcode/openfasttrace/importer/zip/TestZipFileImporterFactory.java +++ b/src/test/java/org/itsallcode/openfasttrace/importer/zip/TestZipFileImporterFactory.java @@ -23,30 +23,30 @@ */ import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.when; import java.util.List; import org.itsallcode.openfasttrace.importer.ImporterFactoryTestBase; import org.itsallcode.openfasttrace.importer.ImporterService; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; -public class TestZipFileImporterFactory extends ImporterFactoryTestBase +class TestZipFileImporterFactory extends ImporterFactoryTestBase { @Mock private ImporterService importerServiceMock; - @Before + @BeforeEach public void configureMock() { when(this.contextMock.getImporterService()).thenReturn(this.importerServiceMock); } @Test - public void test() + void test() { new ZipFileImporterFactory(); } @@ -70,10 +70,10 @@ protected List getUnsupportedFilenames() } @Test - public void testFactoryThrowsExceptionWhenContextMissing() + void testFactoryThrowsExceptionWhenContextMissing() { - this.thrown.expect(NullPointerException.class); - this.thrown.expectMessage(equalTo("Context was not initialized")); - new ZipFileImporterFactory().createImporter(null, null); + assertThrows(NullPointerException.class, + () -> new ZipFileImporterFactory().createImporter(null, null), + "Context was not initialized"); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/matcher/MatcherTestBase.java b/src/test/java/org/itsallcode/openfasttrace/matcher/MatcherTestBase.java index 89f840701..27542855c 100644 --- a/src/test/java/org/itsallcode/openfasttrace/matcher/MatcherTestBase.java +++ b/src/test/java/org/itsallcode/openfasttrace/matcher/MatcherTestBase.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.matcher; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L \* OpenFastTrace @@ -22,15 +24,14 @@ * #L% */ - import static org.hamcrest.core.IsEqual.equalTo; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.hamcrest.Matcher; import org.hamcrest.StringDescription; import org.hamcrest.TypeSafeDiagnosingMatcher; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * This is the base class for all tests of {@link TypeSafeDiagnosingMatcher}. @@ -41,10 +42,10 @@ */ public abstract class MatcherTestBase { - @Test(expected = NullPointerException.class) - public void testNullObject() + @Test + void testNullObject() { - createMatcher(null); + assertThrows(NullPointerException.class, () -> createMatcher(null)); } protected void assertMatch(final T object) diff --git a/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemIdMatcher.java b/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemIdMatcher.java index 76696f9f2..6c7c2eac0 100644 --- a/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemIdMatcher.java +++ b/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemIdMatcher.java @@ -25,33 +25,33 @@ import org.hamcrest.Matcher; import org.itsallcode.openfasttrace.core.SpecificationItemId; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit test for {@link SpecificationItemIdMatcher} */ -public class TestSpecificationItemIdMatcher extends MatcherTestBase +class TestSpecificationItemIdMatcher extends MatcherTestBase { @Test - public void testMatches() + void testMatches() { assertMatch(baseBuilder().build()); } @Test - public void testDifferentArtifactType() + void testDifferentArtifactType() { assertDifferentFromBase(baseBuilder().artifactType("artifactType2")); } @Test - public void testDifferentName() + void testDifferentName() { assertDifferentFromBase(baseBuilder().name("name2")); } @Test - public void testDifferentRevision() + void testDifferentRevision() { assertDifferentFromBase(baseBuilder().revision(43)); } diff --git a/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemMatcher.java b/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemMatcher.java index b84426982..33aae1ebc 100644 --- a/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemMatcher.java +++ b/src/test/java/org/itsallcode/openfasttrace/matcher/TestSpecificationItemMatcher.java @@ -27,12 +27,12 @@ import org.itsallcode.openfasttrace.core.SpecificationItem; import org.itsallcode.openfasttrace.core.SpecificationItemId; import org.itsallcode.openfasttrace.core.SpecificationItem.Builder; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit test for {@link SpecificationItemMatcher} */ -public class TestSpecificationItemMatcher extends MatcherTestBase +class TestSpecificationItemMatcher extends MatcherTestBase { private final static SpecificationItemId ID1 = new SpecificationItemId.Builder() .artifactType("artifactType").name("name").revision(42).build(); @@ -44,68 +44,68 @@ public class TestSpecificationItemMatcher extends MatcherTestBase"; private Oft oft; - @Before - public void setUp() throws UnsupportedEncodingException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws UnsupportedEncodingException { - perpareOutput(); + perpareOutput(tempDir); this.oft = Oft.create(); } @Test - public void testConvertToSpecobjectFile() throws IOException + void testConvertToSpecobjectFile() throws IOException { final ImportSettings settings = ImportSettings.builder().addInputs(this.docDir).build(); final List items = this.oft.importItems(settings); diff --git a/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java b/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java index 3f988d4ee..a3c720381 100644 --- a/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java +++ b/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.mode; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L \* OpenFastTrace @@ -24,33 +26,33 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertThat; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.file.Files; +import java.nio.file.Path; import java.util.*; import org.itsallcode.openfasttrace.*; import org.itsallcode.openfasttrace.core.*; import org.itsallcode.openfasttrace.report.ReportVerbosity; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.SystemErrRule; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; +@ExtendWith(TempDirectory.class) public class ITestOftAsReporter extends AbstractOftTest { private Oft oft; - @Rule - public final SystemErrRule systemErrRule = new SystemErrRule().enableLog(); private Trace trace; private List linkedItems; - @Before - public void setUp() throws UnsupportedEncodingException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws UnsupportedEncodingException { - perpareOutput(); + perpareOutput(tempDir); final ImportSettings settings = ImportSettings.builder().addInputs(this.docDir).build(); this.oft = Oft.create(); final List items = this.oft.importItems(settings); @@ -59,7 +61,7 @@ public void setUp() throws UnsupportedEncodingException } @Test - public void testTraceToFile() throws IOException + void testTraceToFile() throws IOException { this.oft.reportToPath(this.trace, this.outputFile); assertStandardReportFileResult(); @@ -72,7 +74,7 @@ private void assertStandardReportFileResult() throws IOException } @Test - public void testTraceWithReportVerbosityMinimal() throws IOException + void testTraceWithReportVerbosityMinimal() throws IOException { final ReportSettings settings = ReportSettings.builder().verbosity(ReportVerbosity.MINIMAL) .build(); @@ -82,7 +84,7 @@ public void testTraceWithReportVerbosityMinimal() throws IOException } @Test - public void testTraceMacNewlines() throws IOException + void testTraceMacNewlines() throws IOException { final ReportSettings settings = ReportSettings.builder() // .newline(Newline.OLDMAC) // @@ -96,7 +98,7 @@ public void testTraceMacNewlines() throws IOException } @Test - public void testTraceToStdOut() throws IOException + void testTraceToStdOut() throws IOException { this.oft.reportToStdOut(this.trace); assertStandardReportStdOutResult(); @@ -109,7 +111,7 @@ private void assertStandardReportStdOutResult() throws IOException // [itest->dsn~filtering-by-artifact-types-during-import~1] @Test - public void testFilterAllowsAllAtrifactsButDsn() + void testFilterAllowsAllAtrifactsButDsn() { final Set artifactTypes = new HashSet<>(Arrays.asList("feat", "req")); assertThat("Number of items with type \"dsn\" in regular trace", diff --git a/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java b/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java index b8f9dfab9..c0d65295a 100644 --- a/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java +++ b/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.mode; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L * OpenFastTrace @@ -23,9 +25,9 @@ */ import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertThat; import java.io.IOException; +import java.nio.file.Path; import java.util.Arrays; import java.util.HashSet; import java.util.List; @@ -38,11 +40,13 @@ import org.itsallcode.openfasttrace.core.SpecificationItem; import org.itsallcode.openfasttrace.core.Trace; import org.itsallcode.openfasttrace.testutil.AbstractFileBasedTest; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; +@ExtendWith(TempDirectory.class) public class ITestReporterWithFilter extends AbstractFileBasedTest { public static final String SPECIFICATION = String.join(System.lineSeparator(), // @@ -61,21 +65,20 @@ public class ITestReporterWithFilter extends AbstractFileBasedTest "A unit test", // "Tags: tag3"); - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - private Oft oft; + private Path tempDir; - @Before - public void before() throws IOException + @BeforeEach + void beforeEach(@TempDir final Path tempDir) throws IOException { - writeTextFile(this.tempFolder.newFile("spec.md"), SPECIFICATION); + this.tempDir = tempDir; + writeTextFile(tempDir.resolve("spec.md").toFile(), SPECIFICATION); this.oft = Oft.create(); } // [itest->dsn~filtering-by-tags-during-import~1] @Test - public void testFilterWithAtLeastOneMatchingTag() + void testFilterWithAtLeastOneMatchingTag() { final FilterSettings filterSettings = new FilterSettings.Builder() // .tags(new HashSet<>(Arrays.asList("tag1", "tag2"))) // @@ -88,7 +91,7 @@ public void testFilterWithAtLeastOneMatchingTag() private List getIdsFromTraceWithFilterSettings(final FilterSettings filterSettings) { final ImportSettings importSettings = ImportSettings.builder() // - .addInputs(this.tempFolder.getRoot().toPath()) // + .addInputs(this.tempDir) // .filter(filterSettings) // .build(); final List items = this.oft.importItems(importSettings); @@ -103,7 +106,7 @@ private List getIdsFromTraceWithFilterSettings(final FilterSettings filt // [itest->dsn~filtering-by-tags-or-no-tags-during-import~1] @Test - public void testFilterWithAtLeastOneMatchingTagOrNoTags() + void testFilterWithAtLeastOneMatchingTagOrNoTags() { final FilterSettings filterSettings = new FilterSettings.Builder() // .tags(new HashSet<>(Arrays.asList("tag1", "tag2"))) // diff --git a/src/test/java/org/itsallcode/openfasttrace/report/TestReportException.java b/src/test/java/org/itsallcode/openfasttrace/report/TestReportException.java index 69dd0ba00..c8034a3f6 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/TestReportException.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/TestReportException.java @@ -23,14 +23,14 @@ */ import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestReportException +class TestReportException { @Test - public void testNewReportExceptionWithMessage() + void testNewReportExceptionWithMessage() { final String message = "foobar"; final ReportException exception = new ReportException(message); @@ -38,7 +38,7 @@ public void testNewReportExceptionWithMessage() } @Test - public void testNewReportExceptionWithMessageAndCause() + void testNewReportExceptionWithMessageAndCause() { final String message = "foobar"; final Exception cause = new Exception("barzoo"); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/TestReportFormat.java b/src/test/java/org/itsallcode/openfasttrace/report/TestReportFormat.java index 7e10350e3..0549fed4d 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/TestReportFormat.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/TestReportFormat.java @@ -23,21 +23,22 @@ */ import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestReportFormat +class TestReportFormat { @Test - public void testParseValid() + void testParseValid() { assertThat(ReportFormat.parse("plain"), equalTo(ReportFormat.PLAIN_TEXT)); } - @Test(expected = IllegalArgumentException.class) - public void testParseInalidFormatThrowsIllegalArguemtException() + @Test + void testParseInalidFormatThrowsIllegalArguemtException() { - ReportFormat.parse("invalid"); + assertThrows(IllegalArgumentException.class, () -> ReportFormat.parse("invalid")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java b/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java index ae280090d..7d0072bcc 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.report; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L * OpenFastTrace @@ -24,34 +26,34 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.File; import java.io.IOException; +import java.nio.file.Path; +import org.itsallcode.io.Capturable; +import org.itsallcode.junit.sysextensions.SystemOutGuard; import org.itsallcode.openfasttrace.ReportSettings; import org.itsallcode.openfasttrace.core.Trace; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.contrib.java.lang.system.SystemOutRule; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestReportService +@ExtendWith(TempDirectory.class) +@ExtendWith(SystemOutGuard.class) +class TestReportService { - @Rule - public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - @Mock Trace traceMock; private ReportService service; - @Before + @BeforeEach public void prepareTest() { MockitoAnnotations.initMocks(this); @@ -59,38 +61,43 @@ public void prepareTest() } @Test - public void testReportPlainText() + void testReportPlainText(final Capturable stream) { final ReportSettings settings = ReportSettings.builder().verbosity(ReportVerbosity.MINIMAL) .build(); + stream.capture(); this.service.reportTraceToStdOut(this.traceMock, settings); - assertThat(this.systemOutRule.getLog(), equalTo("not ok\n")); + assertThat(stream.getCapturedData(), equalTo("not ok\n")); } @Test - public void testReportHtml() + void testReportHtml(final Capturable stream) { final ReportSettings settings = ReportSettings.builder().outputFormat("html") .verbosity(ReportVerbosity.MINIMAL).build(); + stream.capture(); this.service.reportTraceToStdOut(this.traceMock, settings); - assertThat(this.systemOutRule.getLog(), startsWith("")); + assertThat(stream.getCapturedData(), startsWith("")); } - @Test(expected = IllegalArgumentException.class) - public void testInvalidReportFormatThrowsIllegalArgumentException() + @Test + void testInvalidReportFormatThrowsIllegalArgumentException() { final ReportSettings settings = ReportSettings.builder().outputFormat("invalid") .verbosity(ReportVerbosity.QUIET).build(); - this.service.reportTraceToStdOut(this.traceMock, settings); + assertThrows(IllegalArgumentException.class, + () -> this.service.reportTraceToStdOut(this.traceMock, settings)); } - @Test(expected = ReportException.class) - public void testReportToIllegalPathThrowsReportExpection() throws IOException + @Test + void testReportToIllegalPathThrowsReportExpection(@TempDir final Path tempDir) + throws IOException { - final File readOnlyFile = this.temporaryFolder.newFile(); + final File readOnlyFile = tempDir.resolve("readonly.txt").toFile(); readOnlyFile.setReadOnly(); final ReportSettings settings = ReportSettings.builder().verbosity(ReportVerbosity.QUIET) .build(); - this.service.reportTraceToPath(this.traceMock, readOnlyFile.toPath(), settings); + assertThrows(ReportException.class, () -> this.service.reportTraceToPath(this.traceMock, + readOnlyFile.toPath(), settings)); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java b/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java index 95ee2dd05..9692fb30c 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java @@ -23,7 +23,7 @@ */ import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; import java.io.ByteArrayOutputStream; @@ -32,24 +32,24 @@ import org.itsallcode.openfasttrace.core.*; import org.itsallcode.openfasttrace.report.Reportable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestHtmlReport +class TestHtmlReport { @Mock private Trace traceMock; - @Before + @BeforeEach public void prepareTest() { MockitoAnnotations.initMocks(this); } @Test - public void testRenderEmptyTrace() + void testRenderEmptyTrace() { final String outputAsString = renderToString(); assertThat(outputAsString, startsWith("")); @@ -67,7 +67,7 @@ protected String renderToString() } @Test - public void testRenderSimpleTrace() + void testRenderSimpleTrace() { final LinkedSpecificationItem itemA = new LinkedSpecificationItem( new SpecificationItem.Builder() // diff --git a/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReportCssInlining.java b/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReportCssInlining.java index d93ea854d..030fd75e4 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReportCssInlining.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReportCssInlining.java @@ -1,5 +1,7 @@ package org.itsallcode.openfasttrace.report.html; +import static org.hamcrest.MatcherAssert.assertThat; + /*- * #%L * OpenFastTrace @@ -23,35 +25,35 @@ */ import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Path; import org.itsallcode.openfasttrace.report.ReportException; import org.itsallcode.openfasttrace.report.view.ViewableContainer; import org.itsallcode.openfasttrace.report.view.html.HtmlViewFactory; import org.itsallcode.openfasttrace.testutil.AbstractFileBasedTest; import org.itsallcode.openfasttrace.testutil.OsDetector; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junitpioneer.jupiter.TempDirectory; +import org.junitpioneer.jupiter.TempDirectory.TempDir; -public class TestHtmlReportCssInlining extends AbstractFileBasedTest +@ExtendWith(TempDirectory.class) +class TestHtmlReportCssInlining extends AbstractFileBasedTest { private static final String CSS = "* { font-family: helvetica; }"; - @Rule - public TemporaryFolder tempFolder = new TemporaryFolder(); - // [itest->dsn~reporting.html.inline_css~1] @Test - public void testHtmlReportContainsInlineCSS() throws IOException + void testHtmlReportContainsInlineCSS(@TempDir final Path tempDir) throws IOException { - final File cssFile = this.tempFolder.newFile("test.css"); + final File cssFile = tempDir.resolve("test.css").toFile(); writeTextFile(cssFile, CSS); final ByteArrayOutputStream stream = new ByteArrayOutputStream(); final HtmlViewFactory factory = HtmlViewFactory.create(stream, cssFile.toURI().toURL()); @@ -60,23 +62,23 @@ public void testHtmlReportContainsInlineCSS() throws IOException assertThat(stream.toString(), containsString(CSS)); } - @Test(expected = ReportException.class) - public void testInliningNonExistentCssThrowsException() throws MalformedURLException + @Test + void testInliningNonExistentCssThrowsException() throws MalformedURLException { final HtmlViewFactory factory = HtmlViewFactory.create(System.out, new URL("file:///this_file_does_not_exist.css")); final ViewableContainer view = factory.createView("foo", "bar"); - view.render(); + assertThrows(ReportException.class, () -> view.render()); } - @Test(expected = ReportException.class) - public void testInliningUnreadableCssThrowsException() throws IOException + @Test + void testInliningUnreadableCssThrowsException(@TempDir final Path tempDir) throws IOException { OsDetector.assumeRunningOnUnix(); - final File cssFile = this.tempFolder.newFile("test.css"); + final File cssFile = tempDir.resolve("test.css").toFile(); cssFile.setReadable(false); final HtmlViewFactory factory = HtmlViewFactory.create(System.out, cssFile.toURI().toURL()); final ViewableContainer view = factory.createView("foo", "bar"); - view.render(); + assertThrows(ReportException.class, () -> view.render()); } -} +} \ No newline at end of file diff --git a/src/test/java/org/itsallcode/openfasttrace/report/plaintext/TestPlainTextReport.java b/src/test/java/org/itsallcode/openfasttrace/report/plaintext/TestPlainTextReport.java index dcb443407..0d9a800cc 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/plaintext/TestPlainTextReport.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/plaintext/TestPlainTextReport.java @@ -27,7 +27,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.itsallcode.openfasttrace.core.SampleArtifactTypes.*; import static org.itsallcode.openfasttrace.matcher.MultilineTextMatcher.matchesAllLines; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -41,26 +41,26 @@ import org.itsallcode.openfasttrace.core.*; import org.itsallcode.openfasttrace.report.ReportVerbosity; import org.itsallcode.openfasttrace.report.Reportable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestPlainTextReport +class TestPlainTextReport { private static final Newline NEWLINE_SEPARATOR = Newline.UNIX; @Mock private Trace traceMock; - @Before + @BeforeEach public void prepareTest() { MockitoAnnotations.initMocks(this); } @Test - public void testOutputStreamClosed() throws IOException + void testOutputStreamClosed() throws IOException { final OutputStream outputStreamMock = mock(OutputStream.class); final ReportSettings settings = ReportSettings.builder().verbosity(ReportVerbosity.SUMMARY) @@ -70,14 +70,14 @@ public void testOutputStreamClosed() throws IOException } @Test - public void testReportLevel_Quiet_Ok() + void testReportLevel_Quiet_Ok() { when(this.traceMock.hasNoDefects()).thenReturn(true); assertReportOutput(ReportVerbosity.QUIET); } @Test - public void testReportLevel_Minimal_OK() + void testReportLevel_Minimal_OK() { when(this.traceMock.hasNoDefects()).thenReturn(true); assertReportOutput(ReportVerbosity.MINIMAL, "ok"); @@ -125,7 +125,7 @@ private String getReportOutputWithNewline(final ReportVerbosity verbosity, } @Test - public void testReport_LevelMinimal_NotOk() + void testReport_LevelMinimal_NotOk() { when(this.traceMock.hasNoDefects()).thenReturn(false); assertReportOutput(ReportVerbosity.MINIMAL, "not ok"); @@ -133,7 +133,7 @@ public void testReport_LevelMinimal_NotOk() @Test // [utest->dsn~reporting.plain-text.summary~2] - public void testReport_LevelSummary_OK() + void testReport_LevelSummary_OK() { when(this.traceMock.hasNoDefects()).thenReturn(true); when(this.traceMock.count()).thenReturn(1); @@ -142,7 +142,7 @@ public void testReport_LevelSummary_OK() @Test // [utest->dsn~reporting.plain-text.summary~2] - public void testReport_LevelSummary_NotOK() + void testReport_LevelSummary_NotOK() { when(this.traceMock.hasNoDefects()).thenReturn(true); when(this.traceMock.count()).thenReturn(2); @@ -151,7 +151,7 @@ public void testReport_LevelSummary_NotOK() } @Test - public void testReport_LevelFailures_Ok() + void testReport_LevelFailures_Ok() { when(this.traceMock.hasNoDefects()).thenReturn(true); when(this.traceMock.count()).thenReturn(1); @@ -159,7 +159,7 @@ public void testReport_LevelFailures_Ok() } @Test - public void testReport_LevelFailures_NotOK() + void testReport_LevelFailures_NotOK() { final SpecificationItemId idA = SpecificationItemId.parseId("req~foo~1"); final SpecificationItemId idB = SpecificationItemId.parseId("dsn~bar~1"); @@ -172,7 +172,7 @@ public void testReport_LevelFailures_NotOK() @Test // [utest->dsn~reporting.plain-text.specification-item-overview~2] - public void testReport_LevelFailureSummaries_NotOK() + void testReport_LevelFailureSummaries_NotOK() { when(this.traceMock.count()).thenReturn(6); when(this.traceMock.countDefects()).thenReturn(4); @@ -218,7 +218,7 @@ private void prepareFailedItemDetails() // [utest->dsn~reporting.plain-text.link-details~1] @Test - public void testReport_LevelFailureDetails() + void testReport_LevelFailureDetails() { when(this.traceMock.count()).thenReturn(2); when(this.traceMock.countDefects()).thenReturn(1); @@ -242,7 +242,7 @@ public void testReport_LevelFailureDetails() // [utest->dsn~reporting.plain-text.link-details~1] @Test - public void testReport_LevelAll() + void testReport_LevelAll() { when(this.traceMock.count()).thenReturn(2); when(this.traceMock.countDefects()).thenReturn(1); @@ -345,7 +345,7 @@ private LinkedSpecificationItem createLinkedItemMock(final String idAsText, // [itest->dsn~newline-format~1] @Test - public void testReportWithDifferentLineSeparator() + void testReportWithDifferentLineSeparator() { final Newline separator = Newline.OLDMAC; @@ -382,7 +382,7 @@ public void testReportWithDifferentLineSeparator() // [utest->dsn~reporting.plain-text.specification-item-origin~1] // [utest->dsn~reporting.plain-text.linked-specification-item-origin~1] @Test - public void testReportWithOriginDisplayEnabled() + void testReportWithOriginDisplayEnabled() { final LinkedSpecificationItem itemMock = createLinkedItemMock("req~item.with-source~77", "Description", 0, 1, 0, 0, 0); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/TestAbstractViewableContainer.java b/src/test/java/org/itsallcode/openfasttrace/report/view/TestAbstractViewableContainer.java index 1ac8196d0..2d4c3318f 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/TestAbstractViewableContainer.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/TestAbstractViewableContainer.java @@ -24,15 +24,15 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.emptyCollectionOf; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.*; -public class TestAbstractViewableContainer +class TestAbstractViewableContainer { private ViewContainerStub viewableContainer; @Mock @@ -40,7 +40,7 @@ public class TestAbstractViewableContainer @Mock private Viewable viewMockB; - @Before + @BeforeEach public void prepareEachTest() { MockitoAnnotations.initMocks(this); @@ -48,7 +48,7 @@ public void prepareEachTest() } @Test - public void testListOfChildrenIsInitiallyEmpty() + void testListOfChildrenIsInitiallyEmpty() { assertThat(this.viewableContainer.getChildren(), emptyCollectionOf(Viewable.class)); } @@ -62,7 +62,7 @@ public void add() } @Test - public void testContainerCallsRenderMethodsOfChildren() + void testContainerCallsRenderMethodsOfChildren() { final int containerIndentationLevel = 42; final int childIndentationLevel = containerIndentationLevel + 1; diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/AbstractTestHtmlRenderer.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/AbstractTestHtmlRenderer.java index ef7e8c3d8..8fa6c9425 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/AbstractTestHtmlRenderer.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/AbstractTestHtmlRenderer.java @@ -23,7 +23,7 @@ */ import static org.itsallcode.openfasttrace.matcher.MultilineTextMatcher.matchesAllLines; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -31,14 +31,14 @@ import org.itsallcode.openfasttrace.report.html.HtmlReport; import org.itsallcode.openfasttrace.report.view.ViewFactory; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public class AbstractTestHtmlRenderer { protected OutputStream outputStream; protected ViewFactory factory; - @Before + @BeforeEach public void prepareEachTest() { this.outputStream = new ByteArrayOutputStream(); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSection.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSection.java index d804c00e7..ebe24ca50 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSection.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSection.java @@ -23,24 +23,24 @@ */ import org.itsallcode.openfasttrace.report.view.Viewable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestHtmlSection extends AbstractTestHtmlRenderer +class TestHtmlSection extends AbstractTestHtmlRenderer { private static final String ID = "section ID"; private static final String TITLE = "section title"; private static final int LEVEL = 1; @Override - @Before + @BeforeEach public void prepareEachTest() { super.prepareEachTest(); } @Test - public void testRender() + void testRender() { final Viewable view = this.factory.createSection(ID, TITLE); view.render(LEVEL); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSpecificationItem.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSpecificationItem.java index 0c56ebc80..67fc85101 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSpecificationItem.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlSpecificationItem.java @@ -30,12 +30,12 @@ import org.itsallcode.openfasttrace.core.*; import org.itsallcode.openfasttrace.report.view.Viewable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -public class TestHtmlSpecificationItem extends AbstractTestHtmlRenderer +class TestHtmlSpecificationItem extends AbstractTestHtmlRenderer { private static final SpecificationItemId ITEM_A_ID = SpecificationItemId .parseId("dsn~name-a~1"); @@ -50,7 +50,7 @@ public class TestHtmlSpecificationItem extends AbstractTestHtmlRenderer private LinkedSpecificationItem itemMockC; @Override - @Before + @BeforeEach public void prepareEachTest() { super.prepareEachTest(); @@ -60,7 +60,7 @@ public void prepareEachTest() } @Test - public void testRenderMinimalItem() + void testRenderMinimalItem() { final SpecificationItem item = new SpecificationItem.Builder() // .id(ITEM_A_ID) // @@ -81,7 +81,7 @@ public void testRenderMinimalItem() } @Test - public void testRenderMultiLineItem() + void testRenderMultiLineItem() { final SpecificationItem item = new SpecificationItem.Builder() // .id(ITEM_B_ID) // @@ -116,7 +116,7 @@ protected void renderItemOnIndentationLevel(final SpecificationItem item, } @Test - public void testRenderNeeds() + void testRenderNeeds() { final SpecificationItem item = new SpecificationItem.Builder() // .id(ITEM_A_ID) // @@ -141,7 +141,7 @@ public void testRenderNeeds() } @Test - public void testRenderIncomingLinks() + void testRenderIncomingLinks() { final SpecificationItem item = new SpecificationItem.Builder() // .id(ITEM_A_ID) // @@ -171,7 +171,7 @@ public void testRenderIncomingLinks() } @Test - public void testRenderOutgoingLinks() + void testRenderOutgoingLinks() { final SpecificationItem item = new SpecificationItem.Builder() // .id(ITEM_A_ID) // @@ -201,7 +201,7 @@ public void testRenderOutgoingLinks() } @Test - public void testRenderOrigin() + void testRenderOrigin() { final Location location = Location.create("foo/bar", 13); final SpecificationItem item = new SpecificationItem.Builder() // diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlView.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlView.java index b2465c299..97e941116 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlView.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlView.java @@ -23,23 +23,23 @@ */ import org.itsallcode.openfasttrace.report.view.Viewable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestHtmlView extends AbstractTestHtmlRenderer +class TestHtmlView extends AbstractTestHtmlRenderer { private static final String ID = "view ID"; private static final String TITLE = "view title"; @Override - @Before + @BeforeEach public void prepareEachTest() { super.prepareEachTest(); } @Test - public void testRender() + void testRender() { final Viewable view = this.factory.createView(ID, TITLE); view.render(1); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlViewFactory.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlViewFactory.java index 70f4ee073..2ba54b086 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlViewFactory.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestHtmlViewFactory.java @@ -23,7 +23,7 @@ */ import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.ByteArrayOutputStream; import java.io.OutputStream; @@ -32,14 +32,14 @@ import org.itsallcode.openfasttrace.report.html.HtmlReport; import org.itsallcode.openfasttrace.report.view.ViewFactory; import org.itsallcode.openfasttrace.report.view.Viewable; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestHtmlViewFactory +class TestHtmlViewFactory { private LinkedSpecificationItem item; @Test - public void testCreateSpecificationItem() + void testCreateSpecificationItem() { final OutputStream outputStream = new ByteArrayOutputStream(); final ViewFactory factory = HtmlViewFactory.create(outputStream, HtmlReport.getCssUrl()); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestMarkdownConverter.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestMarkdownConverter.java index 30825fe0b..027b7c849 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestMarkdownConverter.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestMarkdownConverter.java @@ -22,24 +22,24 @@ package org.itsallcode.openfasttrace.report.view.html; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestMarkdownConverter +class TestMarkdownConverter { private static final String LINE_SEPARATOR = "\n"; private MarkdownConverter converter; - @Before + @BeforeEach public void prepareEachTest() { this.converter = new MarkdownConverter(); } @Test - public void testConvertPreformatted() + void testConvertPreformatted() { final String original = "Before preformatted" + LINE_SEPARATOR // + " first line" + LINE_SEPARATOR // @@ -63,7 +63,7 @@ protected String convert(final String original) } @Test - public void testConvertUnorderedList() + void testConvertUnorderedList() { final String original = "Before list" + LINE_SEPARATOR // + "* first item" + LINE_SEPARATOR // @@ -87,7 +87,7 @@ protected void assertConverted(final String original, final String expected) } @Test - public void testConvertUnorderedListWithMultilineItems() + void testConvertUnorderedListWithMultilineItems() { final String original = "Before list" + LINE_SEPARATOR // + "* first item" + LINE_SEPARATOR // @@ -107,7 +107,7 @@ public void testConvertUnorderedListWithMultilineItems() } @Test - public void testConvertOrderedList() + void testConvertOrderedList() { final String original = "Before list" + LINE_SEPARATOR // + "1. first item" + LINE_SEPARATOR // @@ -126,31 +126,31 @@ public void testConvertOrderedList() } @Test - public void testCloseOrderedList() + void testCloseOrderedList() { assertConverted("5. foobar", "
  1. foobar
"); } @Test - public void testCloseUnurderedList() + void testCloseUnurderedList() { assertConverted("+ foobar", "
  • foobar
"); } @Test - public void testClosePreformatted() + void testClosePreformatted() { assertConverted(" foobar ", "
 foobar  
"); } @Test - public void testCloseWithTerminator() + void testCloseWithTerminator() { assertConverted("foobar\n\n\n", "

foobar

"); } @Test - public void testChainedParagraphs() + void testChainedParagraphs() { final String original = "First paragraph" + LINE_SEPARATOR // + "... continued" + LINE_SEPARATOR // @@ -164,28 +164,28 @@ public void testChainedParagraphs() } @Test - public void testConvertCode() + void testConvertCode() { assertConverted("This text `contains code ` and regular text", "

This text contains code and regular text

"); } @Test - public void testConvertLink() + void testConvertLink() { assertConverted("See [link label](#link-target) for details.", "

See link label for details.

"); } @Test - public void testConvertTwoLinksInOneLine() + void testConvertTwoLinksInOneLine() { assertConverted("Before [A](#to-a) between [B](#to-b) after.", "

Before A between B after.

"); } @Test - public void testConvertEmphasis() + void testConvertEmphasis() { assertConverted("This _is important_, believe me!", "

This is important, believe me!

"); @@ -194,7 +194,7 @@ public void testConvertEmphasis() } @Test - public void testConvertStrong() + void testConvertStrong() { assertConverted("This __is very important__, believe me!", "

This is very important, believe me!

"); diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java index e8676252d..bef3834ec 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java @@ -25,27 +25,27 @@ import static org.hamcrest.core.IsEqual.equalTo; import static org.itsallcode.openfasttrace.report.view.html.OriginLinkFormatter.formatAsBlock; import static org.itsallcode.openfasttrace.report.view.html.OriginLinkFormatter.formatAsSpan; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import org.itsallcode.openfasttrace.core.Location; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestOriginLinkFormatter +class TestOriginLinkFormatter { @Test - public void testNullOrigin() + void testNullOrigin() { assertThat(formatAsSpan(null), equalTo("")); } @Test - public void testEmptyOrigin() + void testEmptyOrigin() { assertThat(formatAsSpan(Location.create("", 1)), equalTo("")); } @Test - public void testFormatMinimalHttpLink() + void testFormatMinimalHttpLink() { assertPathAndLineRenderedToSpan("http://example.org", 1, "http://example.org:1"); @@ -59,7 +59,7 @@ private void assertPathAndLineRenderedToSpan(final String path, final int line, } @Test - public void testFormatMinimalHttpLinkAsBlock() + void testFormatMinimalHttpLinkAsBlock() { assertPathAndLineRenderedToBlock("http://example.org", 1, "http://example.org:1"); @@ -73,34 +73,34 @@ private void assertPathAndLineRenderedToBlock(final String path, final int line, } @Test - public void testLongerHttpLink() + void testLongerHttpLink() { assertPathAndLineRenderedToSpan("http://example.org/foo/bar%20baz?zoo", 1, "http://example.org/foo/bar%20baz?zoo:1"); } @Test - public void testFormatRegularAbsoluteUnixPath() + void testFormatRegularAbsoluteUnixPath() { assertPathAndLineRenderedToSpan("/foo/bar/baz", 1111, "/foo/bar/baz:1111"); } @Test - public void testFormatAbsoluteUnixPathWithSpecialCharacters() + void testFormatAbsoluteUnixPathWithSpecialCharacters() { assertPathAndLineRenderedToSpan("/fo o/bär/baz", 12345678, "/fo o/bär/baz:12345678"); } @Test - public void testFormatRelativeUnixPath() + void testFormatRelativeUnixPath() { assertPathAndLineRenderedToSpan("foo/bar/baz", 2, "foo/bar/baz:2"); } @Test - public void testIllegalUri() + void testIllegalUri() { assertPathAndLineRenderedToSpan("http://example.org/a b", 5, "http://example.org/a b:5"); } diff --git a/src/test/java/org/itsallcode/openfasttrace/testutil/OsDetector.java b/src/test/java/org/itsallcode/openfasttrace/testutil/OsDetector.java index 66c609648..c2187451a 100644 --- a/src/test/java/org/itsallcode/openfasttrace/testutil/OsDetector.java +++ b/src/test/java/org/itsallcode/openfasttrace/testutil/OsDetector.java @@ -22,8 +22,8 @@ * #L% */ -import static org.junit.Assume.assumeFalse; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assumptions.assumeFalse; +import static org.junit.jupiter.api.Assumptions.assumeTrue; public class OsDetector { @@ -36,12 +36,12 @@ private OsDetector() public static void assumeRunningOnWindows() { - assumeTrue("not running on windows", runningOnWindows()); + assumeTrue(OsDetector::runningOnWindows, "not running on windows"); } public static void assumeRunningOnUnix() { - assumeFalse("not running on unix", runningOnWindows()); + assumeFalse(OsDetector::runningOnWindows, "not running on unix"); } private static boolean runningOnWindows() From 0d6dd6f60ce4b482041166a2336987065c5b762a Mon Sep 17 00:00:00 2001 From: kaklakariada Date: Sat, 27 Oct 2018 13:32:19 +0200 Subject: [PATCH 5/9] Fix unit test under windows --- .../report/view/html/OriginLinkFormatter.java | 2 +- .../view/html/TestOriginLinkFormatter.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/itsallcode/openfasttrace/report/view/html/OriginLinkFormatter.java b/src/main/java/org/itsallcode/openfasttrace/report/view/html/OriginLinkFormatter.java index 6ec00ac44..465f90da4 100644 --- a/src/main/java/org/itsallcode/openfasttrace/report/view/html/OriginLinkFormatter.java +++ b/src/main/java/org/itsallcode/openfasttrace/report/view/html/OriginLinkFormatter.java @@ -138,6 +138,6 @@ private static URI convertPathWithoutProtocolToUri(final String path) private static String unWindowsify(final String path) { - return path.replaceAll("([A-Z]:)", "/$1").replaceAll("\\\\", "/"); + return path.replaceAll("\\\\", "/"); } } diff --git a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java index e8676252d..40b5b9863 100644 --- a/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java +++ b/src/test/java/org/itsallcode/openfasttrace/report/view/html/TestOriginLinkFormatter.java @@ -28,6 +28,7 @@ import static org.junit.Assert.assertThat; import org.itsallcode.openfasttrace.core.Location; +import org.itsallcode.openfasttrace.testutil.OsDetector; import org.junit.Test; public class TestOriginLinkFormatter @@ -82,17 +83,35 @@ public void testLongerHttpLink() @Test public void testFormatRegularAbsoluteUnixPath() { + OsDetector.assumeRunningOnUnix(); assertPathAndLineRenderedToSpan("/foo/bar/baz", 1111, "/foo/bar/baz:1111"); } + @Test + public void testFormatRegularAbsoluteWindowsPath() + { + OsDetector.assumeRunningOnWindows(); + assertPathAndLineRenderedToSpan("C:\\foo\\bar\\baz", 1111, + "C:\\foo\\bar\\baz:1111"); + } + @Test public void testFormatAbsoluteUnixPathWithSpecialCharacters() { + OsDetector.assumeRunningOnUnix(); assertPathAndLineRenderedToSpan("/fo o/bär/baz", 12345678, "/fo o/bär/baz:12345678"); } + @Test + public void testFormatAbsoluteWindowsPathWithSpecialCharacters() + { + OsDetector.assumeRunningOnWindows(); + assertPathAndLineRenderedToSpan("C:\\fo o\\bär\\baz", 12345678, + "C:\\fo o\\bär\\baz:12345678"); + } + @Test public void testFormatRelativeUnixPath() { From 64f5dddcf9584d787bcd613975e2d4f902f7da82 Mon Sep 17 00:00:00 2001 From: redcatbear Date: Sun, 28 Oct 2018 16:53:06 +0100 Subject: [PATCH 6/9] #159 Upgrade surefire and system extensions --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 4e167df4e..f854bd2a6 100644 --- a/pom.xml +++ b/pom.xml @@ -100,7 +100,7 @@ org.itsallcode junit5-system-extensions - 1.0.2 + 1.0.3 test @@ -142,7 +142,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.21.0 + 2.22.1 ${basedir}/src/test/resources/logging.properties From d3d511936dbd82a233dae4e5ebee3034e3cd890b Mon Sep 17 00:00:00 2001 From: redcatbear Date: Sun, 28 Oct 2018 18:20:27 +0100 Subject: [PATCH 7/9] #159: Renamed all launches to make them stand out more in case of multiple projects in one workspace. --- launch/OFT - Run all test.launch | 22 +++++++++++++++++++ launch/OFT compile.launch | 19 ++++++++++++++++ .../OFT generate SVGs from UML model.launch | 19 ++++++++++++++++ launch/OFT license update.launch | 17 ++++++++++++++ launch/OFT package.launch | 19 ++++++++++++++++ launch/OFT trace.launch | 20 +++++++++++++++++ launch/OFT update license.launch | 21 ++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 launch/OFT - Run all test.launch create mode 100644 launch/OFT compile.launch create mode 100644 launch/OFT generate SVGs from UML model.launch create mode 100644 launch/OFT license update.launch create mode 100644 launch/OFT package.launch create mode 100644 launch/OFT trace.launch create mode 100644 launch/OFT update license.launch diff --git a/launch/OFT - Run all test.launch b/launch/OFT - Run all test.launch new file mode 100644 index 000000000..b9bc7658e --- /dev/null +++ b/launch/OFT - Run all test.launch @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/launch/OFT compile.launch b/launch/OFT compile.launch new file mode 100644 index 000000000..8da2e8212 --- /dev/null +++ b/launch/OFT compile.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/launch/OFT generate SVGs from UML model.launch b/launch/OFT generate SVGs from UML model.launch new file mode 100644 index 000000000..e164338e6 --- /dev/null +++ b/launch/OFT generate SVGs from UML model.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/launch/OFT license update.launch b/launch/OFT license update.launch new file mode 100644 index 000000000..a76ad8044 --- /dev/null +++ b/launch/OFT license update.launch @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/launch/OFT package.launch b/launch/OFT package.launch new file mode 100644 index 000000000..9888b7f28 --- /dev/null +++ b/launch/OFT package.launch @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/launch/OFT trace.launch b/launch/OFT trace.launch new file mode 100644 index 000000000..e5c9999c7 --- /dev/null +++ b/launch/OFT trace.launch @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/launch/OFT update license.launch b/launch/OFT update license.launch new file mode 100644 index 000000000..ab99bc4f1 --- /dev/null +++ b/launch/OFT update license.launch @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + From 33e4a58ad5f2b9301b1644fbaf99ffdaa352965f Mon Sep 17 00:00:00 2001 From: redcatbear Date: Sun, 28 Oct 2018 18:21:59 +0100 Subject: [PATCH 8/9] #159: Added missing SVGs. --- doc/images/uml/class/cl_importer_overview.svg | 1 + doc/images/uml/class/cl_report_rendering.svg | 1 + 2 files changed, 2 insertions(+) create mode 100644 doc/images/uml/class/cl_importer_overview.svg create mode 100644 doc/images/uml/class/cl_report_rendering.svg diff --git a/doc/images/uml/class/cl_importer_overview.svg b/doc/images/uml/class/cl_importer_overview.svg new file mode 100644 index 000000000..6f2091081 --- /dev/null +++ b/doc/images/uml/class/cl_importer_overview.svg @@ -0,0 +1 @@ +java.utilorg.itsallcode.openfasttraceimporterzipcore.serviceloaderServiceLoaderImporterFactoryLoaderMultiFileImporter«interface»ImporterrunImport() : void«abstract»ImporterFactorysupportsFile(inputFile: InputFile) : booleancreateImporter(inputFile: InputFile, listener: ImportEventListener) : ImportergetContext() : ImporterContextImporterServiceImporterService(context: ImporterContext) : ImporterServicecreateImporter() : MultiFileImporter«abstract»RegExMatchingImporterFactoryImporterContextgetImporterService() : ImporterServicesetImporterService(importerService: ImporterService) : voidZipFileImporterZipFileImporterFactoryInitializingServiceLoader«interface»Initializableinit(context: ImporterContext) : void«create»contains«create»delegatespasses«initialize»getavailablefactoriesfind factory responsiblefor input format«create»«use» \ No newline at end of file diff --git a/doc/images/uml/class/cl_report_rendering.svg b/doc/images/uml/class/cl_report_rendering.svg new file mode 100644 index 000000000..a2dffbc11 --- /dev/null +++ b/doc/images/uml/class/cl_report_rendering.svg @@ -0,0 +1 @@ +HtmlSectionHtmlSection(id: String, title: String)HtmlSpecificationItemHtmlSpecificationItem(LinkedSpecificationItem item)HtmlViewHtmlView(title: String)«interface»Viewablerender()render(level : int)«interface»ViewableContaineradd(Viewable child)renderBeforeChildren()renderChildren()renderAfterChildren()«abstract»AbstractViewContainerchildren : List<Viewable>add(Viewable child)HtmlViewFactory«abstract»AbstractViewFactorycreateView(title: String) : ViewableContainercreateSection(id: String, title: String) : ViewableContainercreateSpecificationItem(item: LinkedSpecificationItem) : ViewableContainerContentTypePLAIN_TEXTHTMLcreatecreatecreate \ No newline at end of file From ed2b53bd0090ad22ce51986a30c3eec51e7720d9 Mon Sep 17 00:00:00 2001 From: redcatbear Date: Sun, 28 Oct 2018 18:42:46 +0100 Subject: [PATCH 9/9] #159: Fixed POM for version detection. --- pom.xml | 679 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 339 insertions(+), 340 deletions(-) diff --git a/pom.xml b/pom.xml index 0a121cba6..eef175d10 100644 --- a/pom.xml +++ b/pom.xml @@ -1,341 +1,340 @@ - - 4.0.0 - org.itsallcode - openfasttrace - 2.0.2 - OpenFastTrace - Free requirement tracking suite - https://github.com/itsallcode/openfasttrace - - 1.8 - 5.3.1 - 1.3.1 - UTF-8 - - - - GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html - repo - - - - - redcatbear - https://github.com/redcatbear - itsallcode - https://github.com/itsallcode - - - sascha15432 - https://github.com/sascha15432 - itsallcode - https://github.com/itsallcode - - - kaklakariada - https://github.com/kaklakariada - itsallcode - https://github.com/itsallcode - github@chp1.net - - - - scm:git:https://github.com/itsallcode/openfasttrace.git - scm:git:https://github.com/itsallcode/openfasttrace.git - https://github.com/itsallcode/openfasttrace - - - - jcenter - http://jcenter.bintray.com/ - - - - - itsallcode-maven-repo - https://api.bintray.com/maven/itsallcode/itsallcode/openfasttrace/;publish=0 - - - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.version} - test - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - org.junit.platform - junit-platform-launcher - ${junit.platform.version} - test - - - org.junit-pioneer - junit-pioneer - 0.2.2 - - - org.hamcrest - hamcrest-all - 1.3 - test - - - org.mockito - mockito-junit-jupiter - 2.23.0 - test - - - org.itsallcode - junit5-system-extensions - 1.0.3 - test - - - com.github.kaklakariada - hamcrest-auto-matcher - 0.4.3 - test - - - nl.jqno.equalsverifier - equalsverifier - 2.4.6 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java.version} - ${java.version} - - - - org.apache.maven.plugins - maven-jar-plugin - 3.1.0 - - - - org.itsallcode.openfasttrace.cli.CliStarter - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.22.1 - - - ${basedir}/src/test/resources/logging.properties - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - - attach-javadocs - - jar - - - - - UTF-8 - - true - false - false - - - - org.jacoco - jacoco-maven-plugin - 0.8.1 - - - - prepare-agent - - - - report - test - - report - - - - - - org.codehaus.mojo - license-maven-plugin - 1.16 - - false - true - gpl_v3 - itsallcode.org - 2016 - - - test/resources/specobject/*.xml - - **/*.css - **/*.html - - true - true - true - true - UTF-8 - false - - - - check-file-header - - check-file-header - - validate - - - add-third-party-licenses - - add-third-party - third-party-report - download-licenses - - - - - - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - trace - - java - - - - - org.itsallcode.openfasttrace.cli.CliStarter - trace -s doc src/main/java src/test/java - - - - org.pitest - pitest-maven - 1.4.0 - - - - - - - org.eclipse.m2e - lifecycle-mapping - 1.0.0 - - - - - - - org.codehaus.mojo - - - license-maven-plugin - - - [1.8,) - - - - check-file-header - - add-third-party - - - - - - - - - - - - com.github.jeluard - plantuml-maven-plugin - 1.2 - - - ${basedir}/model/diagrams - - **/*.plantuml - - - svg - ${basedir}/doc/images/uml - - - - net.sourceforge.plantuml - plantuml - 8059 - - - - - - - - - - org.apache.maven.plugins - maven-surefire-report-plugin - 2.21.0 - - - + + 4.0.0 + org.itsallcode + openfasttrace + 2.0.2 + OpenFastTrace + Free requirement tracking suite + https://github.com/itsallcode/openfasttrace + + 1.8 + 5.3.1 + 1.3.1 + UTF-8 + + + + GNU General Public License v3.0 + https://www.gnu.org/licenses/gpl-3.0.html + repo + + + + + redcatbear + https://github.com/redcatbear + itsallcode + https://github.com/itsallcode + + + sascha15432 + https://github.com/sascha15432 + itsallcode + https://github.com/itsallcode + + + kaklakariada + https://github.com/kaklakariada + itsallcode + https://github.com/itsallcode + github@chp1.net + + + + scm:git:https://github.com/itsallcode/openfasttrace.git + scm:git:https://github.com/itsallcode/openfasttrace.git + https://github.com/itsallcode/openfasttrace + + + + jcenter + http://jcenter.bintray.com/ + + + + + itsallcode-maven-repo + https://api.bintray.com/maven/itsallcode/itsallcode/openfasttrace/;publish=0 + + + + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + org.junit.platform + junit-platform-launcher + ${junit.platform.version} + test + + + org.junit-pioneer + junit-pioneer + 0.2.2 + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.mockito + mockito-junit-jupiter + 2.23.0 + test + + + org.itsallcode + junit5-system-extensions + 1.0.3 + test + + + com.github.kaklakariada + hamcrest-auto-matcher + 0.4.3 + test + + + nl.jqno.equalsverifier + equalsverifier + 2.4.6 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-jar-plugin + 3.1.0 + + + + org.itsallcode.openfasttrace.cli.CliStarter + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + + ${basedir}/src/test/resources/logging.properties + + + + + org.apache.maven.plugins + maven-source-plugin + 3.0.1 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.0.1 + + + attach-javadocs + + jar + + + + + UTF-8 + + true + false + false + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + + prepare-agent + + + + report + test + + report + + + + + + org.codehaus.mojo + license-maven-plugin + 1.16 + + false + true + gpl_v3 + itsallcode.org + 2016 + + + test/resources/specobject/*.xml + + **/*.css + **/*.html + + true + true + true + true + UTF-8 + false + + + + check-file-header + + check-file-header + + validate + + + add-third-party-licenses + + add-third-party + third-party-report + download-licenses + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + trace + + java + + + + + org.itsallcode.openfasttrace.cli.CliStarter + trace -s doc src/main/java src/test/java + + + + org.pitest + pitest-maven + 1.4.0 + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.codehaus.mojo + + + license-maven-plugin + + + [1.8,) + + + + check-file-header + + add-third-party + + + + + + + + + + + + com.github.jeluard + plantuml-maven-plugin + 1.2 + + + ${basedir}/model/diagrams + + **/*.plantuml + + + svg + ${basedir}/doc/images/uml + + + + net.sourceforge.plantuml + plantuml + 8059 + + + + + + + + + + org.apache.maven.plugins + maven-surefire-report-plugin + 2.21.0 + + +