Skip to content

Commit 01fc486

Browse files
committed
chore: output in json, xml and text
1 parent 4ffa208 commit 01fc486

File tree

6 files changed

+599
-43
lines changed

6 files changed

+599
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- documented output in json, xml and text
13+
1014
## [1.0.0] - 2025-11-26
1115

1216
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A simple plugin to check the presence of JUnit5 test by tags.
1212

1313
| parameter | type | required | notes |
1414
|--------------------------|---------|----------|------------------------------------------------------|
15-
| format | string | true | only 'html' accepted |
15+
| format | string | false | default 'text', accepts 'html', 'json', 'xml' |
1616
| outputFile | string | true | path where should be produced the report |
1717
| requiredTags.requiredTag | string | true | tag to be checked |
1818
| failOnMissingTag | boolean | true | if set to 'true' the build will fail on missing tags |

pom.xml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,39 @@
113113
<dependency>
114114
<groupId>org.junit.platform</groupId>
115115
<artifactId>junit-platform-launcher</artifactId>
116-
<version>1.10.0</version>
116+
<version>1.14.1</version>
117117
</dependency>
118118

119119
<dependency>
120120
<groupId>org.junit.jupiter</groupId>
121121
<artifactId>junit-jupiter-api</artifactId>
122-
<version>5.13.4</version>
123122
<scope>compile</scope>
124123
</dependency>
125124

126125
<dependency>
127126
<groupId>org.junit.jupiter</groupId>
128127
<artifactId>junit-jupiter</artifactId>
129-
<version>5.13.4</version>
130128
<scope>compile</scope>
131129
</dependency>
132130

131+
<dependency>
132+
<groupId>org.apache.maven.plugin-testing</groupId>
133+
<artifactId>maven-plugin-testing-harness</artifactId>
134+
<version>3.3.0</version> <scope>test</scope>
135+
</dependency>
136+
137+
<dependency>
138+
<groupId>org.apache.maven</groupId>
139+
<artifactId>maven-compat</artifactId>
140+
<version>3.9.0</version>
141+
<scope>test</scope>
142+
</dependency>
143+
144+
<dependency>
145+
<groupId>org.slf4j</groupId>
146+
<artifactId>slf4j-simple</artifactId>
147+
</dependency>
148+
133149
</dependencies>
134150

135151
<build>

src/main/java/org/fugerit/java/junit5/tag/check/ExecutedTestTagReporterMojo.java

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
253253
String line = repeatString("-", 80);
254254

255255
try (FileWriter writer = new FileWriter(outputFile)) {
256-
writer.write(separator + "%n");
257-
writer.write("EXECUTED TEST TAG REPORT%n");
258-
writer.write(separator + "%n%n");
256+
writer.write(separator + "\n");
257+
writer.write("EXECUTED TEST TAG REPORT\n");
258+
writer.write(separator + "\n\n");
259259

260260
int totalTests = testTagMap.size();
261261

@@ -269,16 +269,16 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
269269
int skippedTests = (int) testTagMap.keySet().stream()
270270
.filter(ExecutedTest::isSkipped).count();
271271

272-
writer.write("EXECUTION SUMMARY:%n");
273-
writer.write(line + "%n");
272+
writer.write("EXECUTION SUMMARY:\n");
273+
writer.write(line + "\n");
274274
writer.write(String.format(" Total Tests: %d%n", totalTests));
275275
writer.write(String.format(" Passed: %d%n", passedTests));
276276
writer.write(String.format(" Failed: %d%n", failedTests));
277277
writer.write(String.format(" Errors: %d%n", errorTests));
278278
if (includeSkipped) {
279279
writer.write(String.format(" Skipped: %d%n", skippedTests));
280280
}
281-
writer.write("%n");
281+
writer.write("\n");
282282

283283
// Summary by tag (Java 8 compatible map operations: computeIfAbsent is fine)
284284
Map<String, List<ExecutedTest>> tagToTests = new HashMap<>();
@@ -297,11 +297,11 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
297297
}
298298
}
299299

300-
writer.write("SUMMARY BY TAG:%n");
301-
writer.write(line + "%n");
300+
writer.write("SUMMARY BY TAG:\n");
301+
writer.write(line + "\n");
302302
writer.write(String.format("%-20s | %5s | %5s | %5s | %5s%n",
303303
"Tag", "Total", "Pass", "Fail", "Error"));
304-
writer.write(line + "%n");
304+
writer.write(line + "\n");
305305

306306
for (Map.Entry<String, TestStats> entry : tagStats.entrySet()) {
307307
TestStats stats = entry.getValue();
@@ -320,14 +320,14 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
320320
"<NO TAG>", testsWithoutTags, "?", "?", "?"));
321321
}
322322

323-
writer.write("%n" + separator + "%n");
324-
writer.write("EXECUTED TESTS BY TAG:%n");
325-
writer.write(separator + "%n%n");
323+
writer.write("\n" + separator + "\n");
324+
writer.write("EXECUTED TESTS BY TAG:\n");
325+
writer.write(separator + "\n\n");
326326

327327
for (Map.Entry<String, List<ExecutedTest>> entry : tagToTests.entrySet()) {
328328
writer.write(String.format("Tag: %s (%d tests)%n",
329329
entry.getKey(), entry.getValue().size()));
330-
writer.write(line + "%n");
330+
writer.write(line + "\n");
331331
for (ExecutedTest test : entry.getValue()) {
332332
String status = getStatusIcon(test);
333333
writer.write(String.format(" %s %s#%s (%.3fs)%n",
@@ -336,12 +336,12 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
336336
test.getMethodName(),
337337
Double.parseDouble(test.getTime())));
338338
}
339-
writer.write("%n");
339+
writer.write("\n");
340340
}
341341

342-
writer.write("%n" + separator + "%n");
343-
writer.write("ALL EXECUTED TESTS WITH TAGS:%n");
344-
writer.write(separator + "%n%n");
342+
writer.write("\n" + separator + "\n");
343+
writer.write("ALL EXECUTED TESTS WITH TAGS:\n");
344+
writer.write(separator + "\n\n");
345345

346346
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
347347
ExecutedTest test = entry.getKey();
@@ -359,10 +359,10 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
359359
}
360360

361361
if (testsWithoutTags > 0) {
362-
writer.write("%n" + separator + "%n");
362+
writer.write("%n" + separator + "\n");
363363
writer.write("⚠️ WARNING: " + testsWithoutTags +
364-
" executed tests without tags%n");
365-
writer.write(separator + "%n");
364+
" executed tests without tags\n");
365+
writer.write(separator + "\n");
366366
}
367367
}
368368
}
@@ -463,38 +463,38 @@ private void generateHtmlReport(Map<ExecutedTest, Set<String>> testTagMap)
463463
private void generateJsonReport(Map<ExecutedTest, Set<String>> testTagMap)
464464
throws IOException {
465465
try (FileWriter writer = new FileWriter(outputFile)) {
466-
writer.write("{%n");
467-
writer.write(" \"executedTests\": [%n");
466+
writer.write("{\n");
467+
writer.write(" \"executedTests\": [\n");
468468

469469
int count = 0;
470470
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
471-
if (count++ > 0) writer.write(",%n");
471+
if (count++ > 0) writer.write(",\n");
472472
ExecutedTest test = entry.getKey();
473-
writer.write(" {%n");
474-
writer.write(" \"class\": \"" + escapeJson(test.getClassName()) + "\",%n");
475-
writer.write(" \"method\": \"" + escapeJson(test.getMethodName()) + "\",%n");
476-
writer.write(" \"time\": " + test.getTime() + ",%n");
477-
writer.write(" \"skipped\": " + test.isSkipped() + ",%n");
478-
writer.write(" \"failed\": " + test.isFailed() + ",%n");
479-
writer.write(" \"error\": " + test.isError() + ",%n");
473+
writer.write(" {\n");
474+
writer.write(" \"class\": \"" + escapeJson(test.getClassName()) + "\",\n");
475+
writer.write(" \"method\": \"" + escapeJson(test.getMethodName()) + "\",\n");
476+
writer.write(" \"time\": " + test.getTime() + ",\n");
477+
writer.write(" \"skipped\": " + test.isSkipped() + ",\n");
478+
writer.write(" \"failed\": " + test.isFailed() + ",\n");
479+
writer.write(" \"error\": " + test.isError() + ",\n");
480480
writer.write(" \"tags\": [");
481481
writer.write(entry.getValue().stream()
482482
.map(tag -> "\"" + escapeJson(tag) + "\"")
483483
.collect(Collectors.joining(", ")));
484-
writer.write("]%n");
484+
writer.write("]\n");
485485
writer.write(" }");
486486
}
487487

488-
writer.write("%n ]%n");
489-
writer.write("}%n");
488+
writer.write("\n ]\n");
489+
writer.write("}");
490490
}
491491
}
492492

493493
private void generateXmlReport(Map<ExecutedTest, Set<String>> testTagMap)
494494
throws IOException {
495495
try (FileWriter writer = new FileWriter(outputFile)) {
496-
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n");
497-
writer.write("<executedTestTagReport>%n");
496+
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
497+
writer.write("<executedTestTagReport>\n");
498498

499499
for (Map.Entry<ExecutedTest, Set<String>> entry : testTagMap.entrySet()) {
500500
ExecutedTest test = entry.getKey();
@@ -503,14 +503,14 @@ private void generateXmlReport(Map<ExecutedTest, Set<String>> testTagMap)
503503
writer.write("time=\"" + test.getTime() + "\" ");
504504
writer.write("skipped=\"" + test.isSkipped() + "\" ");
505505
writer.write("failed=\"" + test.isFailed() + "\" ");
506-
writer.write("error=\"" + test.isError() + "\">%n");
506+
writer.write("error=\"" + test.isError() + "\">\n");
507507
for (String tag : entry.getValue()) {
508-
writer.write(" <tag>" + escapeXml(tag) + "</tag>%n");
508+
writer.write(" <tag>" + escapeXml(tag) + "</tag>\n");
509509
}
510-
writer.write(" </test>%n");
510+
writer.write(" </test>\n");
511511
}
512512

513-
writer.write("</executedTestTagReport>%n");
513+
writer.write("</executedTestTagReport>\n");
514514
}
515515
}
516516

0 commit comments

Comments
 (0)