public void set(Collection<ActiveRule> activeRules) {
    requireNonNull(activeRules, "Active rules cannot be null");
    checkState(activeRulesByKey == null, "Active rules have already been initialized");

    Map<RuleKey, ActiveRule> temp = new HashMap<>();
    for (ActiveRule activeRule : activeRules) {
      ActiveRule previousValue = temp.put(activeRule.getRuleKey(), activeRule);
      if (previousValue != null) {
        throw new IllegalArgumentException("Active rule must not be declared multiple times: " + activeRule.getRuleKey());
      }
    }
    activeRulesByKey = ImmutableMap.copyOf(temp);
  }
@Test
  public void can_not_set_duplicated_rules() {
    assertThatThrownBy(() -> {
      underTest.set(asList(
        new ActiveRule(RULE_KEY, Severity.BLOCKER, Collections.emptyMap(), SOME_DATE, PLUGIN_KEY, QP_KEY),
        new ActiveRule(RULE_KEY, Severity.MAJOR, Collections.emptyMap(), SOME_DATE, PLUGIN_KEY, QP_KEY)));
    })
      .isInstanceOf(IllegalArgumentException.class)
      .hasMessage("Active rule must not be declared multiple times: java:S001");
  }