]> source.dussan.org Git - sonarqube.git/commitdiff
Simplify read of test files
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 26 Mar 2014 15:50:02 +0000 (16:50 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 26 Mar 2014 15:50:11 +0000 (16:50 +0100)
sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java
sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java
sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java

index a6b0bd3b8bb7f16ad87ec9753d0bdf4ab8c914ce..7dc0406ca64665efa07b75943f761a49db1a6296 100644 (file)
 
 package org.sonar.server.debt;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 import org.sonar.api.server.debt.DebtCharacteristic;
+import org.sonar.test.TestUtils;
 
-import java.io.IOException;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -35,7 +34,7 @@ import static org.sonar.server.debt.DebtModelXMLExporter.DebtModel;
 public class DebtCharacteristicsXMLImporterTest {
 
   @Test
-  public void import_characteristics() {
+  public void import_characteristics() throws Exception {
     String xml = getFileContent("import_characteristics.xml");
 
     DebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml);
@@ -64,7 +63,7 @@ public class DebtCharacteristicsXMLImporterTest {
   }
 
   @Test
-  public void import_badly_formatted_xml() {
+  public void import_badly_formatted_xml() throws Exception {
     String xml = getFileContent("import_badly_formatted_xml.xml");
 
     DebtModel debtModel = new DebtCharacteristicsXMLImporter().importXML(xml);
@@ -85,7 +84,7 @@ public class DebtCharacteristicsXMLImporterTest {
   }
 
   @Test
-  public void fail_on_bad_xml() {
+  public void fail_on_bad_xml() throws Exception {
     String xml = getFileContent("fail_on_bad_xml.xml");
 
     try {
@@ -96,12 +95,8 @@ public class DebtCharacteristicsXMLImporterTest {
     }
   }
 
-  private String getFileContent(String file) {
-    try {
-      return Resources.toString(Resources.getResource(this.getClass(), this.getClass().getSimpleName() + "/" + file), Charsets.UTF_8);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
+  private String getFileContent(String file) throws Exception {
+    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
   }
 
 }
index 9ed00f331f9f7520f75066049506fc840a6f08a7..21e3dc00855b3ba6fcae40059f751d28b3b6341b 100644 (file)
@@ -19,8 +19,7 @@
  */
 package org.sonar.server.debt;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.junit.Before;
 import org.junit.Test;
@@ -29,7 +28,6 @@ import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
 import org.sonar.test.TestUtils;
 
-import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
 import java.util.regex.Pattern;
@@ -132,11 +130,7 @@ public class DebtModelXMLExporterTest {
     );
   }
 
-  private String getFileContent(String file) {
-    try {
-      return Resources.toString(Resources.getResource(this.getClass(), this.getClass().getSimpleName() + "/" + file), Charsets.UTF_8);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
+  private String getFileContent(String file) throws Exception {
+    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
   }
 }
index edbc348a873b347ca910c36ecf0dc10b7ae8a02c..f2aba19ac157d7c874193110087309ba567cc982 100644 (file)
 
 package org.sonar.server.debt;
 
-import com.google.common.base.Charsets;
-import com.google.common.io.Resources;
+import org.apache.commons.io.IOUtils;
 import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.utils.ValidationMessages;
+import org.sonar.test.TestUtils;
 
-import java.io.IOException;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
@@ -40,7 +39,7 @@ public class DebtRulesXMLImporterTest {
   DebtRulesXMLImporter importer = new DebtRulesXMLImporter();
 
   @Test
-  public void import_rules() {
+  public void import_rules() throws Exception {
     String xml = getFileContent("import_rules.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -51,7 +50,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void import_linear() {
+  public void import_linear() throws Exception {
     String xml = getFileContent("import_linear.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -66,7 +65,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void import_linear_having_offset_to_zero() {
+  public void import_linear_having_offset_to_zero() throws Exception {
     String xml = getFileContent("import_linear_having_offset_to_zero.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -81,7 +80,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void import_linear_with_offset() {
+  public void import_linear_with_offset() throws Exception {
     String xml = getFileContent("import_linear_with_offset.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -95,7 +94,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void import_constant_issue() {
+  public void import_constant_issue() throws Exception {
     String xml = getFileContent("import_constant_issue.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -109,7 +108,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void use_default_unit_when_no_unit() {
+  public void use_default_unit_when_no_unit() throws Exception {
     String xml = getFileContent("use_default_unit_when_no_unit.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -123,7 +122,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void replace_mn_by_min() {
+  public void replace_mn_by_min() throws Exception {
     String xml = getFileContent("replace_mn_by_min.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -137,7 +136,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void read_integer() {
+  public void read_integer() throws Exception {
     String xml = getFileContent("read_integer.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -152,7 +151,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void convert_deprecated_linear_with_threshold_function_by_linear_function() {
+  public void convert_deprecated_linear_with_threshold_function_by_linear_function() throws Exception {
     String xml = getFileContent("convert_deprecated_linear_with_threshold_function_by_linear_function.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -168,7 +167,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset() {
+  public void convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset() throws Exception {
     String xml = getFileContent("convert_constant_per_issue_with_coefficient_by_constant_per_issue_with_offset.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -182,7 +181,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void ignore_deprecated_constant_per_file_function() {
+  public void ignore_deprecated_constant_per_file_function() throws Exception {
     String xml = getFileContent("ignore_deprecated_constant_per_file_function.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -192,7 +191,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void ignore_rule_on_root_characteristics() {
+  public void ignore_rule_on_root_characteristics() throws Exception {
     String xml = getFileContent("ignore_rule_on_root_characteristics.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -202,7 +201,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void import_badly_formatted_xml() {
+  public void import_badly_formatted_xml() throws Exception {
     String xml = getFileContent("import_badly_formatted_xml.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
@@ -226,7 +225,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   @Test
-  public void fail_on_bad_xml() {
+  public void fail_on_bad_xml() throws Exception {
     String xml = getFileContent("fail_on_bad_xml.xml");
 
     try {
@@ -237,12 +236,7 @@ public class DebtRulesXMLImporterTest {
     }
   }
 
-  private String getFileContent(String file) {
-    try {
-      return Resources.toString(Resources.getResource(DebtRulesXMLImporterTest.class, "DebtRulesXMLImporterTest/" + file), Charsets.UTF_8);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
+  private String getFileContent(String file) throws Exception {
+    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
   }
-
 }