fillRemediationFunction(rule, debtRemediationFunction, debtRemediationFunctionGapMultiplier, debtRemediationFunctionBaseEffort);
fillParams(rule, params);
} catch (Exception e) {
- throw new IllegalArgumentException(format("Fail to load the rule with key [%s:%s]", repo.key(), key), e);
+ throw new IllegalStateException(format("Fail to load the rule with key [%s:%s]", repo.key(), key), e);
}
}
import org.sonar.api.server.debt.DebtRemediationFunction;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.fail;
+import static org.sonar.test.ExceptionCauseMatcher.hasType;
public class RulesDefinitionXmlLoaderTest {
@Test
public void fail_if_invalid_remediation_function() {
- try {
- load("" +
- "<rules>" +
- " <rule>" +
- " <key>1</key>" +
- " <name>One</name>" +
- " <description>Desc</description>" +
- " <remediationFunction>UNKNOWN</remediationFunction>" +
- " </rule>" +
- "</rules>");
- fail();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageContaining("Fail to load the rule with key [squid:1]");
- assertThat(e.getCause()).hasMessageContaining("No enum constant org.sonar.api.server.debt.DebtRemediationFunction.Type.UNKNOWN");
- }
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Fail to load the rule with key [squid:1]");
+ expectedException.expectCause(hasType(IllegalArgumentException.class)
+ .andMessage("No enum constant org.sonar.api.server.debt.DebtRemediationFunction.Type.UNKNOWN"));
+
+ load("" +
+ "<rules>" +
+ " <rule>" +
+ " <key>1</key>" +
+ " <name>One</name>" +
+ " <description>Desc</description>" +
+ " <remediationFunction>UNKNOWN</remediationFunction>" +
+ " </rule>" +
+ "</rules>");
}
@Test
@Test
public void fail_if_unsupported_description_format() {
- try {
- String xml = "" +
- "<rules>" +
- " <rule>" +
- " <key>1</key>" +
- " <name>One</name>" +
- " <description>Desc</description>" +
- " <descriptionFormat>UNKNOWN</descriptionFormat>" +
- " </rule>" +
- "</rules>";
- RulesDefinition.Rule rule = load(xml).rule("1");
- assertThat(rule.markdownDescription()).isEqualTo("Desc");
- assertThat(rule.htmlDescription()).isNull();
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageContaining("Fail to load the rule with key [squid:1]");
- assertThat(e.getCause()).hasMessageContaining("No enum constant org.sonar.api.server.rule.RulesDefinitionXmlLoader.DescriptionFormat.UNKNOWN");
- }
+ String xml = "" +
+ "<rules>" +
+ " <rule>" +
+ " <key>1</key>" +
+ " <name>One</name>" +
+ " <description>Desc</description>" +
+ " <descriptionFormat>UNKNOWN</descriptionFormat>" +
+ " </rule>" +
+ "</rules>";
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Fail to load the rule with key [squid:1]");
+ expectedException.expectCause(hasType(IllegalArgumentException.class)
+ .andMessage("No enum constant org.sonar.api.server.rule.RulesDefinitionXmlLoader.DescriptionFormat.UNKNOWN"));
+
+ load(xml).rule("1");
}
@Test