@Override
  public void publish(ScannerReportWriter writer) {
    final ScannerReport.ActiveRule.Builder builder = ScannerReport.ActiveRule.newBuilder();
    writer.writeActiveRules(activeRules.findAll().stream()
      .map(DefaultActiveRule.class::cast)
      .map(input -> {
        builder.clear();
        builder.setRuleRepository(input.ruleKey().repository());
        builder.setRuleKey(input.ruleKey().rule());
        builder.setSeverity(Constants.Severity.valueOf(input.severity()));
        builder.setCreatedAt(input.createdAt());
        builder.setUpdatedAt(input.updatedAt());
        builder.setQProfileKey(input.qpKey());
        builder.getMutableParamsByKey().putAll(input.params());
        return builder.build();
      }).toList());
  }
@Test
  public void write() throws Exception {
    File outputDir = temp.newFolder();
    FileStructure fileStructure = new FileStructure(outputDir);
    ScannerReportWriter writer = new ScannerReportWriter(fileStructure);

    NewActiveRule ar = new NewActiveRule.Builder()
      .setRuleKey(RuleKey.of("java", "S001"))
      .setSeverity("BLOCKER")
      .setParam("p1", "v1")
      .setCreatedAt(1_000L)
      .setUpdatedAt(2_000L)
      .setQProfileKey("qp1")
      .build();
    ActiveRules activeRules = new DefaultActiveRules(singletonList(ar));

    ActiveRulesPublisher underTest = new ActiveRulesPublisher(activeRules);
    underTest.publish(writer);

    ScannerReportReader reader = new ScannerReportReader(fileStructure);
    try (CloseableIterator<ScannerReport.ActiveRule> readIt = reader.readActiveRules()) {
      ScannerReport.ActiveRule reportAr = readIt.next();
      assertThat(reportAr.getRuleRepository()).isEqualTo("java");
      assertThat(reportAr.getRuleKey()).isEqualTo("S001");
      assertThat(reportAr.getSeverity()).isEqualTo(Constants.Severity.BLOCKER);
      assertThat(reportAr.getCreatedAt()).isEqualTo(1_000L);
      assertThat(reportAr.getUpdatedAt()).isEqualTo(2_000L);
      assertThat(reportAr.getQProfileKey()).isEqualTo("qp1");
      assertThat(reportAr.getParamsByKeyMap()).hasSize(1);
      assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getKey()).isEqualTo("p1");
      assertThat(reportAr.getParamsByKeyMap().entrySet().iterator().next().getValue()).isEqualTo("v1");

      assertThat(readIt.hasNext()).isFalse();
    }
  }