Skip to content

Commit

Permalink
Remove issue printer.
Browse files Browse the repository at this point in the history
This part of the code was used as example only.
  • Loading branch information
uhafner committed Jan 14, 2025
1 parent 6d029e3 commit 8660897
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 90 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
<exclude>.*LineRangeList</exclude>
<exclude>.*SecureDigester</exclude>
<exclude>.*Benchmark.*</exclude>
<exclude>.*ModuleDetector.*</exclude>
<exclude>edu.hm.hafner.analysis.parser.*</exclude>
<exclude>edu.hm.hafner.analysis.PackageDetectors.*</exclude>
</excludes>
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/edu/hm/hafner/analysis/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
Expand Down Expand Up @@ -824,16 +823,6 @@ private String getDuplicates() {
return StringUtils.EMPTY;
}

/**
* Prints all issues of the report.
*
* @param issuePrinter
* prints a summary of an {@link Issue}
*/
public void print(final IssuePrinter issuePrinter) {
forEach(issuePrinter::print);
}

/**
* Returns the affected modules for all issues.
*
Expand Down Expand Up @@ -1431,44 +1420,6 @@ public boolean hasCounter(final String key) {
return countersByKey.containsKey(key);
}

/**
* Prints a summary of an {@link Issue}.
*/
public interface IssuePrinter {
/**
* Prints the specified issue.
*
* @param issue
* the issue to print
*/
void print(Issue issue);
}

/**
* Prints issues to the "standard" output stream.
*/
public static class StandardOutputPrinter implements IssuePrinter {
private final PrintStream printStream;

/**
* Creates a new printer that prints to the "standard" output stream.
*/
@SuppressWarnings("SystemOut")
public StandardOutputPrinter() {
this(System.out);
}

@VisibleForTesting
StandardOutputPrinter(final PrintStream printStream) {
this.printStream = printStream;
}

@Override
public void print(final Issue issue) {
printStream.println(issue.toString());
}
}

/**
* Builds a combined filter based on several include and exclude filters.
*
Expand Down
41 changes: 0 additions & 41 deletions src/test/java/edu/hm/hafner/analysis/ReportTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.hm.hafner.analysis;

import java.io.IOException;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.List;
Expand All @@ -19,14 +18,10 @@
import org.slf4j.bridge.SLF4JBridgeHandler;

import edu.hm.hafner.analysis.Report.IssueFilterBuilder;
import edu.hm.hafner.analysis.Report.IssuePrinter;
import edu.hm.hafner.analysis.Report.StandardOutputPrinter;
import edu.hm.hafner.analysis.assertions.SoftAssertions;
import edu.hm.hafner.analysis.parser.CheckStyleParser;
import edu.hm.hafner.util.FilteredLog;
import edu.hm.hafner.util.LineRange;
import edu.hm.hafner.util.LineRangeList;
import edu.hm.hafner.util.PathUtil;
import edu.hm.hafner.util.SerializableTest;
import edu.hm.hafner.util.TreeString;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -35,7 +30,6 @@

import static edu.hm.hafner.analysis.assertions.Assertions.*;
import static java.util.Arrays.*;
import static org.mockito.Mockito.*;

/**
* Unit tests for {@link Report}.
Expand Down Expand Up @@ -867,41 +861,6 @@ void shouldBeNotEqualsAPropertyChanges() {
assertThat(report).isNotEqualTo(other); // there should be duplicates
}

@Test
void shouldPrintAllIssues() {
var report = readCheckStyleReport();

var printer = mock(IssuePrinter.class);
report.print(printer);

for (Issue issue : report) {
verify(printer).print(issue);
}
}

@Test
void shouldPrintAllIssuesToPrintStream() {
var report = readCheckStyleReport();

try (var printStream = mock(PrintStream.class)) {
report.print(new StandardOutputPrinter(printStream));

for (Issue issue : report) {
verify(printStream).println(issue.toString());
}
}
}

private Report readCheckStyleReport() {
var fileName = "parser/checkstyle/all-severities.xml";
var report = new CheckStyleParser().parse(read(fileName));
report.add(new IssueBuilder().setSeverity(Severity.WARNING_HIGH).setMessage("Severity High warning").build());
assertThat(report).hasSize(4);
assertThat(report.getSeverities()).hasSize(4);
assertThat(report).hasOriginReportFile(new PathUtil().getAbsolutePath(getResourceAsFile(fileName)));
return report;
}

private ReaderFactory read(final String fileName) {
return new FileReaderFactory(getResourceAsFile(fileName), StandardCharsets.UTF_8);

Check warning on line 865 in src/test/java/edu/hm/hafner/analysis/ReportTest.java

View check run for this annotation

ci.jenkins.io / SpotBugs

UPM_UNCALLED_PRIVATE_METHOD

LOW: Private method edu.hm.hafner.analysis.ReportTest.read(String) is never called
Raw output
<p> This private method is never called. Although it is possible that the method will be invoked through reflection, it is more likely that the method is never used, and should be removed. </p>
}
Expand Down

0 comments on commit 8660897

Please sign in to comment.