]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5056 Remove useless static creation methods
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 24 Mar 2014 12:50:21 +0000 (13:50 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Mon, 24 Mar 2014 12:50:21 +0000 (13:50 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DefaultDebtRemediationFunction.java
sonar-plugin-api/src/main/java/org/sonar/api/server/rule/DefaultDebtRemediationFunctions.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/DefaultDebtRemediationFunctionTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionTest.java

index a5bda3a8f25bc68b605616d280d160ecf711decd..dedf5a3e60c8d1f0aa512f228b6622aee3adfa92 100644 (file)
@@ -35,7 +35,7 @@ class DefaultDebtRemediationFunction implements DebtRemediationFunction {
   private String factor;
   private String offset;
 
-  private DefaultDebtRemediationFunction(Type type, @Nullable String factor, @Nullable String offset) {
+  public DefaultDebtRemediationFunction(Type type, @Nullable String factor, @Nullable String offset) {
     this.type = type;
     // TODO validate factor and offset format
     this.factor = StringUtils.deleteWhitespace(factor);
@@ -43,31 +43,18 @@ class DefaultDebtRemediationFunction implements DebtRemediationFunction {
     validate();
   }
 
-  static DebtRemediationFunction create(Type type, @Nullable String factor, @Nullable String offset) {
-    return new DefaultDebtRemediationFunction(type, factor, offset);
-  }
-
-  static DebtRemediationFunction createLinear(String factor) {
-    return new DefaultDebtRemediationFunction(Type.LINEAR, factor, null);
-  }
-
-  static DebtRemediationFunction createLinearWithOffset(String factor, String offset) {
-    return new DefaultDebtRemediationFunction(Type.LINEAR_OFFSET, factor, offset);
-  }
-
-  static DebtRemediationFunction createConstantPerIssue(String offset) {
-    return new DefaultDebtRemediationFunction(Type.CONSTANT_ISSUE, null, offset);
-  }
-
+  @Override
   public Type type() {
     return type;
   }
 
+  @Override
   @CheckForNull
   public String factor() {
     return factor;
   }
 
+  @Override
   @CheckForNull
   public String offset() {
     return offset;
index 3c529e73b57d84e5cc27b376a0e035ff770063b1..befa7907095172d4f27957c7eb02e6b02c3277cf 100644 (file)
@@ -50,7 +50,7 @@ class DefaultDebtRemediationFunctions implements DebtRemediationFunctions {
 
   private DebtRemediationFunction create(DefaultDebtRemediationFunction.Type type, @Nullable String factor, @Nullable String offset) {
     try {
-      return DefaultDebtRemediationFunction.create(type, factor, offset);
+      return new DefaultDebtRemediationFunction(type, factor, offset);
     } catch (DefaultDebtRemediationFunction.ValidationException e) {
       throw MessageException.of(String.format("The rule '%s:%s' is invalid : %s ", this.repoKey, this.key, e.getMessage()));
     }
index e504ee5c55797162fc11e9d22328997a45f96cb1..5f1b5ae57ec0c50b686da40fe9164208b1a070c0 100644 (file)
@@ -29,7 +29,7 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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();
@@ -37,7 +37,7 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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");
@@ -45,7 +45,7 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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");
@@ -53,7 +53,7 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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");
@@ -62,7 +62,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -72,7 +72,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -82,7 +82,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -92,7 +92,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -102,7 +102,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -112,7 +112,7 @@ public class DefaultDebtRemediationFunctionTest {
   @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);
@@ -121,17 +121,18 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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());
@@ -140,7 +141,7 @@ public class DefaultDebtRemediationFunctionTest {
 
   @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();
   }
 
 }
index 665b1c87d2507251387bf88fd7a408e8efc85f74..5a9f2511c126e92f1fa484638eebe494642f863c 100644 (file)
@@ -64,17 +64,18 @@ public class RulesDefinitionTest {
   @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();
 
@@ -92,7 +93,9 @@ public class RulesDefinitionTest {
     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);
@@ -310,9 +313,9 @@ public class RulesDefinitionTest {
   @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();