public boolean initAndAddIssue(Issue issue) {
    DefaultInputComponent inputComponent = (DefaultInputComponent) issue.primaryLocation().inputComponent();

    if (noSonar(inputComponent, issue)) {
      return false;
    }

    ActiveRule activeRule = activeRules.find(issue.ruleKey());
    if (activeRule == null) {
      // rule does not exist or is not enabled -> ignore the issue
      return false;
    }

    ScannerReport.Issue rawIssue = createReportIssue(issue, inputComponent.scannerId(), activeRule.severity());

    if (filters.accept(inputComponent, rawIssue)) {
      write(inputComponent.scannerId(), rawIssue);
      return true;
    }
    return false;
  }
@Test
  public void add_issue_to_cache() {
    initModuleIssues();

    final String ruleDescriptionContextKey = "spring";
    DefaultIssue issue = new DefaultIssue(project)
      .at(new DefaultIssueLocation().on(file).at(file.selectLine(3)).message("Foo"))
      .forRule(JAVA_RULE_KEY)
      .overrideSeverity(org.sonar.api.batch.rule.Severity.CRITICAL)
      .setQuickFixAvailable(true)
      .setRuleDescriptionContextKey(ruleDescriptionContextKey)
      .setCodeVariants(List.of("variant1", "variant2"))
      .overrideImpact(MAINTAINABILITY, org.sonar.api.issue.impact.Severity.HIGH)
      .overrideImpact(RELIABILITY, org.sonar.api.issue.impact.Severity.LOW);

    when(filters.accept(any(InputComponent.class), any(ScannerReport.Issue.class))).thenReturn(true);

    boolean added = moduleIssues.initAndAddIssue(issue);

    assertThat(added).isTrue();
    ArgumentCaptor<ScannerReport.Issue> argument = ArgumentCaptor.forClass(ScannerReport.Issue.class);
    verify(reportPublisher.getWriter()).appendComponentIssue(eq(file.scannerId()), argument.capture());
    assertThat(argument.getValue().getSeverity()).isEqualTo(org.sonar.scanner.protocol.Constants.Severity.CRITICAL);
    assertThat(argument.getValue().getQuickFixAvailable()).isTrue();
    assertThat(argument.getValue().getRuleDescriptionContextKey()).isEqualTo(ruleDescriptionContextKey);
    assertThat(argument.getValue().getCodeVariantsList()).containsExactly("variant1", "variant2");

    ScannerReport.Impact impact1 = ScannerReport.Impact.newBuilder().setSoftwareQuality(MAINTAINABILITY.name()).setSeverity("HIGH").build();
    ScannerReport.Impact impact2 = ScannerReport.Impact.newBuilder().setSoftwareQuality(RELIABILITY.name()).setSeverity("LOW").build();
    assertThat(argument.getValue().getOverridenImpactsList()).containsExactly(impact1, impact2);
  }