@Test
  public void update_manual_rule() {
    // Create manual rule
    RuleDto manualRule =
        RuleTesting.newManualRule("My manual")
            .setName("Old name")
            .setDescription("Old description")
            .setSeverity(Severity.INFO);
    ruleDao.insert(dbSession, manualRule);

    dbSession.commit();

    // Update manual rule
    RuleUpdate update =
        RuleUpdate.createForManualRule(manualRule.getKey())
            .setName("New name")
            .setMarkdownDescription("New description")
            .setSeverity(Severity.CRITICAL);
    updater.update(update, userSessionRule);

    dbSession.clearCache();

    // Verify manual rule is updated
    Rule manualRuleReloaded = ruleIndex.getByKey(manualRule.getKey());
    assertThat(manualRuleReloaded).isNotNull();
    assertThat(manualRuleReloaded.name()).isEqualTo("New name");
    assertThat(manualRuleReloaded.htmlDescription()).isEqualTo("New description");
    assertThat(manualRuleReloaded.severity()).isEqualTo(Severity.CRITICAL);
  }
  @Test
  public void fail_to_update_manual_rule_if_status_is_set() {
    // Create manual rule
    RuleDto manualRule = RuleTesting.newManualRule("My manual");
    ruleDao.insert(dbSession, manualRule);

    dbSession.commit();

    try {
      // Update manual rule
      RuleUpdate.createForManualRule(manualRule.getKey()).setStatus(RuleStatus.BETA);
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule");
    }
  }
  @Test
  public void fail_to_update_manual_rule_if_parameters_are_set() {
    // Create manual rule
    RuleDto manualRule = RuleTesting.newManualRule("My manual");
    ruleDao.insert(dbSession, manualRule);

    dbSession.commit();

    try {
      // Update manual rule
      RuleUpdate.createForManualRule(manualRule.getKey())
          .setStatus(RuleStatus.BETA)
          .setParameters(ImmutableMap.of("regex", "b.*", "message", "a message"));
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not a custom rule");
    }
  }