### Question:
SoliumReportSensor extends AbstractExternalReportSensor { @Nullable @Override ExternalIssue parse(String line) { Matcher m = SOLIUM_SPECIAL_CHARACTERS.matcher(line); String cleanLine = m.replaceAll(""); Matcher fileMatcher = SOLIUM_FILE_REGEX.matcher(cleanLine); Matcher lineMatcher = SOLIUM_LINE_REGEX.matcher(cleanLine); if (fileMatcher.matches()) { String filename = fileMatcher.group("file"); return new ExternalIssue(LINTER_ID, null, null, filename, 0, "onlyfilename"); } else if (lineMatcher.matches()) { int lineNumber = Integer.parseInt(lineMatcher.group("line")); String issueType = lineMatcher.group("type").trim(); String message = lineMatcher.group("message").trim(); String issueKey = lineMatcher.group("key").trim(); if (SoliumKeyUtils.keyExists(issueKey)) { return new ExternalIssue(LINTER_ID, matchIssueToRuleType(issueType, issueKey), issueKey, null, lineNumber, message); } else { return null; } } else { LOG.debug(logPrefix() + "Unexpected line: " + line); } return null; }   static final String PROPERTY_KEY; static final String LINTER_NAME; static final String LINTER_ID; }### Answer:
@Test public void test_issues() throws IOException { SensorContextTester context = SoliumTestHelper.createContext(7, 2); context.settings().setProperty(SoliumReportSensor.PROPERTY_KEY, REPORT_BASE_PATH.resolve("test-report1.out").toString()); List<ExternalIssue> externalIssues = SoliumTestHelper.executeSensor(new SoliumReportSensor(), context); assertThat(externalIssues).isNotEmpty(); ExternalIssue firstExternalIssue = externalIssues.get(0); assertThat(firstExternalIssue.ruleKey()).isEqualTo(RuleKey.parse("solium:security/no-block-members")); assertThat(firstExternalIssue.type()).isEqualTo(RuleType.CODE_SMELL); assertThat(firstExternalIssue.severity()).isEqualTo(Severity.MAJOR); assertThat(firstExternalIssue.primaryLocation().message()).isEqualTo("Avoid using 'now' (alias to 'block.timestamp')."); assertThat(firstExternalIssue.primaryLocation().textRange().start().line()).isEqualTo(6); }
@Test public void simple_issue() throws IOException { String line = "21:26 error Assignment operator must have exactly single space on both sides of it. operator-whitespace"; org.sonarsource.solidity.externalreport.ExternalIssue issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); assertThat(issue.message).isEqualTo("Assignment operator must have exactly single space on both sides of it."); assertThat(issue.lineNumber).isEqualTo(21); assertThat(issue.ruleKey).isEqualTo("operator-whitespace"); assertThat(issue.type).isEqualTo(RuleType.BUG); line = "21:26 error Assignment operator must have exactly single space on both sides of it. security/no-block-members"; issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); line = "21:26 warning Ensure that all import statements are on top of the file imports-on-top"; issue = new SoliumReportSensor().parse(line); assertThat(issue).isNotNull(); }
@Test public void wrong_issue() throws IOException { String line = " warning Wrong Issue nokey"; org.sonarsource.solidity.externalreport.ExternalIssue issue = new SoliumReportSensor().parse(line); assertThat(issue).isNull(); }
@Test public void wrong_issue2() throws IOException { String line = "2:0 warning Assignment operator must have exactly single space on both sides of it. wrong_key"; org.sonarsource.solidity.externalreport.ExternalIssue issue = new SoliumReportSensor().parse(line); assertThat(issue).isNull(); }