-
Notifications
You must be signed in to change notification settings - Fork 578
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: try to reproduce the reported issue as #1187
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
spotbugs/src/test/java/edu/umd/cs/findbugs/HTMLBugReporterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package edu.umd.cs.findbugs; | ||
|
||
import edu.umd.cs.findbugs.ba.AnalysisContext; | ||
import edu.umd.cs.findbugs.classfile.Global; | ||
import edu.umd.cs.findbugs.classfile.IAnalysisCache; | ||
import edu.umd.cs.findbugs.classfile.impl.ClassFactory; | ||
import edu.umd.cs.findbugs.classfile.impl.ClassPathImpl; | ||
import edu.umd.cs.findbugs.internalAnnotations.DottedClassName; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
public class HTMLBugReporterTest { | ||
private HTMLBugReporter reporter; | ||
private StringWriter writer; | ||
|
||
@Before | ||
public void setup() { | ||
Project project = new Project(); | ||
reporter = new HTMLBugReporter(project, "fancy.xsl"); | ||
writer = new StringWriter(); | ||
reporter.setWriter(new PrintWriter(writer)); | ||
reporter.setPriorityThreshold(Priorities.IGNORE_PRIORITY); | ||
DetectorFactoryCollection.resetInstance(new DetectorFactoryCollection()); | ||
IAnalysisCache analysisCache = ClassFactory.instance().createAnalysisCache(new ClassPathImpl(), reporter); | ||
Global.setAnalysisCacheForCurrentThread(analysisCache); | ||
FindBugs2.registerBuiltInAnalysisEngines(analysisCache); | ||
AnalysisContext analysisContext = new AnalysisContext(project) { | ||
public boolean isApplicationClass(@DottedClassName String className) { | ||
// treat all classes as application class, to report bugs in it | ||
return true; | ||
} | ||
}; | ||
AnalysisContext.setCurrentAnalysisContext(analysisContext); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
AnalysisContext.removeCurrentAnalysisContext(); | ||
Global.removeAnalysisCacheForCurrentThread(); | ||
} | ||
|
||
/** | ||
* @see <a href="https://github.com/spotbugs/spotbugs/issues/1187">related GitHub Issue</a> | ||
*/ | ||
@Test | ||
public void testInnerClass() { | ||
BugPattern bugPattern = new BugPattern("bugType", "abbrev", "category", false, "shortDescription", | ||
"describing about this bug type with value {0}...", "detailText", null, 0); | ||
DetectorFactoryCollection.instance().registerBugPattern(bugPattern); | ||
BugCode bugCode = new BugCode("abbrev", "description", 0); | ||
DetectorFactoryCollection.instance().registerBugCode(bugCode); | ||
|
||
reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass("the/target/Class$Inner")); | ||
reporter.finish(); | ||
|
||
System.out.println(writer.toString()); | ||
} | ||
} |