@Test
public void create_linear() throws Exception {
- DebtRemediationFunction function = DefaultDebtRemediationFunction.createLinear("10h");
+ DebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "10h", null);
assertThat(function.type()).isEqualTo(DefaultDebtRemediationFunction.Type.LINEAR);
assertThat(function.factor()).isEqualTo("10h");
assertThat(function.offset()).isNull();
@Test
public void create_linear_with_offset() throws Exception {
- DebtRemediationFunction function = DefaultDebtRemediationFunction.createLinearWithOffset("10h", "5min");
+ DebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "5min");
assertThat(function.type()).isEqualTo(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET);
assertThat(function.factor()).isEqualTo("10h");
assertThat(function.offset()).isEqualTo("5min");
@Test
public void create_constant_per_issue() throws Exception {
- DebtRemediationFunction function = DefaultDebtRemediationFunction.createConstantPerIssue("10h");
+ DebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "10h");
assertThat(function.type()).isEqualTo(DefaultDebtRemediationFunction.Type.CONSTANT_ISSUE);
assertThat(function.factor()).isNull();
assertThat(function.offset()).isEqualTo("10h");
@Test
public void sanitize_remediation_factor_and_offset() {
- DebtRemediationFunction function = DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, " 1 h ", " 10 mi n");
+ DebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, " 1 h ", " 10 mi n");
assertThat(function.factor()).isEqualTo("1h");
assertThat(function.offset()).isEqualTo("10min");
@Test
public void fail_to_create_linear_when_no_factor() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR, null, "10h");
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, null, "10h");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void fail_to_create_linear_when_offset() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR, "5min", "10h");
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "5min", "10h");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void fail_to_create_constant_per_issue_when_no_offset() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.CONSTANT_ISSUE, "10h", null);
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, "10h", null);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void fail_to_create_constant_per_issue_when_factor() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.CONSTANT_ISSUE, "5min", "10h");
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, "5min", "10h");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void fail_to_create_linear_with_offset_when_no_factor() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, null, "10h");
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, null, "10h");
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void fail_to_create_linear_with_offset_when_no_offset() throws Exception {
try {
- DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, "5min", null);
+ new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "5min", null);
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(DefaultDebtRemediationFunction.ValidationException.class);
@Test
public void test_equals_and_hashcode() throws Exception {
- DebtRemediationFunction function = DefaultDebtRemediationFunction.createLinearWithOffset("10h", "5min");
- DebtRemediationFunction functionWithSameValue = DefaultDebtRemediationFunction.createLinearWithOffset("10h", "5min");
- DebtRemediationFunction functionWithDifferentType = DefaultDebtRemediationFunction.createConstantPerIssue("5min");
+ DebtRemediationFunction function = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "5min");
+ DebtRemediationFunction functionWithSameValue = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "5min");
+ DebtRemediationFunction functionWithDifferentType = new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "5min");
assertThat(function).isEqualTo(function);
assertThat(function).isEqualTo(functionWithSameValue);
assertThat(function).isNotEqualTo(functionWithDifferentType);
- assertThat(function).isNotEqualTo(DefaultDebtRemediationFunction.createLinearWithOffset("11h", "5min"));
- assertThat(function).isNotEqualTo(DefaultDebtRemediationFunction.createLinearWithOffset("10h", "6min"));
- assertThat(function).isNotEqualTo(DefaultDebtRemediationFunction.createLinear("10h"));
- assertThat(function).isNotEqualTo(DefaultDebtRemediationFunction.createConstantPerIssue("6min"));
+
+ assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "11h", "5min"));
+ assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "6min"));
+ assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR, "10h", null));
+ assertThat(function).isNotEqualTo(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, "6min"));
assertThat(function.hashCode()).isEqualTo(function.hashCode());
assertThat(function.hashCode()).isEqualTo(functionWithSameValue.hashCode());
@Test
public void test_to_string() throws Exception {
- assertThat(DefaultDebtRemediationFunction.createLinearWithOffset("10h", "5min").toString()).isNotNull();
+ assertThat(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.LINEAR_OFFSET, "10h", "5min").toString()).isNotNull();
}
}
@Test
public void define_rules() {
RulesDefinition.NewRepository newFindbugs = context.createRepository("findbugs", "java");
- newFindbugs.createRule("NPE")
+ RulesDefinition.NewRule newFindbug = newFindbugs.createRule("NPE")
.setName("Detect NPE")
.setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
.setSeverity(Severity.BLOCKER)
.setInternalKey("/something")
.setStatus(RuleStatus.BETA)
.setDebtCharacteristic("COMPILER")
- .setDebtRemediationFunction(DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"))
.setEffortToFixDescription("squid.S115.effortToFix")
.setTags("one", "two")
.addTags("two", "three", "four");
+ newFindbug.setDebtRemediationFunction(newFindbug.debtRemediationFunctions().linearWithOffset("1h", "10min"));
+
newFindbugs.createRule("ABC").setName("ABC").setHtmlDescription("ABC");
newFindbugs.done();
assertThat(npeRule.template()).isFalse();
assertThat(npeRule.status()).isEqualTo(RuleStatus.BETA);
assertThat(npeRule.debtCharacteristic()).isEqualTo("COMPILER");
- assertThat(npeRule.debtRemediationFunction()).isEqualTo(DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"));
+ assertThat(npeRule.debtRemediationFunction().type()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET);
+ assertThat(npeRule.debtRemediationFunction().factor()).isEqualTo("1h");
+ assertThat(npeRule.debtRemediationFunction().offset()).isEqualTo("10min");
assertThat(npeRule.effortToFixDescription()).isEqualTo("squid.S115.effortToFix");
assertThat(npeRule.toString()).isEqualTo("[repository=findbugs, key=NPE]");
assertThat(npeRule.repository()).isSameAs(findbugs);
@Test
public void fail_if_define_function_without_characteristic() {
RulesDefinition.NewRepository newRepository = context.createRepository("findbugs", "java");
- newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
- .setDebtCharacteristic("")
- .setDebtRemediationFunction(DefaultDebtRemediationFunction.create(DefaultDebtRemediationFunction.Type.LINEAR_OFFSET, "1h", "10min"));
+ RulesDefinition.NewRule newRule = newRepository.createRule("NPE").setName("NPE").setHtmlDescription("Detect <code>java.lang.NullPointerException</code>")
+ .setDebtCharacteristic("");
+ newRule.setDebtRemediationFunction(newRule.debtRemediationFunctions().linearWithOffset("1h", "10min"));
try {
newRepository.done();
fail();