public RuleRestResponse toRuleRestResponse(RuleInformation ruleInformation) {

    RuleRestResponse.Builder builder = RuleRestResponse.Builder.builder();
    RuleDto ruleDto = ruleInformation.ruleDto();
    builder
      .setId(ruleDto.getUuid())
      .setKey(ruleDto.getKey().toString())
      .setRepositoryKey(ruleDto.getRepositoryKey())
      .setName(ruleDto.getName())
      .setSeverity(ruleDto.getSeverityString())
      .setType(RuleTypeRestEnum.from(RuleType.valueOf(ruleDto.getType())))
      .setImpacts(toImpactRestResponse(ruleDto.getDefaultImpacts()))
      .setCleanCodeAttribute(CleanCodeAttributeRestEnum.from(ruleDto.getCleanCodeAttribute()))
      .setCleanCodeAttributeCategory(ofNullable(ruleDto.getCleanCodeAttribute())
        .map(CleanCodeAttribute::getAttributeCategory)
        .map(CleanCodeAttributeCategoryRestEnum::from)
        .orElse(null))
      .setStatus(RuleStatusRestEnum.from(ruleDto.getStatus()))
      .setExternal(ruleDto.isExternal())
      .setCreatedAt(toDateTime(ruleDto.getCreatedAt()))
      .setGapDescription(ruleDto.getGapDescription())
      .setHtmlNote(ofNullable(ruleDto.getNoteData()).map(n -> macroInterpreter.interpret(Markdown.convertToHtml(n))).orElse(null))
      .setMarkdownNote(ruleDto.getNoteData())
      .setEducationPrinciples(new ArrayList<>(ruleDto.getEducationPrinciples()))
      .setTemplate(ruleDto.isTemplate())
      .setTemplateId(ruleDto.getTemplateUuid())
      .setTags(new ArrayList<>(ruleDto.getTags()))
      .setSystemTags(new ArrayList<>(ruleDto.getSystemTags()))
      .setLanguageKey(ruleDto.getLanguage())
      .setLanguageName(getLanguageName(ruleDto.getLanguage()))
      .setParameters(toRuleParameterResponse(ruleInformation.params()));

    setDescriptionFields(builder, ruleDto);
    setRemediationFunctionFields(builder, ruleDto);

    if (ruleDto.isAdHoc()) {
      ofNullable(ruleDto.getAdHocName()).ifPresent(builder::setName);
      ofNullable(ruleDto.getAdHocDescription())
        .map(this::toDescriptionSectionResponse)
        .ifPresent(section -> builder.setDescriptionSections(List.of(section)));
      ofNullable(ruleDto.getAdHocSeverity()).ifPresent(builder::setSeverity);
      ofNullable(ruleDto.getAdHocType()).ifPresent(type -> builder.setType(RuleTypeRestEnum.from(RuleType.valueOf(type))));
    }
    return builder.build();
  }
@Test
  public void toRuleRestResponse_shouldReturnSameFieldForStandardMapping() {
    when(macroInterpreter.interpret(Mockito.anyString())).thenAnswer(invocation -> "interpreted" + invocation.getArgument(0));
    when(ruleDescriptionFormatter.toHtml(any(), any())).thenAnswer(invocation -> "html" + ((RuleDescriptionSectionDto) invocation.getArgument(1)).getContent());

    RuleDto dto = RuleTesting.newRule();
    when(languages.get(dto.getLanguage())).thenReturn(LanguageTesting.newLanguage(dto.getLanguage(), "languageName"));

    RuleRestResponse ruleRestResponse = ruleRestResponseGenerator.toRuleRestResponse(new RuleInformation(dto, List.of()));
    assertThat(ruleRestResponse.id()).isEqualTo(dto.getUuid());
    assertThat(ruleRestResponse.key()).isEqualTo(dto.getKey().toString());
    assertThat(ruleRestResponse.repositoryKey()).isEqualTo(dto.getRepositoryKey());
    assertThat(ruleRestResponse.name()).isEqualTo(dto.getName());
    assertThat(ruleRestResponse.descriptionSections()).extracting(s -> s.key(), s -> s.content(), s -> s.context())
      .containsExactly(dto.getRuleDescriptionSectionDtos().stream().map(s -> tuple(s.getKey(), "interpreted" + "html" + s.getContent(), s.getContext())).toArray(Tuple[]::new));
    assertThat(ruleRestResponse.severity()).isEqualTo(dto.getSeverityString());
    assertThat(ruleRestResponse.type().name()).isEqualTo(RuleType.valueOf(dto.getType()).name());
    assertThat(ruleRestResponse.impacts()).extracting(r -> r.severity().name(), r -> r.softwareQuality().name())
      .containsExactly(dto.getDefaultImpacts().stream().map(e -> tuple(e.getSeverity().name(), e.getSoftwareQuality().name())).toArray(Tuple[]::new));
    assertThat(ruleRestResponse.cleanCodeAttribute().name()).isEqualTo(dto.getCleanCodeAttribute().name());
    assertThat(ruleRestResponse.cleanCodeAttributeCategory().name()).isEqualTo(dto.getCleanCodeAttribute().getAttributeCategory().name());
    assertThat(ruleRestResponse.status().name()).isEqualTo(dto.getStatus().name());
    assertThat(ruleRestResponse.external()).isEqualTo(dto.isExternal());
    assertThat(ruleRestResponse.createdAt()).isEqualTo(DateUtils.formatDateTime(dto.getCreatedAt()));
    assertThat(ruleRestResponse.gapDescription()).isEqualTo(dto.getGapDescription());
    assertThat(ruleRestResponse.markdownNote()).isEqualTo(dto.getNoteData());
    assertThat(ruleRestResponse.educationPrinciples()).containsExactlyElementsOf(dto.getEducationPrinciples());
    assertThat(ruleRestResponse.template()).isEqualTo(dto.isTemplate());
    assertThat(ruleRestResponse.templateId()).isEqualTo(dto.getTemplateUuid());
    assertThat(ruleRestResponse.tags()).containsExactlyElementsOf(dto.getTags());
    assertThat(ruleRestResponse.systemTags()).containsExactlyElementsOf(dto.getSystemTags());
    assertThat(ruleRestResponse.languageKey()).isEqualTo(dto.getLanguage());
    assertThat(ruleRestResponse.languageName()).isEqualTo("languageName");

    DefaultDebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.valueOf(dto.getRemediationFunction().toUpperCase(Locale.ENGLISH)),
      dto.getRemediationGapMultiplier(),
      dto.getRemediationBaseEffort());
    assertThat(ruleRestResponse.remediationFunctionBaseEffort()).isEqualTo(function.baseEffort());
    assertThat(ruleRestResponse.remediationFunctionGapMultiplier()).isEqualTo(function.gapMultiplier());
    assertThat(ruleRestResponse.remediationFunctionType()).isEqualTo(dto.getRemediationFunction());
  }