@Test public void writeXML() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); String xmlOutput = writeXMLAndGetStringOutput(sm, false); assertEquals("<Source name=\"" + fileName + "\"/>", xmlOutput); sm = new SourceMatcher(fileName); xmlOutput = writeXMLAndGetStringOutput(sm, true); assertEquals("<Source name=\"" + fileName + "\" disabled=\"true\"/>", xmlOutput); }
@Test public void match() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); // no source set: test incomplete data assertFalse(sm.match(bug)); bug.addClass("bla", null); assertFalse(sm.match(bug)); ClassAnnotation primaryClass = bug.getPrimaryClass(); primaryClass.setSourceLines(SourceLineAnnotation.createUnknown("bla", "")); assertFalse(sm.match(bug)); // set right source file primaryClass.setSourceLines(SourceLineAnnotation.createUnknown("bla", fileName)); // exact match assertTrue(sm.match(bug)); // regexp first part sm = new SourceMatcher("~bla.*"); assertTrue(sm.match(bug)); sm = new SourceMatcher("~blup.*"); assertFalse(sm.match(bug)); // regexp second part sm = new SourceMatcher("~.*\\.groovy"); assertTrue(sm.match(bug)); sm = new SourceMatcher("~.*\\.java"); assertFalse(sm.match(bug)); }
private String writeXMLAndGetStringOutput(SourceMatcher matcher, boolean disabled) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLOutput xmlOutput = new OutputStreamXMLOutput(outputStream); matcher.writeXML(xmlOutput, disabled); xmlOutput.finish(); return outputStream.toString(StandardCharsets.UTF_8.name()).trim(); }
pushCompoundMatcherAsChild(matcher); } else if ("Source".equals(qName)) { addMatcher(new SourceMatcher(getRequiredAttribute(attributes, "name", qName)));
@Test public void readXML() throws Exception { SourceMatcher sm = new SourceMatcher(fileName); String xml = writeXMLAndGetStringOutput(sm, false); xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "\n<FindBugsFilter>" + "\n<Match>" + "\n" + xml + "\n</Match>" + "\n</FindBugsFilter>\n"; Filter filter = new Filter(new StringInputStream(xml)); assertFalse(filter.match(bug)); bug.addClass("bla", fileName); assertTrue(filter.match(bug)); }
pushCompoundMatcherAsChild(matcher); } else if ("Source".equals(qName)) { addMatcher(new SourceMatcher(getRequiredAttribute(attributes, "name", qName)));