diff --git a/api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.java b/api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.java index 6b9c6086f..23bb7ed5a 100644 --- a/api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.java +++ b/api/src/main/java/org/itsallcode/openfasttrace/api/core/LinkedSpecificationItem.java @@ -3,7 +3,6 @@ import java.util.*; import java.util.Map.Entry; import java.util.function.Predicate; -import java.util.stream.Collectors; /** * Specification items with links that can be followed. @@ -147,8 +146,7 @@ public void addLinkToItemWithStatus(final LinkedSpecificationItem item, final Li cacheOverCoveredArtifactType(item); addMyItemIdToCoveringItem(item); break; - case COVERED_OUTDATED: - case COVERED_PREDATED: + case COVERED_OUTDATED, COVERED_PREDATED: addMyItemIdToCoveringItem(item); break; default: @@ -395,7 +393,7 @@ private List getIncomingItems() .stream() // .filter(entry -> entry.getKey().isIncoming()) // .flatMap(entry -> entry.getValue().stream()) // - .collect(Collectors.toList()); + .toList(); } /** diff --git a/api/src/main/java/org/itsallcode/openfasttrace/api/core/Trace.java b/api/src/main/java/org/itsallcode/openfasttrace/api/core/Trace.java index c4461d73f..71a8ecceb 100644 --- a/api/src/main/java/org/itsallcode/openfasttrace/api/core/Trace.java +++ b/api/src/main/java/org/itsallcode/openfasttrace/api/core/Trace.java @@ -1,7 +1,6 @@ package org.itsallcode.openfasttrace.api.core; import java.util.List; -import java.util.stream.Collectors; /** * The result of tracing requirements. @@ -58,7 +57,7 @@ public List getDefectIds() { return this.defectItems.stream() .map(LinkedSpecificationItem::getId) - .collect(Collectors.toList()); + .toList(); } /** diff --git a/api/src/test/java/org/itsallcode/openfasttrace/api/core/TestLinkedSpecificationItem.java b/api/src/test/java/org/itsallcode/openfasttrace/api/core/TestLinkedSpecificationItem.java index 78abeccd4..c8fb4cc06 100644 --- a/api/src/test/java/org/itsallcode/openfasttrace/api/core/TestLinkedSpecificationItem.java +++ b/api/src/test/java/org/itsallcode/openfasttrace/api/core/TestLinkedSpecificationItem.java @@ -30,7 +30,7 @@ class TestLinkedSpecificationItem private SpecificationItem itemMock, coveredItemMock, otherItemMock; @BeforeEach - public void prepareAllTests() + void prepareAllTests() { this.linkedItem = new LinkedSpecificationItem(this.itemMock); this.coveredLinkedItem = new LinkedSpecificationItem(this.coveredItemMock); diff --git a/api/src/test/java/org/itsallcode/openfasttrace/api/importer/TestSpecificationListBuilder.java b/api/src/test/java/org/itsallcode/openfasttrace/api/importer/TestSpecificationListBuilder.java index ff60bf4cb..2a2691b52 100644 --- a/api/src/test/java/org/itsallcode/openfasttrace/api/importer/TestSpecificationListBuilder.java +++ b/api/src/test/java/org/itsallcode/openfasttrace/api/importer/TestSpecificationListBuilder.java @@ -6,7 +6,6 @@ import static org.junit.jupiter.api.Assertions.assertAll; import java.util.*; -import java.util.stream.Collectors; import org.itsallcode.openfasttrace.api.FilterSettings; import org.itsallcode.openfasttrace.api.core.*; @@ -16,7 +15,7 @@ class TestSpecificationListBuilder { private static final String DESCRIPTION = "description"; private static final String TITLE = "title"; - private final static SpecificationItemId ID = SpecificationItemId.parseId("feat~id~1"); + private static final SpecificationItemId ID = SpecificationItemId.parseId("feat~id~1"); @Test void testBuildBasicItem() @@ -168,7 +167,7 @@ void testFilterSpecificationItemsByTags() addItemWithTags(builder, "out-C", "exporter", "database"); addItemWithTags(builder, "out-D"); final List items = builder.build(); - assertThat(items.stream().map(SpecificationItem::getName).collect(Collectors.toList()), + assertThat(items.stream().map(SpecificationItem::getName).toList(), containsInAnyOrder("in-A", "in-B")); } @@ -202,7 +201,7 @@ void testFilterSpecificationItemsByTagsIncludingNoTags() addItemWithTags(builder, "out-C", "exporter", "database"); addItemWithTags(builder, "in-D"); final List items = builder.build(); - assertThat(items.stream().map(SpecificationItem::getName).collect(Collectors.toList()), + assertThat(items.stream().map(SpecificationItem::getName).toList(), containsInAnyOrder("in-A", "in-B", "in-D")); } diff --git a/api/src/test/java/org/itsallcode/openfasttrace/api/importer/input/TestRealFileInput.java b/api/src/test/java/org/itsallcode/openfasttrace/api/importer/input/TestRealFileInput.java index 0fd56d46d..555570f31 100644 --- a/api/src/test/java/org/itsallcode/openfasttrace/api/importer/input/TestRealFileInput.java +++ b/api/src/test/java/org/itsallcode/openfasttrace/api/importer/input/TestRealFileInput.java @@ -26,7 +26,7 @@ void beforeEach(@TempDir final Path tempDir) } @Test - void testRelativeFileGetPath() throws IOException + void testRelativeFileGetPath() { final Path path = Paths.get("blah"); final InputFile inputFile = RealFileInput.forPath(path); @@ -35,7 +35,7 @@ void testRelativeFileGetPath() throws IOException } @Test - void testAbsoluteFileGetPath() throws IOException + void testAbsoluteFileGetPath() { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = RealFileInput.forPath(path); @@ -44,7 +44,7 @@ void testAbsoluteFileGetPath() throws IOException } @Test - void testRelativeFileToPath() throws IOException + void testRelativeFileToPath() { final Path path = Paths.get("blah"); final InputFile inputFile = RealFileInput.forPath(path); @@ -52,7 +52,7 @@ void testRelativeFileToPath() throws IOException } @Test - void testAbsoluteFileToPath() throws IOException + void testAbsoluteFileToPath() { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = RealFileInput.forPath(path); @@ -60,7 +60,7 @@ void testAbsoluteFileToPath() throws IOException } @Test - void testIsRealFileTrue() throws IOException + void testIsRealFileTrue() { final InputFile inputFile = RealFileInput.forPath(Paths.get("blah")); assertThat(inputFile.isRealFile(), equalTo(true)); diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/LinkedItemIndex.java b/core/src/main/java/org/itsallcode/openfasttrace/core/LinkedItemIndex.java index 25140566a..c09918a2f 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/LinkedItemIndex.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/LinkedItemIndex.java @@ -35,7 +35,7 @@ public static LinkedItemIndex create(final List items) private static List wrapItems(final List items) { - return items.stream().map(LinkedSpecificationItem::new).collect(Collectors.toList()); + return items.stream().map(LinkedSpecificationItem::new).toList(); } /** diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/Linker.java b/core/src/main/java/org/itsallcode/openfasttrace/core/Linker.java index 0fc738c43..5660bd111 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/Linker.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/Linker.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import org.itsallcode.openfasttrace.api.core.*; @@ -35,7 +34,7 @@ private List wrapItems(final List it { return items.stream() // .map(LinkedSpecificationItem::new) // - .collect(Collectors.toList()); + .toList(); } /** diff --git a/core/src/main/java/org/itsallcode/openfasttrace/core/Tracer.java b/core/src/main/java/org/itsallcode/openfasttrace/core/Tracer.java index d52fe0735..78688c96d 100644 --- a/core/src/main/java/org/itsallcode/openfasttrace/core/Tracer.java +++ b/core/src/main/java/org/itsallcode/openfasttrace/core/Tracer.java @@ -1,7 +1,6 @@ package org.itsallcode.openfasttrace.core; import java.util.List; -import java.util.stream.Collectors; import org.itsallcode.openfasttrace.api.core.LinkedSpecificationItem; import org.itsallcode.openfasttrace.api.core.Trace; @@ -33,7 +32,7 @@ public Trace trace(final List items) builder.items(items); builder.defectItems(items.stream() // .filter(LinkedSpecificationItem::isDefect) // - .collect(Collectors.toList())); + .toList()); return builder.build(); } } diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java index ed0f3a1f7..7a19ef239 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedItemIndex.java @@ -18,13 +18,13 @@ @ExtendWith(MockitoExtension.class) class TestLinkedItemIndex { - private final static SpecificationItemId DUPLICATE_ID_1 = SpecificationItemId.createId("type", + private static final SpecificationItemId DUPLICATE_ID_1 = SpecificationItemId.createId("type", "name", 42); - private final static SpecificationItemId DUPLICATE_ID_2 = SpecificationItemId.createId("type", + private static final SpecificationItemId DUPLICATE_ID_2 = SpecificationItemId.createId("type", "name", 42); - private final static SpecificationItemId DUPLICATE_ID_INGORING_VERSION = SpecificationItemId + private static final SpecificationItemId DUPLICATE_ID_INGORING_VERSION = SpecificationItemId .createId("type", "name", 42 + 1); - private final static SpecificationItemId UNIQUE_ID = SpecificationItemId.createId("type2", + private static final SpecificationItemId UNIQUE_ID = SpecificationItemId.createId("type2", "name2", 42 + 1); @Mock @@ -32,7 +32,7 @@ class TestLinkedItemIndex duplicateIdIgnoringVersionItemMock; @BeforeEach - public void prepareTest() + void prepareTest() { lenient().when(this.duplicateIdItem1Mock.getId()).thenReturn(DUPLICATE_ID_1); lenient().when(this.duplicateIdItem2Mock.getId()).thenReturn(DUPLICATE_ID_2); diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java index 2cee0e130..bc6c38a85 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinkedSpecificationItem.java @@ -31,7 +31,7 @@ class TestLinkedSpecificationItem private SpecificationItem itemMock, coveredItemMock, otherItemMock; @BeforeEach - public void prepareAllTests() + void prepareAllTests() { this.linkedItem = new LinkedSpecificationItem(this.itemMock); this.coveredLinkedItem = new LinkedSpecificationItem(this.coveredItemMock); diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java index e2f169a50..9c34cee78 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestLinker.java @@ -45,13 +45,13 @@ private List linkItems(final SpecificationItem... items private void assertItemUnderTestHasExactlyOneLinkWithStatus( final SpecificationItem itemUnderTest, final List linkedItems, - final LinkStatus expected_status) + final LinkStatus expectedStatus) { final Optional linkedItemUnderTest = findLinkedItem(itemUnderTest, linkedItems); if (linkedItemUnderTest.isPresent()) { - assertItemHasExactlyOneLinkWithStatus(linkedItemUnderTest.get(), expected_status); + assertItemHasExactlyOneLinkWithStatus(linkedItemUnderTest.get(), expectedStatus); } else { @@ -92,7 +92,7 @@ void testDetectOutgoingLinkStatusOutdated() .addCoveredId(REQ, "this-is-newer-than-link", 1) // .build(); final List linkedItems = linkItems(covering, covered); - final Map expectedStatuses = new HashMap<>(); + final Map expectedStatuses = new EnumMap<>(LinkStatus.class); expectedStatuses.put(LinkStatus.OUTDATED, 1); expectedStatuses.put(LinkStatus.ORPHANED, 1); assertItemHasLinksWithStatus(findLinkedItem(covering, linkedItems).get(), expectedStatuses); @@ -111,7 +111,7 @@ void testDetectOutgoingLinkStatusPredated() .addCoveredId(REQ, "this-is-older-than-link", 2) // .build(); final List linkedItems = linkItems(covering, covered); - final Map expectedStatuses = new HashMap<>(); + final Map expectedStatuses = new EnumMap<>(LinkStatus.class); expectedStatuses.put(LinkStatus.PREDATED, 1); expectedStatuses.put(LinkStatus.ORPHANED, 1); assertItemHasLinksWithStatus(findLinkedItem(covering, linkedItems).get(), expectedStatuses); @@ -171,7 +171,7 @@ void testDetectIncomingLinkStatusCoveredShallow() private void assertItemHasExactlyOneLinkWithStatus(final LinkedSpecificationItem itemUnderTest, final LinkStatus expectedStatus) { - final Map expectedStatuses = new HashMap<>(); + final Map expectedStatuses = new EnumMap<>(LinkStatus.class); expectedStatuses.put(expectedStatus, 1); assertItemHasLinksWithStatus(itemUnderTest, expectedStatuses); } @@ -303,7 +303,7 @@ void testCoverageForDifferentArtifactTypes() linkedItems); if (linkedCovered.isPresent()) { - final Map expectedLinksOnCovered = new HashMap<>(); + final Map expectedLinksOnCovered = new EnumMap<>(LinkStatus.class); expectedLinksOnCovered.put(COVERED_SHALLOW, 1); expectedLinksOnCovered.put(COVERED_UNWANTED, 1); assertItemHasLinksWithStatus(linkedCovered.get(), expectedLinksOnCovered); diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java index d077bcc20..054fd997e 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestSpecificationItem.java @@ -9,7 +9,6 @@ import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; import org.itsallcode.openfasttrace.api.core.ItemStatus; import org.itsallcode.openfasttrace.api.core.Location; @@ -25,25 +24,26 @@ class TestSpecificationItem { private static final String NOT_NEEDED_ARTIFACT_TYPE = "not_needed"; private static final String NEEDED_ARTIFACT_TYPE = "needed"; - final static String ARTIFACT_TYPE = "req"; - final static String NAME = "foobar"; - final static int REVISION = 1; - final static String ID_AS_TEXT = ARTIFACT_TYPE + SpecificationItemId.ARTIFACT_TYPE_SEPARATOR + static final String ARTIFACT_TYPE = "req"; + static final String NAME = "foobar"; + static final int REVISION = 1; + static final String ID_AS_TEXT = ARTIFACT_TYPE + SpecificationItemId.ARTIFACT_TYPE_SEPARATOR + NAME + SpecificationItemId.REVISION_SEPARATOR + REVISION; - final static SpecificationItemId ID = SpecificationItemId.parseId(ID_AS_TEXT); - final static String DESCRIPTION = "This is a description\nwith multiple lines"; - final static String RATIONALE = "A rationale\nwith multiple lines"; - final static String COMMENT = "A comment\nwith multiple lines"; - final static List COVERED_IDS = parseIds("feat~foo~1", "feat~bar~2", + static final SpecificationItemId ID = SpecificationItemId.parseId(ID_AS_TEXT); + static final String DESCRIPTION = "This is a description\nwith multiple lines"; + static final String RATIONALE = "A rationale\nwith multiple lines"; + static final String COMMENT = "A comment\nwith multiple lines"; + static final List COVERED_IDS = parseIds("feat~foo~1", "feat~bar~2", "constr~baz~3"); - final static List NEEDED_ARTIFACT_TYPES = Arrays.asList("dsn", "uman"); - final static List DEPEND_ON_IDS = parseIds("req~blah~4", "req~zoo~5"); + static final List NEEDED_ARTIFACT_TYPES = Arrays.asList("dsn", "uman"); + static final List DEPEND_ON_IDS = parseIds("req~blah~4", "req~zoo~5"); private static final String TITLE = "The title"; private static List parseIds(final String... ids) { - return Arrays.asList(ids).stream().map(SpecificationItemId::parseId) - .collect(Collectors.toList()); + return Arrays.stream(ids) + .map(SpecificationItemId::parseId) + .toList(); } // [utest.requirement_format~1] @@ -213,7 +213,7 @@ void testTagBuilder() void testBuildingWithOutIdThrowsExepction() { final Builder builder = item(); - assertThrows(IllegalStateException.class, () -> builder.build()); + assertThrows(IllegalStateException.class, builder::build); } // [utest->dsn~specification-item~3] diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java index 7990199e7..64e1ac406 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracer.java @@ -28,7 +28,7 @@ class TestTracer LinkedSpecificationItem aMock, bMock, cMock; @BeforeEach - public void prepareTest() + void prepareTest() { lenient().when(this.aMock.getId()).thenReturn(ID_A); lenient().when(this.bMock.getId()).thenReturn(ID_B); diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracing.java b/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracing.java index c422bc541..3a2c50ece 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracing.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/TestTracing.java @@ -5,7 +5,6 @@ import static org.itsallcode.openfasttrace.testutil.core.ItemBuilderFactory.item; import static org.junit.jupiter.api.Assertions.assertAll; -import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -63,8 +62,7 @@ private Trace traceItems(final SpecificationItem.Builder... builders) final List items = buildTestItems(builders); final Oft oft = Oft.create(); final List linkedItems = oft.link(items); - final Trace trace = oft.trace(linkedItems); - return trace; + return oft.trace(linkedItems); } private List buildTestItems(final SpecificationItem.Builder... builders) @@ -80,7 +78,7 @@ private List buildTestItems(final SpecificationItem.Builder.. // [utest->dsn~tracing.deep-coverage~1] // [utest->dsn~tracing.needed-coverage-status~1] @Test - void testThreeLevelsOk() throws IOException + void testThreeLevelsOk() { final Trace trace = traceItems( // this.grandParentBuilder.addNeedsArtifactType(PARENT_ARTIFACT_TYPE), // @@ -110,7 +108,7 @@ void testThreeLevelsOk() throws IOException // [utest->dsn~tracing.deep-coverage~1] // [utest->dsn~tracing.needed-coverage-status~1] @Test - void testTwoLevelsWithOneNeededArtifactTypeMissing() throws IOException + void testTwoLevelsWithOneNeededArtifactTypeMissing() { final Trace trace = traceItems( // this.parentBuilder.addNeedsArtifactType(CHILD_A_ARTIFACT_TYPE) @@ -131,7 +129,7 @@ void testTwoLevelsWithOneNeededArtifactTypeMissing() throws IOException // [utest->dsn~tracing.link-cycle~1] @Test - void testSelfCycle() throws IOException + void testSelfCycle() { final Trace trace = traceItems( // this.childABuilder.addNeedsArtifactType("any").addCoveredId(childAId)); @@ -144,7 +142,7 @@ void testSelfCycle() throws IOException // [utest->dsn~tracing.link-cycle~1] @Test - void testTwoLevelsWithTwoLevelCycle() throws IOException + void testTwoLevelsWithTwoLevelCycle() { final Trace trace = traceItems( // this.parentBuilder.addNeedsArtifactType(CHILD_A_ARTIFACT_TYPE) @@ -166,7 +164,7 @@ void testTwoLevelsWithTwoLevelCycle() throws IOException // [utest->dsn~tracing.link-cycle~1] @Test - void testTwoLevelsWithThreeLevelCycle() throws IOException + void testTwoLevelsWithThreeLevelCycle() { final Trace trace = traceItems( // this.grandParentBuilder.addNeedsArtifactType(PARENT_ARTIFACT_TYPE) @@ -193,7 +191,7 @@ void testTwoLevelsWithThreeLevelCycle() throws IOException // [utest->dsn~tracing.link-cycle~1] @Test - void testTwoLevelsWithThreeLevelCycleAndWrongCoverageInLevelThree() throws IOException + void testTwoLevelsWithThreeLevelCycleAndWrongCoverageInLevelThree() { final Trace trace = traceItems( // this.grandParentBuilder.addNeedsArtifactType(PARENT_ARTIFACT_TYPE) diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/cli/commands/TestConvertCommand.java b/core/src/test/java/org/itsallcode/openfasttrace/core/cli/commands/TestConvertCommand.java index 17e0b6bcf..6bee41add 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/cli/commands/TestConvertCommand.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/cli/commands/TestConvertCommand.java @@ -25,8 +25,7 @@ void testRun() final CliArguments args = new CliArguments(directoryServiceMock); args.setUnnamedValues(asList("convert", "input")); final ConvertCommand command = new ConvertCommand(args); - final ExporterException exception = assertThrows(ExporterException.class, - () -> command.run()); + final ExporterException exception = assertThrows(ExporterException.class, command::run); assertThat(exception.getMessage(), equalTo("Found no matching exporter for output format 'specobject'")); } diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/importer/input/TestStreamInput.java b/core/src/test/java/org/itsallcode/openfasttrace/core/importer/input/TestStreamInput.java index 8241c72ff..8e9fa29af 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/importer/input/TestStreamInput.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/importer/input/TestStreamInput.java @@ -20,7 +20,7 @@ class TestStreamInput private static final String CONTENT = "file content 1\nabcöäüßÖÄÜ!\"§$%&/()=?`´'#+*~-_,.;:<>|^°"; @Test - void testRelativeFileGetPath() throws IOException + void testRelativeFileGetPath() { final Path path = Paths.get("blah"); final InputFile inputFile = StreamInput.forReader(path, null); @@ -29,7 +29,7 @@ void testRelativeFileGetPath() throws IOException } @Test - void testAbsoluteFileGetPath() throws IOException + void testAbsoluteFileGetPath() { final Path path = Paths.get("blah").toAbsolutePath(); final InputFile inputFile = StreamInput.forReader(path, null); @@ -38,15 +38,15 @@ void testAbsoluteFileGetPath() throws IOException } @Test - void testToPathUnsupported() throws IOException + void testToPathUnsupported() { final Path path = Paths.get("blah"); final InputFile input = StreamInput.forReader(path, null); - assertThrows(UnsupportedOperationException.class, () -> input.toPath()); + assertThrows(UnsupportedOperationException.class, input::toPath); } @Test - void testIsRealFileFalse() throws IOException + void testIsRealFileFalse() { final InputFile inputFile = StreamInput.forReader(Paths.get("blah"), null); assertThat(inputFile.isRealFile(), equalTo(false)); @@ -62,6 +62,8 @@ void testReadContent() throws IOException private String readContent(final InputFile inputFile) throws IOException { - return inputFile.createReader().lines().collect(joining("\n")); + try(final BufferedReader reader = inputFile.createReader()) { + return reader.lines().collect(joining("\n")); + } } } diff --git a/core/src/test/java/org/itsallcode/openfasttrace/core/matcher/SpecificationItemIdMatcher.java b/core/src/test/java/org/itsallcode/openfasttrace/core/matcher/SpecificationItemIdMatcher.java index a33cf0c9c..e3e9fbf8f 100644 --- a/core/src/test/java/org/itsallcode/openfasttrace/core/matcher/SpecificationItemIdMatcher.java +++ b/core/src/test/java/org/itsallcode/openfasttrace/core/matcher/SpecificationItemIdMatcher.java @@ -31,7 +31,7 @@ private SpecificationItemIdMatcher(final SpecificationItemId expected) * * @param id * the expected id. - * @return a id matcher. + * @return an ID matcher. */ public static Matcher equalTo(final SpecificationItemId id) { @@ -43,8 +43,8 @@ public static Matcher equalTo(final SpecificationItemId id) * {@link SpecificationItemId}s in any order. * * @param expected - * the expected ids. - * @return a id matcher. + * the expected IDs. + * @return an ID matcher. */ public static Matcher> equalIds( final Collection expected) @@ -54,7 +54,7 @@ public static Matcher> equalIds( return IsEmptyIterable.emptyIterable(); } final List> matchers = expected.stream() - .map(SpecificationItemIdMatcher::equalTo) // + .map(SpecificationItemIdMatcher::equalTo) .collect(Collectors.toList()); return IsIterableContainingInAnyOrder.containsInAnyOrder(matchers); } diff --git a/doc/changes/changes.md b/doc/changes/changes.md index de1a438c1..e12760c6d 100644 --- a/doc/changes/changes.md +++ b/doc/changes/changes.md @@ -1,6 +1,7 @@ # Changes -* [4.6.0](changes_4.5.0.md)* [4.6.0](changes_4.5.0.md) +* [4.6.0](changes_4.6.0.md) +* [4.5.0](changes_4.5.0.md) * [4.4.0](changes_4.4.0.md) * [4.3.0](changes_4.3.0.md) * [4.2.3](changes_4.2.3.md) diff --git a/exporter/common/src/test/java/org/itsallcode/openfasttrace/exporter/common/TestIndentingXMLStreamWriter.java b/exporter/common/src/test/java/org/itsallcode/openfasttrace/exporter/common/TestIndentingXMLStreamWriter.java index 916c3ce01..0969fcaad 100644 --- a/exporter/common/src/test/java/org/itsallcode/openfasttrace/exporter/common/TestIndentingXMLStreamWriter.java +++ b/exporter/common/src/test/java/org/itsallcode/openfasttrace/exporter/common/TestIndentingXMLStreamWriter.java @@ -148,7 +148,6 @@ void testWriteEndElementDepthGreaterThanZero() throws XMLStreamException delegateInOrder.verify(delegateMock).writeCharacters(" "); delegateInOrder.verify(delegateMock).writeEmptyElement(LOCAL_NAME); delegateInOrder.verify(delegateMock).writeCharacters("\n"); - // delegateInOrder.verify(delegateMock).writeCharacters(" "); delegateInOrder.verify(delegateMock).writeEndElement(); delegateInOrder.verifyNoMoreInteractions(); } diff --git a/exporter/specobject/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java b/exporter/specobject/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java index 17505358b..693b808a8 100644 --- a/exporter/specobject/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java +++ b/exporter/specobject/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExporter.java @@ -1,6 +1,6 @@ package org.itsallcode.openfasttrace.exporter.specobject; -import static java.util.Arrays.asList; +import static java.util.Arrays.stream; import static org.hamcrest.MatcherAssert.assertThat; import static org.itsallcode.openfasttrace.testutil.matcher.MultilineTextMatcher.matchesAllLines; import static org.itsallcode.openfasttrace.testutil.core.ItemBuilderFactory.item; @@ -22,29 +22,31 @@ class TestSpecobjectExporter { // [itest->dsn~conversion.reqm2-export~1] @Test - void testExportSimpleSpecObjectWithMandatoryElements() throws IOException, XMLStreamException + void testExportSimpleSpecObjectWithMandatoryElements() { final SpecificationItem item = item() // .id(SpecificationItemId.createId("foo", "bar", 1)) // .description("the description") // .build(); - final String expected = "\n" // - + "\n" // - + " \n" // - + " \n" // - + " bar\n" // - + " approved\n" // - + " 1\n" // - + " the description\n" // - + " \n" // - + " \n" // - + "\n"; + final String expected = """ + + + + + bar + approved + 1 + the description + + + + """; final String actual = exportToString(item); assertThat(actual, matchesAllLines(expected)); } @Test - void testExportSpecObjectWithOptionalElements() throws IOException, XMLStreamException + void testExportSpecObjectWithOptionalElements() { final SpecificationItem item = item() // .id(SpecificationItemId.createId("req", "me", 2)) // @@ -59,43 +61,45 @@ void testExportSpecObjectWithOptionalElements() throws IOException, XMLStreamExc .addTag("the tag") // .location("/the/file", 1024) // .build(); - final String expected = "\n" // - + "\n" // - + " \n" // - + " \n" // - + " me\n" // - + " My item title\n" // - + " draft\n" // - + " 2\n" // - + " /the/file\n" // - + " 1024\n" // " - + " the description\n" // - + " the rationale\n" // - + " the comment\n" // - + " \n" // - + " the tag\n" // - + " \n" // - + " \n" // - + " impl\n" // - + " \n" // - + " \n" // - + " \n" // - + " feat:covered\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " \n" // - + " req~depend-on~1\n" // - + " \n" // - + " \n" // - + " \n" // - + "\n"; + final String expected = """ + + + + + me + My item title + draft + 2 + /the/file + 1024 + the description + the rationale + the comment + + the tag + + + impl + + + + feat:covered + 1 + + + + req~depend-on~1 + + + + + """; final String actual = exportToString(item); assertThat(actual, matchesAllLines(expected)); } @Test - void testExportTwoSpecObjects() throws IOException, XMLStreamException + void testExportTwoSpecObjects() { final SpecificationItem itemA = item() // .id(SpecificationItemId.createId("foo", "bar", 1)) // @@ -111,29 +115,34 @@ void testExportTwoSpecObjects() throws IOException, XMLStreamException .rationale("another\nrationale") // .comment("another\ncomment") // .build(); - final String expected = "\n" // - + "\n" // - + " \n" // - + " \n" // - + " bar\n" // - + " proposed\n" // - + " 1\n" // - + " the description\n" // - + " the rationale\n" // - + " the comment\n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " zoo\n" // - + " rejected\n" // - + " 2\n" // - + " another\ndescription\n" // - + " another\nrationale\n" // - + " another\ncomment\n" // - + " \n" // - + " \n" // - + "\n"; + final String expected = """ + + + + + bar + proposed + 1 + the description + the rationale + the comment + + + + + zoo + rejected + 2 + another + description + another + rationale + another + comment + + + + """; final String actual = exportToString(itemA, itemB); assertThat(actual, matchesAllLines(expected)); } @@ -158,10 +167,10 @@ private String exportToString(final SpecificationItem... items) final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); final XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(stream, StandardCharsets.UTF_8.name()); - new SpecobjectExporter(asList(items).stream(), + new SpecobjectExporter(stream(items), new IndentingXMLStreamWriter(xmlWriter, " ", Newline.UNIX.toString()), new OutputStreamWriter(stream), Newline.UNIX).runExport(); - return new String(stream.toByteArray(), StandardCharsets.UTF_8); + return stream.toString(StandardCharsets.UTF_8); } catch (IOException | XMLStreamException | FactoryConfigurationError e) { diff --git a/importer/specobject/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java b/importer/specobject/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java index 6c981911a..d3b0ad263 100644 --- a/importer/specobject/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java +++ b/importer/specobject/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImporter.java @@ -28,12 +28,13 @@ class TestSpecobjectImporter @Test void testImportOfMinimalSpecObject() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " minimal\n" // - + " 1\n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + minimal + 1 + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~minimal~1")); @@ -56,20 +57,21 @@ private ImportEventListener importFromString(final String text) @Test void testImportOfComplexSpecObject() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " complex\n" // - + " draft" // - + " 2\n" // - + " my short description\n" // - + " multiline description\n" // - + "one more line\n" // - + " multiline rationale\n" // - + "and another line" // - + " multiline comment\n" // - + "yet another line\n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + complex + draft\ + 2 + my short description + multiline description + one more line + multiline rationale + and another line\ + multiline comment + yet another line + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setStatus(ItemStatus.DRAFT); @@ -85,13 +87,14 @@ void testImportOfComplexSpecObject() @Test void testImportOnlyShortDescription() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " complex\n" // - + " 2\n" // - + " My item title\n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + complex + 2 + My item title + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~complex~2")); @@ -103,14 +106,15 @@ void testImportOnlyShortDescription() @Test void testSelectedElementsAreIgnoredDuringImport() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " ignore-selected-xml-elements\n" // - + " 12345\n" // - + " 1970-01-01\n" - + " john doe\n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + ignore-selected-xml-elements + 12345 + 1970-01-01 + john doe + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock) @@ -122,12 +126,13 @@ void testSelectedElementsAreIgnoredDuringImport() @Test void testStripSuperfluousArtifactPrefixFromName() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " impl:strip_duplicate_prefix\n" // - + " 0\n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + impl:strip_duplicate_prefix + 0 + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("impl~strip_duplicate_prefix~0")); @@ -140,8 +145,7 @@ void testTakeOverLocationFromImportedFile() { final String expectedFileName = "/home/johndoe/openfasttrace/examples/specobject.xml"; final int expectedLine = 42; - final ImportEventListener listenerMock = importFromString( - "\n" // + final ImportEventListener listenerMock = importFromString("\n" // + " \n" // + " takeOverLocation\n" // + " 99999999\n" // @@ -159,17 +163,17 @@ void testTakeOverLocationFromImportedFile() @Test void testImportWithTags() { - final ImportEventListener listenerMock = importFromString( - "\n" // - + " \n" // - + " with-tags\n" // - + " 1\n" // - + " \n" // - + " tag 1\n" // - + " tag 2\n" // - + " \n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + with-tags + 1 + + tag 1 + tag 2 + + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("itest~with-tags~1")); @@ -182,16 +186,17 @@ void testImportWithTags() @Test void testImportWithNeedsCoverage() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " with-needs-coverage\n" // - + " 1\n" // - + " \n" // - + " impl\n" // - + " utest\n" // - + " \n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + with-needs-coverage + 1 + + impl + utest + + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~with-needs-coverage~1")); @@ -204,16 +209,17 @@ void testImportWithNeedsCoverage() @Test void testImportWithDependencies() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " with-dependencies\n" // - + " 1\n" // - + " \n" // - + " req:dep-a, v1\n" // - + " req:dep-b, v2\n" // - + " \n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + with-dependencies + 1 + + req:dep-a, v1 + req:dep-b, v2 + + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~with-dependencies~1")); @@ -226,24 +232,25 @@ void testImportWithDependencies() @Test void testImportFulfilledByIsIgnored() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " with-fulfilled-by\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " impl\n" // - + " ffb-a\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " utest\n" // - + " ffb-b\n" // - + " 2\n" // - + " \n" // - + " \n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + with-fulfilled-by + 1 + + + impl + ffb-a + 1 + + + utest + ffb-b + 2 + + + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~with-fulfilled-by~1")); @@ -254,22 +261,23 @@ void testImportFulfilledByIsIgnored() @Test void testImportProvidesCoverage() { - final ImportEventListener listenerMock = importFromString("\n" // - + " \n" // - + " with-fulfilled-by\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " feat:provides-a\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " feat:provides-b\n" // - + " 2\n" // - + " \n" // - + " \n" // - + " \n" // - + ""); + final ImportEventListener listenerMock = importFromString(""" + + + with-fulfilled-by + 1 + + + feat:provides-a + 1 + + + feat:provides-b + 2 + + + + """); verify(listenerMock).beginSpecificationItem(); verify(listenerMock).setLocation(STANDARD_LOCATION); verify(listenerMock).setId(SpecificationItemId.parseId("req~with-fulfilled-by~1")); @@ -284,19 +292,19 @@ void testCustomTagsWithoutNamespacesLogsWarning() { try( final RecordingLogHandler logHandler = new RecordingLogHandler() ) { - importFromString( - "" // - + " \n" // - + " \n" // - + " minimal\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + ""); + importFromString(""" + \ + + + minimal + 1 + + + + + """); final Optional firstRecord = logHandler.getLogRecords() - .filter((logRecord) -> logRecord.getLevel() == Level.WARNING) + .filter(logRecord -> logRecord.getLevel() == Level.WARNING) .findFirst(); assertTrue(firstRecord.isPresent()); assertThat(firstRecord.get().getMessage(), containsString("Found unknown")); @@ -308,19 +316,19 @@ void testCustomTagsWithNamespacesLogsNoWarning() { try( final RecordingLogHandler logHandler = new RecordingLogHandler() ) { - importFromString( - "" // - + " \n" // - + " \n" // - + " minimal\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + ""); + importFromString(""" + + + + minimal + 1 + + + + + + + """); assertThat(logHandler.getLogRecords().count(), equalTo(0L)); } } @@ -330,18 +338,18 @@ void testCustomTagsWithNamespacesPlusOftNamespaceLogsNoWarning() { try( final RecordingLogHandler logHandler = new RecordingLogHandler() ) { - importFromString( - "" // - + " \n" // - + " \n" // - + " minimal\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + ""); + importFromString(""" + + + + minimal + 1 + + + + + """); assertThat(logHandler.getLogRecords().count(), equalTo(0L)); } } @@ -360,10 +368,10 @@ public RecordingLogHandler() rootLogger.addHandler(this); } - @Override public void publish(final LogRecord record) + @Override public void publish(final LogRecord logRecord) { - logRecords.add(record); - super.publish(record); + logRecords.add(logRecord); + super.publish(logRecord); } public Stream getLogRecords() @@ -374,8 +382,8 @@ public Stream getLogRecords() @Override public void close() { Arrays.stream(rootLogger.getHandlers()) - .filter((handler -> handler instanceof RecordingLogHandler)) - .forEach(handler -> rootLogger.removeHandler(handler) ); + .filter((RecordingLogHandler.class::isInstance)) + .forEach(rootLogger::removeHandler); super.close(); } } diff --git a/importer/tag/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java b/importer/tag/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java index 270bbda04..6c920d83b 100644 --- a/importer/tag/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java +++ b/importer/tag/src/test/java/org/itsallcode/openfasttrace/importer/tag/TestTagImporterFactoryWithConfig.java @@ -8,7 +8,6 @@ import static org.mockito.Mockito.when; import java.io.File; -import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; @@ -78,7 +77,7 @@ void testFactoryForUnsupportedFileThrowsException() } @Test - void testFactoryCreatesImporterForSupportedFile(@TempDir final Path tempDir) throws IOException + void testFactoryCreatesImporterForSupportedFile(@TempDir final Path tempDir) { final File tempFile = tempDir.resolve("test").toFile(); final String glob = tempFile.getAbsolutePath().replace('\\', '/'); @@ -87,7 +86,7 @@ void testFactoryCreatesImporterForSupportedFile(@TempDir final Path tempDir) thr } @Test - void testFactoryForMissingFileThrowsException() throws IOException + void testFactoryForMissingFileThrowsException() { final Importer importer = createImporter(configure(glob(PATH1)), Paths.get(PATH1)); assertThrows(ImporterException.class, importer::runImport); @@ -121,10 +120,10 @@ private TagImporterFactory create(final ImportSettings settings) private PathConfig glob(final String globPattern) { - return PathConfig.builder() // - .patternPathMatcher("glob:" + globPattern) // - .coveredItemArtifactType("") // - .tagArtifactType("") // + return PathConfig.builder() + .patternPathMatcher("glob:" + globPattern) + .coveredItemArtifactType("") + .tagArtifactType("") .build(); } } diff --git a/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/ContentHandlerAdapterTest.java b/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/ContentHandlerAdapterTest.java index e63403699..00e66a342 100644 --- a/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/ContentHandlerAdapterTest.java +++ b/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/ContentHandlerAdapterTest.java @@ -52,7 +52,7 @@ void testSetDocumentLocatorFailsForNullValue() } @Test - void testStartElementFailsForMissingLocator() throws SAXException + void testStartElementFailsForMissingLocator() { final ContentHandlerAdapter testee = testee(); final IllegalStateException exception = assertThrows(IllegalStateException.class, @@ -77,7 +77,7 @@ void testStartElementCallsDelegate() throws SAXException } @Test - void testEndElementFailsForMissingLocator() throws SAXException + void testEndElementFailsForMissingLocator() { final ContentHandlerAdapter testee = testee(); final IllegalStateException exception = assertThrows(IllegalStateException.class, diff --git a/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/XmlParserTest.java b/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/XmlParserTest.java index a4917806b..90e455bc6 100644 --- a/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/XmlParserTest.java +++ b/importer/xmlparser/src/test/java/org/itsallcode/openfasttrace/importer/xmlparser/XmlParserTest.java @@ -24,7 +24,7 @@ class XmlParserTest { @Test - void testParsingSucceeds(@Mock final TreeContentHandler handlerMock) throws IOException + void testParsingSucceeds(@Mock final TreeContentHandler handlerMock) { final XmlParser parser = testee(); parser.parse("path", new StringReader(""), handlerMock); @@ -32,17 +32,19 @@ void testParsingSucceeds(@Mock final TreeContentHandler handlerMock) throws IOEx } @Test - void testParsingInvalidXmlFormatFails(@Mock final TreeContentHandler handlerMock) throws IOException + void testParsingInvalidXmlFormatFails(@Mock final TreeContentHandler handlerMock) { final XmlParser parser = testee(); final StringReader reader = new StringReader("invalidContent"); final XmlParserException exception = assertThrows(XmlParserException.class, () -> parser.parse("path", reader, handlerMock)); - assertThat(exception.getMessage(), equalTo("Failed to parse file 'path': Content is not allowed in prolog.")); + assertThat(exception.getMessage(), + equalTo("Failed to parse file 'path': Content is not allowed in prolog.")); } @Test - void testParsingFails(@Mock final Reader readerMock, @Mock final TreeContentHandler handlerMock) throws IOException + void testParsingFails(@Mock final Reader readerMock, @Mock final TreeContentHandler handlerMock) + throws IOException { final XmlParser parser = testee(); when(readerMock.read(any(), anyInt(), anyInt())).thenThrow(new IOException("expected")); diff --git a/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java b/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java index 2fe3dfebd..d2744adee 100644 --- a/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java +++ b/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/ITZipFileImporter.java @@ -78,8 +78,7 @@ void testImportNonPhysicalFile() final InputFile file = StreamInput.forReader(this.zipFile.toPath(), new BufferedReader(new StringReader(""))); final ZipFileImporter importer = new ZipFileImporter(file, this.delegateImporterMock); - assertThrows(UnsupportedOperationException.class, - () -> importer.runImport()); + assertThrows(UnsupportedOperationException.class, importer::runImport); } @Test diff --git a/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/input/TestZipEntryInput.java b/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/input/TestZipEntryInput.java index 33fed0ec7..ffff9e4e0 100644 --- a/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/input/TestZipEntryInput.java +++ b/importer/zip/src/test/java/org/itsallcode/openfasttrace/importer/zip/input/TestZipEntryInput.java @@ -55,8 +55,7 @@ void testToPathUnsupportedThrowsException() throws IOException try (final ZipFile zip = getZipFile()) { final InputFile input = ZipEntryInput.forZipEntry(zip, new ZipEntry("file")); - assertThrows(UnsupportedOperationException.class, - () -> input.toPath()); + assertThrows(UnsupportedOperationException.class, input::toPath); } } @@ -128,7 +127,9 @@ void testReadInvalidEncoding() throws IOException private String readContent(final InputFile inputFile) throws IOException { - return inputFile.createReader().lines().collect(joining("\n")); + try(final BufferedReader reader = inputFile.createReader()) { + return reader.lines().collect(joining("\n")); + } } private void addEntryToZip(final String entryName, final byte[] data) throws IOException diff --git a/product/src/test/java/org/itsallcode/openfasttrace/ITestSelfTrace.java b/product/src/test/java/org/itsallcode/openfasttrace/ITestSelfTrace.java index a3d3938dd..bc29c24b8 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/ITestSelfTrace.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/ITestSelfTrace.java @@ -44,15 +44,24 @@ private void assertSelfTraceClean(final Trace trace) protected String createSelfTraceReport(final Trace trace) { - String message = "Self trace has " + trace.countDefects() + " / " + trace.count() - + " defect items.\n\n"; + final StringBuilder messageBuilder = new StringBuilder(); + messageBuilder.append("Self trace has ") + .append(trace.countDefects()) + .append(" / ") + .append(trace.count()) + .append(" defects.\n\n"); for (final LinkedSpecificationItem item : trace.getDefectItems()) { final Location location = item.getLocation(); - message += "at " + item.getId() + " (" + location.getPath() + ":" + location.getLine() - + ")\n"; + messageBuilder.append("at ") + .append(item.getId()) + .append(" (") + .append(location.getPath()) + .append(":") + .append(location.getLine()) + .append(")\n"); } - return message; + return messageBuilder.toString(); } private ImportSettings buildOftSettings() @@ -73,11 +82,11 @@ private List findInputDirectories(final Path rootProjectDir) { try (final Stream stream = Files.walk(rootProjectDir.normalize(), 5)) { - return stream // - .filter(containsDir("bin").negate()) // - .filter(path -> Files.isDirectory(path)) // - .filter(endsWith(Paths.get("src/main")) // - .or(endsWith(Paths.get("src/test/java")))) // + return stream + .filter(containsDir("bin").negate()) + .filter(Files::isDirectory) + .filter(endsWith(Paths.get("src/main")) + .or(endsWith(Paths.get("src/test/java")))) .toList(); } catch (final IOException e) diff --git a/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/ServiceLoaderFactoryIT.java b/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/ServiceLoaderFactoryIT.java index 5ab223eba..8de5e2bca 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/ServiceLoaderFactoryIT.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/ServiceLoaderFactoryIT.java @@ -56,7 +56,7 @@ void loadServiceFromJar() throws IOException final ReporterFactory service = services.get(0); final ClassLoader pluginClassLoader = service.getClass().getClassLoader(); assertAll( - () -> assertThat(service.getClass().getName().toString(), + () -> assertThat(service.getClass().getName(), equalTo("org.itsallcode.openfasttrace.report.plaintext.PlaintextReporterFactory")), () -> assertThat(pluginClassLoader.getName(), startsWith("JarClassLoader-openfasttrace-reporter-plaintext")), diff --git a/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java b/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java index 63f898393..3144600ae 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/core/serviceloader/TestInitializingServiceLoader.java @@ -105,6 +105,7 @@ class InitializableServiceStub implements Initializable @Override public void init(final Object context) { + // Intentionally empty. } } } diff --git a/product/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExportImport.java b/product/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExportImport.java index d9a27a437..ba81a5a96 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExportImport.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/exporter/specobject/TestSpecobjectExportImport.java @@ -23,7 +23,6 @@ class TestSpecobjectExportImport { @Test void testExportImportSimpleSpecObjectWithMandatoryElements() - throws IOException, XMLStreamException { final SpecificationItem item = SpecificationItem.builder() // .id(SpecificationItemId.createId("foo", "bar", 1)) // @@ -34,7 +33,7 @@ void testExportImportSimpleSpecObjectWithMandatoryElements() } @Test - void testExportImportSpecObjectWithOptionalElements() throws IOException, XMLStreamException + void testExportImportSpecObjectWithOptionalElements() { final SpecificationItem item = SpecificationItem.builder() // .id(SpecificationItemId.createId("req", "me", 2)) // @@ -53,7 +52,7 @@ void testExportImportSpecObjectWithOptionalElements() throws IOException, XMLStr } @Test - void testExportImportTwoSpecObjects() throws IOException, XMLStreamException + void testExportImportTwoSpecObjects() { final SpecificationItem itemA = SpecificationItem.builder() // .id(SpecificationItemId.createId("foo", "bar", 1)) // diff --git a/product/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java b/product/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java index 1dcac7a24..f22f411f0 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/importer/specobject/TestSpecobjectImportExport.java @@ -24,38 +24,39 @@ class TestSpecobjectImportExport @Test void testTraceContent() { - final String content = "\n" // - + "\n" // - + " \n" // - + " \n" // - + " exampleB-3454416016\n" - + " approved\n" // - + " 0\n" // - + " source.java\n" // - + " 1\n" // - + " \n" // - + " \n" // - + " dsn:exampleB\n" - + " 1\n" - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " \n" // - + " exampleB\n" // - + " approved\n" // - + " 1\n" - + " spec.md\n" - + " 2\n" - + " Example requirement\n" - + " \n" // - + " utest\n" - + " impl\n" // - + " \n" // - + " \n" // - + " \n" // - + ""; + final String content = """ + + + + + exampleB-3454416016 + approved + 0 + source.java + 1 + + + dsn:exampleB + 1 + + + + + + + exampleB + approved + 1 + spec.md + 2 + Example requirement + + utest + impl + + + + """; final Trace trace = trace(content); final SpecificationItemId dsnId = SpecificationItemId.createId("dsn", "exampleB", 1); diff --git a/product/src/test/java/org/itsallcode/openfasttrace/mode/AbstractOftTest.java b/product/src/test/java/org/itsallcode/openfasttrace/mode/AbstractOftTest.java index f76e7fdfa..979ca8058 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/mode/AbstractOftTest.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/mode/AbstractOftTest.java @@ -20,7 +20,7 @@ abstract class AbstractOftTest protected final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); protected final ByteArrayOutputStream error = new ByteArrayOutputStream(); - protected void prepareOutput(final Path outputDir) throws UnsupportedEncodingException + protected void prepareOutput(final Path outputDir) { this.docDir = Paths.get("../core/src/test/resources/markdown").toAbsolutePath(); this.outputFile = outputDir.resolve("stream.txt"); diff --git a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsConverter.java b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsConverter.java index c63e7ab85..f76911773 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsConverter.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsConverter.java @@ -1,7 +1,6 @@ package org.itsallcode.openfasttrace.mode; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.nio.file.Path; import java.util.List; @@ -18,7 +17,7 @@ class ITestOftAsConverter extends AbstractOftTest private Oft oft; @BeforeEach - void beforeEach(@TempDir final Path tempDir) throws UnsupportedEncodingException + void beforeEach(@TempDir final Path tempDir) { prepareOutput(tempDir); this.oft = Oft.create(); diff --git a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java index 6010a2a72..758166ca9 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestOftAsReporter.java @@ -5,7 +5,6 @@ import static org.hamcrest.Matchers.greaterThan; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -24,17 +23,16 @@ class ITestOftAsReporter extends AbstractOftTest { private Oft oft; private Trace trace; - private List linkedItems; @BeforeEach - void beforeEach(@TempDir final Path tempDir) throws UnsupportedEncodingException + void beforeEach(@TempDir final Path tempDir) { prepareOutput(tempDir); final ImportSettings settings = ImportSettings.builder().addInputs(this.docDir).build(); this.oft = Oft.create(); final List items = this.oft.importItems(settings); - this.linkedItems = this.oft.link(items); - this.trace = this.oft.trace(this.linkedItems); + final List linkedItems = this.oft.link(items); + this.trace = this.oft.trace(linkedItems); } @Test @@ -75,13 +73,13 @@ void testTraceMacNewlines() throws IOException } @Test - void testTraceToStdOut() throws IOException + void testTraceToStdOut() { this.oft.reportToStdOut(this.trace); assertStandardReportStdOutResult(); } - private void assertStandardReportStdOutResult() throws IOException + private void assertStandardReportStdOutResult() { assertStdOutStartsWith("ok - 5 total"); } @@ -107,8 +105,7 @@ private Trace traceWithFilters(final FilterSettings filterSettings) final List filteredItems = this.oft.importItems(importSettings); final List filteredSpecificationItems = this.oft .link(filteredItems); - final Trace filteredTrace = this.oft.trace(filteredSpecificationItems); - return filteredTrace; + return this.oft.trace(filteredSpecificationItems); } private long countItemsOfArtifactTypeInTrace(final String artifactType, final Trace trace) diff --git a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java index 306e93ea6..0ba648b4e 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/mode/ITestReporterWithFilter.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.nio.file.Path; import java.util.*; -import java.util.stream.Collectors; import org.itsallcode.openfasttrace.api.FilterSettings; import org.itsallcode.openfasttrace.api.core.*; @@ -60,18 +59,17 @@ void testFilterWithAtLeastOneMatchingTag() private List getIdsFromTraceWithFilterSettings(final FilterSettings filterSettings) { - final ImportSettings importSettings = ImportSettings.builder() // - .addInputs(this.tempDir) // - .filter(filterSettings) // + final ImportSettings importSettings = ImportSettings.builder() + .addInputs(this.tempDir) + .filter(filterSettings) .build(); final List items = this.oft.importItems(importSettings); final List linkedItems = this.oft.link(items); final Trace trace = this.oft.trace(linkedItems); - final List filteredIds = trace.getItems() // - .stream() // - .map(item -> item.getId().toString()) // - .collect(Collectors.toList()); - return filteredIds; + return trace.getItems() + .stream() + .map(item -> item.getId().toString()) + .toList(); } // [itest->dsn~filtering-by-tags-or-no-tags-during-import~1] diff --git a/product/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java b/product/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java index d91452257..79967154e 100644 --- a/product/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java +++ b/product/src/test/java/org/itsallcode/openfasttrace/report/TestReportService.java @@ -105,7 +105,7 @@ private Path createReadOnlyFile(final Path tempDir) throws IOException return readOnlyFilePath; } - private void makeFileReadOnly(final Path readOnlyFilePath) throws IOException + private void makeFileReadOnly(final Path readOnlyFilePath) { readOnlyFilePath.toFile().setReadOnly(); } diff --git a/product/src/test/resources/example/src/test.java b/product/src/test/resources/example/src/test.java index f3282ec10..b1e11733a 100644 --- a/product/src/test/resources/example/src/test.java +++ b/product/src/test/resources/example/src/test.java @@ -1 +1,2 @@ +@SuppressWarnings("java:S1220") // This is only a test file. No need for package. // [src->req~java-source~1] diff --git a/reporter/aspec/src/test/java/org/itsallcode/openfasttrace/report/aspec/TestASpecReport.java b/reporter/aspec/src/test/java/org/itsallcode/openfasttrace/report/aspec/TestASpecReport.java index 3cad343bb..b4e2fdc8e 100644 --- a/reporter/aspec/src/test/java/org/itsallcode/openfasttrace/report/aspec/TestASpecReport.java +++ b/reporter/aspec/src/test/java/org/itsallcode/openfasttrace/report/aspec/TestASpecReport.java @@ -8,7 +8,6 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.util.*; -import java.util.stream.Collectors; import org.hamcrest.Matcher; import org.itsallcode.openfasttrace.api.ReportSettings; @@ -464,14 +463,14 @@ private Trace getTrace() builder.items(items); builder.defectItems(items.stream() // .filter(LinkedSpecificationItem::isDefect) // - .collect(Collectors.toList())); + .toList()); return builder.build(); } private String item(final Field... fields) { final StringBuilder result = new StringBuilder(); - final Map> fieldMap = new HashMap<>(); + final Map> fieldMap = new EnumMap<>(Field.Type.class); for (final Field field : fields) { final List value = fieldMap.containsKey(field.type) ? fieldMap.get(field.type) : new ArrayList<>(); diff --git a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/HtmlReport.java b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/HtmlReport.java index a57d4580d..3b09e55cd 100644 --- a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/HtmlReport.java +++ b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/HtmlReport.java @@ -2,7 +2,6 @@ import java.io.OutputStream; import java.net.URL; -import java.util.Comparator; import java.util.List; import org.itsallcode.openfasttrace.api.ReportSettings; @@ -12,6 +11,8 @@ import org.itsallcode.openfasttrace.report.html.view.*; import org.itsallcode.openfasttrace.report.html.view.html.HtmlViewFactory; +import static java.util.Comparator.comparing; + /** * An HTML report. */ @@ -69,10 +70,11 @@ private ViewableContainer createDetails(final ViewFactory factory) private List getSortedItems() { - final List items = this.trace.getItems(); - items.sort(Comparator.comparing(LinkedSpecificationItem::getArtifactType) - .thenComparing(LinkedSpecificationItem::getTitleWithFallback)); - return items; + return this.trace.getItems() + .stream() + .sorted(comparing(LinkedSpecificationItem::getArtifactType) + .thenComparing(LinkedSpecificationItem::getTitleWithFallback)) + .toList(); } private void addSectionedItems(final ViewFactory factory, final ViewableContainer view, diff --git a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlSpecificationItem.java b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlSpecificationItem.java index fb597dd23..52cb4f85d 100644 --- a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlSpecificationItem.java +++ b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlSpecificationItem.java @@ -209,9 +209,9 @@ protected void renderLinkForDirection(final String indentation, final boolean in protected List sortLinkStreamById(final Stream tracedLinkStream) { - return tracedLinkStream // - .sorted(Comparator.comparing(a -> a.getOtherLinkEnd().getId().toString())) // - .collect(Collectors.toList()); + return tracedLinkStream + .sorted(Comparator.comparing(a -> a.getOtherLinkEnd().getId().toString())) + .toList(); } protected void renderLinkEntry(final List outLinks, final String indentation) diff --git a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlViewFactory.java b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlViewFactory.java index b2058221c..7b6cf606a 100644 --- a/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlViewFactory.java +++ b/reporter/html/src/main/java/org/itsallcode/openfasttrace/report/html/view/html/HtmlViewFactory.java @@ -47,9 +47,9 @@ public static HtmlViewFactory create(final OutputStream stream, final URL cssURL private static PrintStream createPrintStream(final OutputStream stream) { - if (stream instanceof PrintStream) + if (stream instanceof PrintStream printStream) { - return (PrintStream) stream; + return printStream; } else { diff --git a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java index fb6e69fad..b6f096e14 100644 --- a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java +++ b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/TestHtmlReport.java @@ -42,20 +42,19 @@ protected String renderToString() htmlReporterFactory.init(new ReporterContext(ReportSettings.createDefault())); final Reportable report = htmlReporterFactory.createImporter(traceMock); report.renderToStream(outputStream); - final String outputAsString = outputStream.toString(); - return outputAsString; + return outputStream.toString(); } @Test void testRenderSimpleTrace() { final LinkedSpecificationItem itemA = new LinkedSpecificationItem( - itemWithId(SpecificationItemId.createId("a", "a-item", 1)) // - .description("Description A") // + itemWithId(SpecificationItemId.createId("a", "a-item", 1)) + .description("Description A") .build()); final LinkedSpecificationItem itemB = new LinkedSpecificationItem( - itemWithId(SpecificationItemId.createId("b", "b-item", 1)) // - .description("Description b") // + itemWithId(SpecificationItemId.createId("b", "b-item", 1)) + .description("Description b") .build()); when(this.traceMock.getItems()).thenReturn(Arrays.asList(itemA, itemB)); when(this.traceMock.count()).thenReturn(2); diff --git a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/TestAbstractViewableContainer.java b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/TestAbstractViewableContainer.java index 48edb9a3c..7be97caac 100644 --- a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/TestAbstractViewableContainer.java +++ b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/TestAbstractViewableContainer.java @@ -24,7 +24,7 @@ class TestAbstractViewableContainer private Viewable viewMockB; @BeforeEach - public void prepareEachTest() + void prepareEachTest() { this.viewableContainer = new ViewContainerStub(); } @@ -97,11 +97,13 @@ public ViewContainerStub(final String id, final String title) @Override protected void renderBeforeChildren(final int level) { + // Stub class. Method is not needed. } @Override protected void renderAfterChildren(final int level) { + // Stub class. Method is not needed. } } } \ No newline at end of file diff --git a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestHtmlViewFactory.java b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestHtmlViewFactory.java index 154a12e15..928510678 100644 --- a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestHtmlViewFactory.java +++ b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestHtmlViewFactory.java @@ -30,7 +30,7 @@ void beforeEach() } @Test - void testCreateFactoryWithPrintStream() throws UnsupportedEncodingException + void testCreateFactoryWithPrintStream() { factory = HtmlViewFactory.create(new PrintStream(outputStream, true, StandardCharsets.UTF_8), HtmlReport.getCssUrl(), DetailsSectionDisplay.COLLAPSE); diff --git a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestMarkdownConverter.java b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestMarkdownConverter.java index 1c167bf1b..c63392737 100644 --- a/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestMarkdownConverter.java +++ b/reporter/html/src/test/java/org/itsallcode/openfasttrace/report/html/view/html/TestMarkdownConverter.java @@ -12,7 +12,7 @@ class TestMarkdownConverter private MarkdownConverter converter; @BeforeEach - public void prepareEachTest() + void prepareEachTest() { this.converter = new MarkdownConverter(); } diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/ImportAssertions.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/ImportAssertions.java index 7eec5e4c0..b714f45d6 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/ImportAssertions.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/ImportAssertions.java @@ -60,7 +60,7 @@ public static void assertImportWithFactory(final Path path, final String input, public static List runImporterOnText(final Path path, final String text, final ImporterFactory importerFactory) { - LOGGER.finest("Importing text: ***\n" + text + "\n***"); + LOGGER.finest(() -> "Importing text: ***\n" + text + "\n***"); final BufferedReader reader = new BufferedReader(new StringReader(text)); final InputFile file = StreamInput.forReader(path, reader); final SpecificationListBuilder specItemBuilder = SpecificationListBuilder.create(); diff --git a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java index 586de360d..f5faf8aee 100644 --- a/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java +++ b/testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java @@ -25,6 +25,7 @@ */ public abstract class AbstractLightWeightMarkupImporterTest { + private static final String FILENAME = "the_file.md"; private static final Path PATH = Path.of("/a/b/c.markdown"); private static final String NL = System.lineSeparator(); private static final Pattern TITLE_PLACEHOLDER = Pattern.compile("\\$\\{title\\(\"([^\"]+)\", (\\d+)\\)}"); @@ -152,15 +153,15 @@ void testSpecificationItemCoversList() assertImport(PATH, """ req~covers-list~4 Covers: - * `feat~item-a~1` - * `feat~item-b~2` - * `feat~item-c~3` + * `feat~item-A~1` + * `feat~item-B~2` + * `feat~item-C~3` """, contains(item() .id("req", "covers-list", 4) - .addCoveredId("feat", "item-a", 1) - .addCoveredId("feat", "item-b", 2) - .addCoveredId("feat", "item-c", 3) + .addCoveredId("feat", "item-A", 1) + .addCoveredId("feat", "item-B", 2) + .addCoveredId("feat", "item-C", 3) .location(PATH.toString(), 1) .build())); } @@ -287,7 +288,7 @@ void testArtifactForwardingNotation(final String input, final String forwardedAr @Test void testForwardingAfterDepends() { - assertImport("1.2.md", """ + assertImport(FILENAME, """ dsn~foo~1 Depends: * req~foo~1 @@ -296,14 +297,14 @@ void testForwardingAfterDepends() contains( item() .id("dsn", "foo", 1) - .location("1.2.md", 1) + .location(FILENAME, 1) .addDependOnId("req", "foo", 1) .build(), item() .id("dsn", "bar", 2) .addCoveredId("req", "bar", 2) .addNeedsArtifactType("impl") - .location("1.2.md", 4) + .location(FILENAME, 4) .forwards(true) .build())); } @@ -312,7 +313,7 @@ void testForwardingAfterDepends() @Test void testForwardingAfterTags() { - assertImport("1.2.md", """ + assertImport(FILENAME, """ dsn~foo~1 Tags: vanilla, strawberry, mint dsn-->impl:req~bar~2 @@ -320,7 +321,7 @@ void testForwardingAfterTags() contains( item() .id("dsn", "foo", 1) - .location("1.2.md", 1) + .location(FILENAME, 1) .addTag("vanilla") .addTag("strawberry") .addTag("mint") @@ -329,7 +330,7 @@ void testForwardingAfterTags() .id("dsn", "bar", 2) .addCoveredId("req", "bar", 2) .addNeedsArtifactType("impl") - .location("1.2.md", 3) + .location(FILENAME, 3) .forwards(true) .build())); } @@ -338,7 +339,7 @@ void testForwardingAfterTags() @Test void testMultipleForwardsInARow() { - assertImport("fwd.md", """ + assertImport(FILENAME, """ ${title("A Collection of Different Forwards", 1)} * `arch --> dsn : req~foo~1` * arch -->dsn : req~bar~2 with a comment @@ -349,19 +350,19 @@ void testMultipleForwardsInARow() .id("arch", "foo", 1).addCoveredId("req", "foo", 1) .addNeedsArtifactType("dsn") .forwards(true) - .location("fwd.md", 2 + titleLocationOffset) + .location(FILENAME, 2 + titleLocationOffset) .build(), item() .id("arch", "bar", 2).addCoveredId("req", "bar", 2) .addNeedsArtifactType("dsn") .forwards(true) - .location("fwd.md", 3 + titleLocationOffset) + .location(FILENAME, 3 + titleLocationOffset) .build(), item() .id("dsn", "zoo", 3).addCoveredId("req", "zoo", 3) .addNeedsArtifactType("impl") .forwards(true) - .location("fwd.md", 4 + titleLocationOffset) + .location(FILENAME, 4 + titleLocationOffset) .build())); } @@ -393,7 +394,7 @@ void testArtifactForwardingAfterARegularSpecificationItem() @Test void testForwardingAfterCovers() { - assertImport("1.2.md", """ + assertImport(FILENAME, """ dsn~foo~1 Covers: * req~foo~1 @@ -402,14 +403,14 @@ void testForwardingAfterCovers() contains( item() .id("dsn", "foo", 1) - .location("1.2.md", 1) + .location(FILENAME, 1) .addCoveredId("req", "foo", 1) .build(), item() .id("dsn", "bar", 2) .addCoveredId("req", "bar", 2) .addNeedsArtifactType("impl") - .location("1.2.md", 4) + .location(FILENAME, 4) .forwards(true) .build())); } @@ -418,7 +419,7 @@ void testForwardingAfterCovers() @Test void testForwardingAfterNeeds() { - assertImport("1.2.md", """ + assertImport(FILENAME, """ dsn~foo~1 Needs: impl dsn-->impl:req~bar~2 @@ -426,14 +427,14 @@ void testForwardingAfterNeeds() contains( item() .id("dsn", "foo", 1) - .location("1.2.md", 1) + .location(FILENAME, 1) .addNeedsArtifactType("impl") .build(), item() .id("dsn", "bar", 2) .addCoveredId("req", "bar", 2) .addNeedsArtifactType("impl") - .location("1.2.md", 3) + .location(FILENAME, 3) .forwards(true) .build())); } @@ -486,7 +487,7 @@ void testComplexRequirement() @Test void testTwoConsecutiveSpecificationItems() { - assertImport("file1.md", """ + assertImport(FILENAME, """ dsn~foo~1 First description @@ -505,13 +506,13 @@ void testTwoConsecutiveSpecificationItems() .id("dsn", "foo", 1) .description("First description") .comment("First comment") - .location("file1.md", 1) + .location(FILENAME, 1) .build(), item() .id("dsn", "bar", 2) .description("Second description") .rationale("Second rationale") - .location("file1.md", 8) + .location(FILENAME, 8) .build())); }