284 }
285
286 @Test
287 public void test_deprecated_remediation_function() {288 String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>"289 + " <description>Desc</description>"290 + " <effortToFixDescription>lines</effortToFixDescription>"291 + " <debtRemediationFunction>LINEAR_OFFSET</debtRemediationFunction>"292 + " <debtRemediationFunctionCoefficient>2d 3h</debtRemediationFunctionCoefficient>"293 + " <debtRemediationFunctionOffset>5min</debtRemediationFunctionOffset>" + " </rule>"294 + "</rules>";295 RulesDefinition.Rule rule = load(xml).rule("1");296 assertThat(rule.gapDescription()).isEqualTo("lines");297 DebtRemediationFunction function = rule.debtRemediationFunction();298 assertThat(function).isNotNull();299 assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);300 assertThat(function.gapMultiplier()).isEqualTo("2d3h");301 assertThat(function.baseEffort()).isEqualTo("5min");302 }303
304 private RulesDefinition.Repository load(InputStream input, String encoding) {
305 RulesDefinition.Context context = new RulesDefinitionContext();
270 }
271
272 @Test
273 public void fail_if_unsupported_description_format() {274 String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>"275 + " <description>Desc</description>" + " <descriptionFormat>UNKNOWN</descriptionFormat>"276 + " </rule>" + "</rules>";277278 assertThatThrownBy(() -> load(xml).rule("1"))279 .isInstanceOf(IllegalStateException.class)280 .hasMessage("Fail to load the rule with key [squid:1]")281 .hasCauseInstanceOf(IllegalArgumentException.class)282 .hasRootCauseMessage(283 "No enum constant org.sonar.cxx.sensors.utils.RulesDefinitionXmlLoader.DescriptionFormat.UNKNOWN");284 }285
286 @Test
287 public void test_deprecated_remediation_function() {
260 }
261
262 @Test
263 public void markdown_description() {264 String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>"265 + " <description>Desc</description>" + " <descriptionFormat>MARKDOWN</descriptionFormat>"266 + " </rule>" + "</rules>";267 RulesDefinition.Rule rule = load(xml).rule("1");268 assertThat(rule.markdownDescription()).isEqualTo("Desc");269 assertThat(rule.htmlDescription()).isNull();270 }271
272 @Test
273 public void fail_if_unsupported_description_format() {
248 }
249
250 @Test
251 public void fail_if_invalid_remediation_function() {252 assertThatThrownBy(() -> load("" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>"253 + " <description>Desc</description>"254 + " <remediationFunction>UNKNOWN</remediationFunction>" + " </rule>"255 + "</rules>"))256 .isInstanceOf(IllegalStateException.class)257 .hasMessage("Fail to load the rule with key [squid:1]")258 .hasCauseInstanceOf(IllegalArgumentException.class)259 .hasRootCauseMessage("No enum constant org.sonar.api.server.debt.DebtRemediationFunction.Type.UNKNOWN");260 }261
262 @Test
263 public void markdown_description() {
233 }
234
235 @Test
236 public void test_constant_remediation_function() {237 String xml = "" + "<rules>" + " <rule>" + " <key>1</key>" + " <name>One</name>"238 + " <description>Desc</description>"239 + " <remediationFunction>CONSTANT_ISSUE</remediationFunction>"240 + " <remediationFunctionBaseEffort>5min</remediationFunctionBaseEffort>" + " </rule>"241 + "</rules>";242 RulesDefinition.Rule rule = load(xml).rule("1");243 DebtRemediationFunction function = rule.debtRemediationFunction();244 assertThat(function).isNotNull();245 assertThat(function.type()).isEqualTo(DebtRemediationFunction.Type.CONSTANT_ISSUE);246 assertThat(function.gapMultiplier()).isNull();247 assertThat(function.baseEffort()).isEqualTo("5min");248 }249
250 @Test
251 public void fail_if_invalid_remediation_function() {
JUnit5 test classes and methods should be package-private.
Unlike JUnit4 which required all the test classes and methods to be declared public
, in JUnit5 they can be anything but private
.
To enforce maximum encapsulation, it is recommended to declare test classes and methods as package-private.
public class MyTest {
@Test
public void testThis() {
// ..test things
}
}
Consider making your test classes and methods package-private.
class MyTest {
@Test
void testThis() {
// ..test things
}
}