Skip to content

Commit 873c2e2

Browse files
committed
chore: sonar issues
1 parent 413aada commit 873c2e2

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

src/main/java/org/fugerit/java/junit5/tag/check/facade/DocHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public class DocHelper {
1818
*
1919
* Consider using a @ApplicationScoped or Singleton approach.
2020
*/
21-
private static final FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade
21+
private final FreemarkerDocProcessConfig docProcessConfig = FreemarkerDocProcessConfigFacade
2222
.loadConfigSafe("cl://junit5-tag-check-maven-plugin/fm-doc-process-config.xml");
2323

24-
public static void generateReport(String handlerId, ReportHelper reportHelper, OutputStream os ) {
24+
public void generateReport(String handlerId, ReportHelper reportHelper, OutputStream os ) {
2525
SafeFunction.apply( () -> docProcessConfig.
2626
fullProcess( "report",
2727
DocProcessContext.newContext( "report", reportHelper )

src/main/java/org/fugerit/java/junit5/tag/check/facade/TagReportFacade.java

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ private void generateReport(Map<ExecutedTest, Set<String>> testTagMap)
5555
generateFjDocReport( helper, format.toLowerCase() );
5656
break;
5757
default:
58-
generateTextReport(testTagMap);
58+
generateTextReport(helper);
5959
}
6060
}
6161

62-
private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
63-
throws IOException {
62+
private void generateTextReport(ReportHelper helper) throws IOException {
63+
64+
Map<ExecutedTest, Set<String>> testTagMap = helper.getTestTagMap();
65+
6466
// Helper method for String.repeat(80)
6567
String separator = repeatString("=", 80);
6668
String line = repeatString("-", 80);
@@ -94,21 +96,8 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
9496
writer.write("\n");
9597

9698
// Summary by tag (Java 8 compatible map operations: computeIfAbsent is fine)
97-
Map<String, List<ExecutedTest>> tagToTests = new HashMap<>();
98-
Map<String, TestStats> tagStats = new HashMap<>();
99-
100-
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
101-
ExecutedTest test = entry.getKey();
102-
for (String tag : entry.getValue()) {
103-
tagToTests.computeIfAbsent(tag, k -> new ArrayList<>()).add(test);
104-
105-
TestStats stats = tagStats.computeIfAbsent(tag, k -> new TestStats());
106-
stats.increaseTotal();
107-
if (test.isFailed()) stats.increaseFailed();
108-
if (test.isError()) stats.increaseErrors();
109-
if (test.isSkipped()) stats.increaseSkipped();
110-
}
111-
}
99+
Map<String, List<ExecutedTest>> tagToTests = helper.getTagsToTests();
100+
Map<String, TestStats> tagStats = helper.getTagsStats();
112101

113102
writer.write("SUMMARY BY TAG:\n");
114103
writer.write(line + "\n");
@@ -193,7 +182,7 @@ private String repeatString(String s, int count) {
193182

194183
private void generateFjDocReport(ReportHelper reportHelper, String handlerId) throws IOException {
195184
try (OutputStream os = new FileOutputStream(outputFile)) {
196-
DocHelper.generateReport( handlerId, reportHelper, os );
185+
new DocHelper().generateReport( handlerId, reportHelper, os );
197186
}
198187
}
199188

src/main/java/org/fugerit/java/junit5/tag/check/model/ExecutedTest.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
package org.fugerit.java.junit5.tag.check.model;
22

3-
/*
4-
5-
{
6-
"class": "test.org.fugerit.java.demo.unittestdemoapp.DocResourceSicurezzaTest",
7-
"method": "testHtmlOkNoAdminRole",
8-
"time": 1.37,
9-
"skipped": false,
10-
"failed": false,
11-
"error": false,
12-
"tags": ["security", "authorized"]
13-
},
14-
15-
*/
16-
173
import com.fasterxml.jackson.annotation.JsonProperty;
184
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
195

src/main/java/org/fugerit/java/junit5/tag/check/model/ReportHelper.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,35 @@ public class ReportHelper {
1111

1212
private ReportModel reportModel;
1313

14+
private Map<String, List<ExecutedTest>> tagToTests;
15+
16+
private Map<String, TestStats> tagStats;
17+
1418
public ReportHelper(Map<ExecutedTest, Set<String>> testTagMap) {
1519
this.testTagMap = testTagMap;
20+
// report model
1621
this.reportModel = new ReportModel();
1722
for (Map.Entry<ExecutedTest, Set<String>> entry : this.getTestTagMap().entrySet()) {
1823
ExecutedTest current = entry.getKey();
1924
current.getTags().addAll(entry.getValue());
2025
reportModel.getExecutedTests().add( current );
2126
}
27+
// tag to test
28+
this.tagToTests = new HashMap<>();
29+
this.tagStats = new HashMap<>();
30+
31+
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
32+
ExecutedTest test = entry.getKey();
33+
for (String tag : entry.getValue()) {
34+
tagToTests.computeIfAbsent(tag, k -> new ArrayList<>()).add(test);
35+
36+
TestStats stats = tagStats.computeIfAbsent(tag, k -> new TestStats());
37+
stats.increaseTotal();
38+
if (test.isFailed()) stats.increaseFailed();
39+
if (test.isError()) stats.increaseErrors();
40+
if (test.isSkipped()) stats.increaseSkipped();
41+
}
42+
}
2243
}
2344

2445
public Map<ExecutedTest, Set<String>> getTestTagMap() {
@@ -42,14 +63,22 @@ public long getSummaryError() {
4263
}
4364

4465
public Map<String, List<ExecutedTest>> getTagsSummary() {
45-
Map<String, List<ExecutedTest>> tagToTests = new LinkedHashMap<>();
66+
Map<String, List<ExecutedTest>> tagsSummary = new LinkedHashMap<>();
4667
for (Map.Entry<ExecutedTest, Set<String>> entry : this.getTestTagMap().entrySet()) {
4768
for (String tag : entry.getValue()) {
48-
tagToTests.computeIfAbsent(tag, k -> new ArrayList<>()).add(entry.getKey());
69+
tagsSummary.computeIfAbsent(tag, k -> new ArrayList<>()).add(entry.getKey());
4970
}
5071
}
51-
log.debug( "getTagsSummary() : {}", tagToTests );
52-
return tagToTests;
72+
log.debug( "getTagsSummary() : {}", tagsSummary );
73+
return tagsSummary;
74+
}
75+
76+
public Map<String, List<ExecutedTest>> getTagsToTests() {
77+
return this.tagToTests;
78+
}
79+
80+
public Map<String, TestStats> getTagsStats() {
81+
return this.tagStats;
5382
}
5483

5584
}

0 commit comments

Comments
 (0)