Skip to content

Commit 6b7da31

Browse files
authored
fix/sonar_specification_item_parametrization (#557)
* 536: Reduced number of lines in lambda in SpecDocumentHandlerBuilder to improve readability. * 536: Reduced number of static imports to four in `AbstractLightWeightMarkupImporterTest`. * 536: Allowed longer method for state transition table. * 536: Allow wildcard generic. * 536: Suppress warning about catching exceptions.
1 parent 656774d commit 6b7da31

5 files changed

Lines changed: 15 additions & 16 deletions

File tree

importer/restructuredtext/src/main/java/org/itsallcode/openfasttrace/importer/restructuredtext/RestructuredTextImporter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class RestructuredTextImporter extends AbstractLightWeightMarkupImporter
3737
}
3838

3939
@Override
40+
@SuppressWarnings("java:S138") // Transition table is OK be larger than 75 lines.
4041
protected Transition[] configureTransitions()
4142
{
4243
// @formatter:off

importer/specobject/src/main/java/org/itsallcode/openfasttrace/importer/specobject/handler/SpecDocumentHandlerBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ public TreeContentHandler build()
6565
throw new ImporterException("Element " + elem + " does not have an attribute '"
6666
+ DOCTYPE_ATTRIBUTE_NAME + "' at " + elem.getLocation());
6767
}
68-
final String defaultDoctype = doctypeAttribute.getValue();
69-
this.handler.pushDelegate(new SpecObjectsHandlerBuilder(this.file, defaultDoctype, this.listener)
70-
.build());
68+
this.handler.pushDelegate(new SpecObjectsHandlerBuilder(this.file, doctypeAttribute.getValue(),
69+
this.listener).build());
7170
});
72-
7371
return this.handler;
7472
}
7573
}

importer/xmlparser/src/main/java/org/itsallcode/openfasttrace/importer/xmlparser/tree/CallbackContentHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public void init(final TreeParsingController treeParsingController)
117117
}
118118

119119
@Override
120+
@SuppressWarnings("java:S2221") // Intentionally catching all exceptions to provide better error messages.
120121
public void startElement(final TreeElement treeElement)
121122
{
122123
LOG.finest(() -> "Start element: " + treeElement);

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/ImportAssertions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ private ImportAssertions()
3838
* @param importerFactory
3939
* factory that generates the importer
4040
*/
41+
@SuppressWarnings("java:S4968") // Match type definition comes from Hamcrest. Cannot change.
4142
public static void assertImportWithFactory(final Path path, final String input,
4243
final Matcher<Iterable<? extends SpecificationItem>> matcher,
4344
final ImporterFactory importerFactory)

testutil/src/main/java/org/itsallcode/openfasttrace/testutil/importer/lightweightmarkup/AbstractLightWeightMarkupImporterTest.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
import static org.hamcrest.MatcherAssert.assertThat;
44
import static org.hamcrest.Matchers.equalTo;
55
import static org.itsallcode.matcher.auto.AutoMatcher.contains;
6-
import static org.itsallcode.openfasttrace.api.core.SpecificationItemId.createId;
76
import static org.itsallcode.openfasttrace.testutil.core.ItemBuilderFactory.item;
8-
import static org.itsallcode.openfasttrace.testutil.importer.ImportAssertions.assertImportWithFactory;
9-
import static org.itsallcode.openfasttrace.testutil.importer.ImportAssertions.runImporterOnText;
107

118
import java.nio.file.Path;
129
import java.util.List;
@@ -16,6 +13,7 @@
1613
import org.hamcrest.Matcher;
1714
import org.itsallcode.openfasttrace.api.core.*;
1815
import org.itsallcode.openfasttrace.api.importer.ImporterFactory;
16+
import org.itsallcode.openfasttrace.testutil.importer.ImportAssertions;
1917
import org.junit.jupiter.api.Test;
2018
import org.junit.jupiter.params.ParameterizedTest;
2119
import org.junit.jupiter.params.provider.*;
@@ -100,7 +98,7 @@ protected void assertImport(final String path, final String input,
10098
protected void assertImport(final Path path, final String input,
10199
final Matcher<Iterable<? extends SpecificationItem>> matcher)
102100
{
103-
assertImportWithFactory(path, processTextInput(input), matcher, getImporterFactory());
101+
ImportAssertions.assertImportWithFactory(path, processTextInput(input), matcher, getImporterFactory());
104102
}
105103

106104
private String processTextInput(final String input)
@@ -236,7 +234,7 @@ static Stream<Arguments> tags()
236234
@MethodSource("tags")
237235
void testTags(final String mdContent, final List<String> expected)
238236
{
239-
final List<SpecificationItem> items = runImporterOnText(Path.of("irrelevant-filename"),
237+
final List<SpecificationItem> items = ImportAssertions.runImporterOnText(Path.of("irrelevant-filename"),
240238
"`a~b~1`\n" + mdContent,
241239
getImporterFactory());
242240
assertThat(items.get(0).getTags(), equalTo(expected));
@@ -538,7 +536,7 @@ static Stream<Arguments> needsCoverage()
538536
@MethodSource("needsCoverage")
539537
void testNeedsCoverage(final String mdContent, final List<String> expected)
540538
{
541-
final List<SpecificationItem> items = runImporterOnText(Path.of("irrelevant-filename"),
539+
final List<SpecificationItem> items = ImportAssertions.runImporterOnText(Path.of("irrelevant-filename"),
542540
"`a~b~1`\n" + mdContent,
543541
getImporterFactory());
544542
assertThat(items.get(0).getNeedsArtifactTypes(), equalTo(expected));
@@ -570,7 +568,7 @@ void testItemIdSupportsUTF8Characaters()
570568
Needs: arch
571569
""",
572570
contains(item()
573-
.id(createId("req", "zellzustandsänderung", 1))
571+
.id(SpecificationItemId.createId("req", "zellzustandsänderung", 1))
574572
.title("Die Implementierung muss den Zustand einzelner Zellen ändern")
575573
.description("Ermöglicht die Aktualisierung des Zustands von lebenden und toten Zellen"
576574
+ " in jeder Generation.")
@@ -591,12 +589,12 @@ void testHeaderBelongsToNextItem()
591589
`req~item2~1
592590
Item 2 description
593591
""",
594-
contains(item().id(createId("req", "item1", 1))
592+
contains(item().id(SpecificationItemId.createId("req", "item1", 1))
595593
.title("Item 1")
596594
.description("Item 1 description")
597595
.location("file", 2 + titleLocationOffset)
598596
.build(),
599-
item().id(createId("req", "item2", 1))
597+
item().id(SpecificationItemId.createId("req", "item2", 1))
600598
.title("Item 2")
601599
.description("Item 2 description")
602600
.location("file", 6 + (2 * titleLocationOffset))
@@ -614,7 +612,7 @@ void testParsingNeedsIgnoresExtraListItems() {
614612
* this must not be in needs section
615613
""",
616614
contains(item()
617-
.id(createId("feat", "the-feature", 1))
615+
.id(SpecificationItemId.createId("feat", "the-feature", 1))
618616
.addNeedsArtifactType("arch")
619617
.description("* this must not be in needs section")
620618
.location("needs_with_extra_list_items.md", 1)
@@ -638,12 +636,12 @@ void testNeedsAfterCovers() {
638636
Needs: itest
639637
""",
640638
contains(item()
641-
.id(createId("dsn", "needs", 3))
639+
.id(SpecificationItemId.createId("dsn", "needs", 3))
642640
.description("Description with a bulleted list"
643641
+ System.lineSeparator()
644642
+ System.lineSeparator() + "* this"
645643
+ System.lineSeparator() + "* that")
646-
.addCoveredId(createId("req", "needs", 2))
644+
.addCoveredId(SpecificationItemId.createId("req", "needs", 2))
647645
.addNeedsArtifactType("itest")
648646
.location("needs_after_covers.md", 1)
649647
.build()));

0 commit comments

Comments
 (0)