Skip to content

Commit a59a406

Browse files
committed
chore: refactor ExecutedTestTagReporterMojo - extract models
1 parent ae0ae02 commit a59a406

File tree

3 files changed

+76
-39
lines changed

3 files changed

+76
-39
lines changed

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

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.dom4j.Document;
99
import org.dom4j.Element;
1010
import org.dom4j.io.SAXReader;
11+
import org.fugerit.java.junit5.tag.check.model.ExecutedTest;
12+
import org.fugerit.java.junit5.tag.check.model.TestStats;
1113
import org.junit.jupiter.api.Tag;
1214

1315
import java.io.File;
@@ -290,10 +292,10 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
290292
tagToTests.computeIfAbsent(tag, k -> new ArrayList<>()).add(test);
291293

292294
TestStats stats = tagStats.computeIfAbsent(tag, k -> new TestStats());
293-
stats.total++;
294-
if (test.isFailed()) stats.failed++;
295-
if (test.isError()) stats.errors++;
296-
if (test.isSkipped()) stats.skipped++;
295+
stats.increaseTotal();
296+
if (test.isFailed()) stats.increaseFailed();
297+
if (test.isError()) stats.increaseErrors();
298+
if (test.isSkipped()) stats.increaseSkipped();
297299
}
298300
}
299301

@@ -305,9 +307,9 @@ private void generateTextReport(Map<ExecutedTest, Set<String>> testTagMap)
305307

306308
for (Map.Entry<String, TestStats> entry : tagStats.entrySet()) {
307309
TestStats stats = entry.getValue();
308-
int passed = stats.total - stats.failed - stats.errors - stats.skipped;
310+
int passed = stats.getTotal() - stats.getFailed() - stats.getErrors() - stats.getSkipped();
309311
writer.write(String.format("%-20s | %5d | %5d | %5d | %5d%n",
310-
entry.getKey(), stats.total, passed, stats.failed, stats.errors));
312+
entry.getKey(), stats.getTotal(), passed, stats.getFailed(), stats.getErrors()));
311313
}
312314

313315
// Tests without tags
@@ -562,37 +564,4 @@ private String escapeXml(String str) {
562564
.replace("'", "&apos;");
563565
}
564566

565-
// Helper classes
566-
static class ExecutedTest {
567-
private final String className;
568-
private final String methodName;
569-
private final boolean skipped;
570-
private final boolean failed;
571-
private final boolean error;
572-
private final String time;
573-
574-
public ExecutedTest(String className, String methodName,
575-
boolean skipped, boolean failed, boolean error, String time) {
576-
this.className = className;
577-
this.methodName = methodName;
578-
this.skipped = skipped;
579-
this.failed = failed;
580-
this.error = error;
581-
this.time = time;
582-
}
583-
584-
public String getClassName() { return className; }
585-
public String getMethodName() { return methodName; }
586-
public boolean isSkipped() { return skipped; }
587-
public boolean isFailed() { return failed; }
588-
public boolean isError() { return error; }
589-
public String getTime() { return time; }
590-
}
591-
592-
static class TestStats {
593-
int total = 0;
594-
int failed = 0;
595-
int errors = 0;
596-
int skipped = 0;
597-
}
598567
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.fugerit.java.junit5.tag.check.model;
2+
3+
public class ExecutedTest {
4+
private final String className;
5+
private final String methodName;
6+
private final boolean skipped;
7+
private final boolean failed;
8+
private final boolean error;
9+
private final String time;
10+
11+
public ExecutedTest(String className, String methodName,
12+
boolean skipped, boolean failed, boolean error, String time) {
13+
this.className = className;
14+
this.methodName = methodName;
15+
this.skipped = skipped;
16+
this.failed = failed;
17+
this.error = error;
18+
this.time = time;
19+
}
20+
21+
public String getClassName() { return className; }
22+
public String getMethodName() { return methodName; }
23+
public boolean isSkipped() { return skipped; }
24+
public boolean isFailed() { return failed; }
25+
public boolean isError() { return error; }
26+
public String getTime() { return time; }
27+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.fugerit.java.junit5.tag.check.model;
2+
3+
public class TestStats {
4+
5+
private int total = 0;
6+
private int failed = 0;
7+
private int errors = 0;
8+
private int skipped = 0;
9+
10+
public void increaseTotal() {
11+
this.total++;
12+
}
13+
14+
public void increaseFailed() {
15+
this.failed++;
16+
}
17+
18+
public void increaseErrors() {
19+
this.errors++;
20+
}
21+
22+
public void increaseSkipped() {
23+
this.skipped++;
24+
}
25+
26+
public int getErrors() {
27+
return errors;
28+
}
29+
30+
public int getFailed() {
31+
return failed;
32+
}
33+
34+
public int getSkipped() {
35+
return skipped;
36+
}
37+
38+
public int getTotal() {
39+
return total;
40+
}
41+
}

0 commit comments

Comments
 (0)