@Test public void testRuleWithArguments() { final String EXPECTED_BUG_TYPE = "BUG_TYPE"; final int EXPECTED_PRIORITY = Priorities.NORMAL_PRIORITY; final String EXPECTED_DESCRIPTION = "describing about this bug type..."; BugPattern bugPattern = new BugPattern(EXPECTED_BUG_TYPE, "abbrev", "category", false, EXPECTED_DESCRIPTION, "describing about this bug type with value {0}...", "detailText", null, 0); DetectorFactoryCollection.instance().registerBugPattern(bugPattern); reporter.reportBug(new BugInstance(bugPattern.getType(), bugPattern.getPriorityAdjustment()).addInt(10).addClass("the/target/Class")); reporter.finish(); String json = writer.toString(); JSONObject jsonObject = new JSONObject(json); JSONObject run = jsonObject.getJSONArray("runs").getJSONObject(0); JSONArray rules = run.getJSONObject("tool").getJSONObject("driver").getJSONArray("rules"); JSONArray results = run.getJSONArray("results"); assertThat(rules.length(), is(1)); JSONObject rule = rules.getJSONObject(0); assertThat(rule.get("id"), is(bugPattern.getType())); String defaultText = rule.getJSONObject("messageStrings").getJSONObject("default").getString("text"); assertThat(defaultText, is("describing about this bug type with value {0}...")); assertThat(results.length(), is(1)); JSONObject result = results.getJSONObject(0); assertThat(result.get("ruleId"), is(bugPattern.getType())); JSONObject message = result.getJSONObject("message"); assertThat(message.getString("id"), is("default")); JSONArray arguments = message.getJSONArray("arguments"); assertThat(arguments.getInt(0), is(10)); }
@Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); @Override void finish(); }
SarifBugReporter extends BugCollectionBugReporter { @Override public void finish() { try { JSONWriter jsonWriter = new JSONWriter(outputStream); jsonWriter.object(); jsonWriter.key("version").value("2.1.0").key("$schema").value( "https: processRuns(jsonWriter); jsonWriter.endObject(); getBugCollection().bugsPopulated(); } finally { outputStream.close(); } } SarifBugReporter(Project project); @Override void finish();  }