]> source.dussan.org Git - sonarqube.git/commitdiff
Remove some usage of TestUtils
authorSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 18:29:35 +0000 (20:29 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Wed, 23 Apr 2014 18:29:35 +0000 (20:29 +0200)
18 files changed:
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java
sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java
sonar-server/pom.xml
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
sonar-server/src/test/java/org/sonar/server/es/ESNodeTest.java
sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java
sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java
sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/ESActiveRuleTest.java
sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java
sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java
sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java
sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java

index b94c87630d99da5269f67dbac893f0855c61e4c4..02e00bacb0a03236cc645a2188aacbe7cdc73ed2 100644 (file)
@@ -19,6 +19,8 @@
  */
 package org.sonar.plugins.core.issue.notification;
 
+import com.google.common.io.Resources;
+import org.apache.commons.codec.Charsets;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
 import org.junit.Test;
@@ -30,7 +32,6 @@ import org.sonar.api.notifications.Notification;
 import org.sonar.api.user.User;
 import org.sonar.api.user.UserFinder;
 import org.sonar.plugins.emailnotifications.api.EmailMessage;
-import org.sonar.test.TestUtils;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -69,9 +70,12 @@ public class IssueChangesEmailTemplateTest {
     assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
 
     String message = email.getMessage();
-    String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt");
-    expectedMessage = StringUtils.remove(expectedMessage, '\r');
-    assertThat(message).isEqualTo(expectedMessage);
+    String expected = Resources.toString(Resources.getResource(
+        "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"),
+      Charsets.UTF_8
+    );
+    expected = StringUtils.remove(expected, '\r');
+    assertThat(message).isEqualTo(expected);
     assertThat(email.getFrom()).isNull();
   }
 
@@ -86,14 +90,17 @@ public class IssueChangesEmailTemplateTest {
     assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
 
     String message = email.getMessage();
-    String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt");
-    expectedMessage = StringUtils.remove(expectedMessage, '\r');
-    assertThat(message).isEqualTo(expectedMessage);
+    String expected = Resources.toString(Resources.getResource(
+        "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt"),
+      Charsets.UTF_8
+    );
+    expected = StringUtils.remove(expected, '\r');
+    assertThat(message).isEqualTo(expected);
     assertThat(email.getFrom()).isNull();
   }
 
   @Test
-  public void test_email_with_multiple_changes() {
+  public void test_email_with_multiple_changes() throws Exception {
     Notification notification = generateNotification()
       .setFieldValue("comment", "How to fix it?")
       .setFieldValue("old.assignee", "simon")
@@ -106,9 +113,10 @@ public class IssueChangesEmailTemplateTest {
     assertThat(email.getSubject()).isEqualTo("Struts, change on issue #ABCDE");
 
     String message = email.getMessage();
-    String expectedMessage = TestUtils.getResourceContent("/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt");
-    expectedMessage = StringUtils.remove(expectedMessage, '\r');
-    assertThat(message).isEqualTo(expectedMessage);
+    String expected = Resources.toString(Resources.getResource(
+      "org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), Charsets.UTF_8);
+    expected = StringUtils.remove(expected, '\r');
+    assertThat(message).isEqualTo(expected);
     assertThat(email.getFrom()).isNull();
   }
 
index 0592c2158d45037396f65111f9e37477cd33d72c..2e29bf1f8e2ca50f239e93f26f79a78158472126 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.batch.bootstrap;
 
+import com.google.common.io.Resources;
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
 import org.junit.Before;
@@ -30,7 +31,6 @@ import org.sonar.api.config.Settings;
 import org.sonar.core.plugins.RemotePlugin;
 import org.sonar.home.cache.FileCache;
 import org.sonar.home.cache.FileCacheBuilder;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -65,7 +65,7 @@ public class BatchPluginRepositoryTest {
   }
 
   @Test
-  public void shouldLoadPlugin() throws IOException {
+  public void shouldLoadPlugin() throws Exception {
     RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
 
     PluginDownloader downloader = mock(PluginDownloader.class);
@@ -82,7 +82,7 @@ public class BatchPluginRepositoryTest {
   }
 
   @Test
-  public void shouldLoadPluginExtension() throws IOException {
+  public void shouldLoadPluginExtension() throws Exception {
     RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
     RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
 
@@ -102,7 +102,7 @@ public class BatchPluginRepositoryTest {
   }
 
   @Test
-  public void shouldExcludePluginAndItsExtensions() throws IOException {
+  public void shouldExcludePluginAndItsExtensions() throws Exception {
     RemotePlugin checkstyle = new RemotePlugin("checkstyle", true);
     RemotePlugin checkstyleExt = new RemotePlugin("checkstyleextensions", false);
 
@@ -119,8 +119,8 @@ public class BatchPluginRepositoryTest {
     assertThat(repository.getMetadata()).isEmpty();
   }
 
-  private File fileFromCache(String filename) throws IOException {
-    File file = TestUtils.getResource("/org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename);
+  private File fileFromCache(String filename) throws Exception {
+    File file = new File(Resources.getResource("org/sonar/batch/bootstrap/BatchPluginRepositoryTest/" + filename).toURI());
     File destDir = new File(userHome, "cache/foomd5");
     FileUtils.forceMkdir(destDir);
     FileUtils.copyFileToDirectory(file, destDir);
index e5815b8928669655f4c345a06c71176a268498cb..10d5241c5a32c74af25671548caf8672e7945a03 100644 (file)
 
 package org.sonar.batch.issue.ignore.scanner;
 
-import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer;
-import org.sonar.batch.issue.ignore.pattern.IssuePattern;
-import org.sonar.batch.issue.ignore.pattern.LineRange;
-import org.sonar.batch.issue.ignore.pattern.PatternMatcher;
-import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner;
-
 import com.google.common.collect.Sets;
+import com.google.common.io.Resources;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonar.test.TestUtils;
+import org.sonar.batch.issue.ignore.pattern.IssueExclusionPatternInitializer;
+import org.sonar.batch.issue.ignore.pattern.IssuePattern;
+import org.sonar.batch.issue.ignore.pattern.LineRange;
+import org.sonar.batch.issue.ignore.pattern.PatternMatcher;
 
-import java.io.IOException;
+import java.io.File;
 import java.util.Arrays;
 import java.util.Set;
 
@@ -80,15 +78,17 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldDoNothing() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-no-regexp.txt"), UTF_8);
+  public void shouldDoNothing() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-no-regexp.txt").toURI()), UTF_8);
 
     verifyNoMoreInteractions(patternsInitializer);
   }
 
   @Test
-  public void shouldAddPatternToExcludeFile() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-single-regexp.txt"), UTF_8);
+  public void shouldAddPatternToExcludeFile() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp.txt").toURI()), UTF_8);
 
     verify(patternsInitializer).getPatternMatcher();
     verify(patternMatcher, times(1)).addPatternToExcludeResource(javaFile);
@@ -96,8 +96,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeFileEvenIfAlsoDoubleRegexps() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-single-regexp-and-double-regexp.txt"), UTF_8);
+  public void shouldAddPatternToExcludeFileEvenIfAlsoDoubleRegexps() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-single-regexp-and-double-regexp.txt").toURI()), UTF_8);
 
     verify(patternsInitializer).getPatternMatcher();
     verify(patternMatcher, times(1)).addPatternToExcludeResource(javaFile);
@@ -105,8 +106,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeLines() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp.txt"), UTF_8);
+  public void shouldAddPatternToExcludeLines() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp.txt").toURI()), UTF_8);
 
     Set<LineRange> lineRanges = Sets.newHashSet();
     lineRanges.add(new LineRange(21, 25));
@@ -116,8 +118,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeLinesTillTheEnd() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-unfinished.txt"), UTF_8);
+  public void shouldAddPatternToExcludeLinesTillTheEnd() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-unfinished.txt").toURI()), UTF_8);
 
     Set<LineRange> lineRanges = Sets.newHashSet();
     lineRanges.add(new LineRange(21, 34));
@@ -127,8 +130,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeSeveralLineRanges() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-twice.txt"), UTF_8);
+  public void shouldAddPatternToExcludeSeveralLineRanges() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-twice.txt").toURI()), UTF_8);
 
     Set<LineRange> lineRanges = Sets.newHashSet();
     lineRanges.add(new LineRange(21, 25));
@@ -139,8 +143,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeLinesWithWrongOrder() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-wrong-order.txt"), UTF_8);
+  public void shouldAddPatternToExcludeLinesWithWrongOrder() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-wrong-order.txt").toURI()), UTF_8);
 
     Set<LineRange> lineRanges = Sets.newHashSet();
     lineRanges.add(new LineRange(25, 35));
@@ -150,8 +155,9 @@ public class IssueExclusionsRegexpScannerTest {
   }
 
   @Test
-  public void shouldAddPatternToExcludeLinesWithMess() throws IOException {
-    regexpScanner.scan(javaFile, TestUtils.getResource(getClass(), "file-with-double-regexp-mess.txt"), UTF_8);
+  public void shouldAddPatternToExcludeLinesWithMess() throws Exception {
+    regexpScanner.scan(javaFile, new File(Resources.getResource(
+      "org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest/file-with-double-regexp-mess.txt").toURI()), UTF_8);
 
     Set<LineRange> lineRanges = Sets.newHashSet();
     lineRanges.add(new LineRange(21, 29));
index be1fd2cfe3ea98bea4d25c7245006d8f15362ada..e9b449a63a4c569b2637a107963630d8997379a2 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.batch.maven;
 
+import com.google.common.io.Resources;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
@@ -30,7 +31,6 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -119,7 +119,7 @@ public class MavenProjectConverterTest {
 
   @Test
   public void moduleNameShouldEqualArtifactId() throws Exception {
-    File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/");
+    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/").toURI());
     MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/pom.xml", true);
     MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module1/pom.xml", false);
     MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameShouldEqualArtifactId/module2/pom.xml", false);
@@ -140,7 +140,7 @@ public class MavenProjectConverterTest {
 
   @Test
   public void moduleNameDifferentThanArtifactId() throws Exception {
-    File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/");
+    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/").toURI());
     MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/pom.xml", true);
     MavenProject module1 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path1/pom.xml", false);
     MavenProject module2 = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/moduleNameDifferentThanArtifactId/path2/pom.xml", false);
@@ -161,7 +161,7 @@ public class MavenProjectConverterTest {
 
   @Test
   public void should_find_module_with_maven_project_file_naming_different_from_pom_xml() throws Exception {
-    File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/");
+    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/").toURI());
     MavenProject parent = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/pom.xml", true);
     MavenProject module = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/mavenProjectFileNameNotEqualsToPomXml/module/pom_having_different_name.xml", false);
 
@@ -181,7 +181,7 @@ public class MavenProjectConverterTest {
 
   @Test
   public void testSingleProjectWithoutModules() throws Exception {
-    File rootDir = TestUtils.getResource("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/");
+    File rootDir = new File(Resources.getResource("org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/").toURI());
     MavenProject pom = loadPom("/org/sonar/batch/maven/MavenProjectConverterTest/singleProjectWithoutModules/pom.xml", true);
 
     ProjectDefinition rootDef = converter.configure(Arrays.asList(pom), pom);
index 2004a1e259b82cd6055aec5f74039ea8201282bb..c232c3344f5e47ec049d87ff0060f94d200f7c96 100644 (file)
@@ -20,6 +20,8 @@
 package org.sonar.batch.scan.report;
 
 import com.google.common.collect.Lists;
+import com.google.common.io.Resources;
+import org.apache.commons.codec.Charsets;
 import org.json.JSONException;
 import org.junit.Before;
 import org.junit.Test;
@@ -44,7 +46,6 @@ import org.sonar.batch.events.EventBus;
 import org.sonar.batch.issue.IssueCache;
 import org.sonar.batch.scan.filesystem.InputFileCache;
 import org.sonar.core.user.DefaultUser;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -124,8 +125,8 @@ public class JsonReportTest {
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report.json"),
-      writer.toString(), false);
+    String expected = Resources.toString(Resources.getResource("org/sonar/batch/scan/report/JsonReportTest/report.json"), Charsets.UTF_8);
+    JSONAssert.assertEquals(expected, writer.toString(), false);
   }
 
   @Test
@@ -142,13 +143,14 @@ public class JsonReportTest {
       .setCloseDate(SIMPLE_DATE_FORMAT.parse("2013-04-26"))
       .setNew(false);
     when(ruleFinder.findByKey(ruleKey)).thenReturn(Rule.create(ruleKey.repository(), ruleKey.rule()).setName("Avoid Cycles"));
-    when(jsonReport.getIssues()).thenReturn(Lists.<DefaultIssue>newArrayList(issue));
+    when(jsonReport.getIssues()).thenReturn(Lists.newArrayList(issue));
 
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JSONAssert.assertEquals(TestUtils.getResourceContent("/org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"),
-      writer.toString(), false);
+    String expected = Resources.toString(Resources.getResource(
+      "org/sonar/batch/scan/report/JsonReportTest/report-without-resolved-issues.json"), Charsets.UTF_8);
+    JSONAssert.assertEquals(expected, writer.toString(), false);
   }
 
   @Test
index 36162c19afeddc42ae9a8097422924ccc7a2a667..94df0eb2f2a980e7385d08b8820c10323ec3b8f2 100644 (file)
       <artifactId>dbunit</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>org.codehaus.sonar</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>com.github.tlrx</groupId>
       <artifactId>elasticsearch-test</artifactId>
index 89f10f109f7c131fbd102cb45428cb2138aef9cb..41ad62857a2a2b9282ac56a59dcccb5ede82cd3e 100644 (file)
 
 package org.sonar.server.debt;
 
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
 import org.junit.Test;
 import org.sonar.api.server.debt.DebtCharacteristic;
-import org.sonar.test.TestUtils;
 
 import java.util.List;
 
@@ -108,7 +108,7 @@ public class DebtCharacteristicsXMLImporterTest {
   }
 
   private String getFileContent(String file) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "DebtCharacteristicsXMLImporterTest/" + file), Charsets.UTF_8);
   }
 
 }
index 5629a09dbcb579fc86fdc0669f3a9d737d680b20..8251e6095ca3608a73f952930661243b039085be 100644 (file)
@@ -19,7 +19,8 @@
  */
 package org.sonar.server.debt;
 
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
 import org.apache.commons.lang.CharUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.custommonkey.xmlunit.Diff;
@@ -29,7 +30,6 @@ import org.junit.Test;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.server.debt.DebtRemediationFunction;
 import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic;
-import org.sonar.test.TestUtils;
 
 import java.util.Collections;
 import java.util.List;
@@ -142,6 +142,6 @@ public class DebtModelXMLExporterTest {
   }
 
   private String getFileContent(String file) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "DebtModelXMLExporterTest/" + file), Charsets.UTF_8);
   }
 }
index 3b4b5612dbe48eab1bb4de20d5bea39d5ebacce1..80181a911001f3255224d3f0aafe2d82aa729847 100644 (file)
 
 package org.sonar.server.debt;
 
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
 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.util.List;
 
@@ -43,7 +43,7 @@ public class DebtRulesXMLImporterTest {
     String xml = getFileContent("import_rules.xml");
 
     List<RuleDebt> results = importer.importXML(xml, validationMessages);
-    
+
     assertThat(results).hasSize(2);
     assertThat(validationMessages.getErrors()).isEmpty();
     assertThat(validationMessages.getWarnings()).isEmpty();
@@ -252,6 +252,7 @@ public class DebtRulesXMLImporterTest {
   }
 
   private String getFileContent(String file) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), file).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "DebtRulesXMLImporterTest/" + file),
+      Charsets.UTF_8);
   }
 }
index c0275ca1b9a9958d34e01005f0782a95d75965cb..19b66f6e3efd5805815cb02fe9030bb091256b2d 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.es;
 
+import com.google.common.io.Resources;
 import org.apache.commons.io.FileUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
 import org.elasticsearch.client.AdminClient;
@@ -34,7 +35,6 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.api.utils.ZipUtils;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -117,7 +117,8 @@ public class ESNodeTest {
 
   @Test
   public void should_restore_status_on_startup() throws Exception {
-    ZipUtils.unzip(TestUtils.getResource(ESNodeTest.class, "data-es-clean.zip"), dataDir);
+    File zip = new File(Resources.getResource(getClass(), "ESNodeTest/data-es-clean.zip").toURI());
+    ZipUtils.unzip(zip, dataDir);
 
     ESNode node = new ESNode(fs, new Settings());
     node.start();
@@ -131,7 +132,8 @@ public class ESNodeTest {
 
   @Test(expected = IllegalStateException.class)
   public void should_fail_on_corrupt_index() throws Exception {
-    ZipUtils.unzip(TestUtils.getResource(ESNodeTest.class, "data-es-corrupt.zip"), dataDir);
+    File zip = new File(Resources.getResource(getClass(), "ESNodeTest/data-es-corrupt.zip").toURI());
+    ZipUtils.unzip(zip, dataDir);
 
     ESNode node = new ESNode(fs, new Settings(), "5s");
     try {
index 8f22e23a815d47fe2be3fd4b7b095c89cc9dfeb9..4f86c1d81ae2567594fa85ba0c3acbd2f467a265 100644 (file)
  */
 package org.sonar.server.platform;
 
+import com.google.common.io.Resources;
 import org.junit.Test;
 import org.sonar.api.platform.ServerFileSystem;
 import org.sonar.core.persistence.Database;
 import org.sonar.core.persistence.dialect.Dialect;
 import org.sonar.core.persistence.dialect.H2;
 import org.sonar.core.persistence.dialect.MySql;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.util.List;
@@ -36,13 +36,14 @@ import static org.mockito.Mockito.when;
 
 public class DefaultServerFileSystemTest {
 
-  private static final String PATH = "/org/sonar/server/platform/DefaultServerFileSystemTest/";
+  private static final String PATH = "org/sonar/server/platform/DefaultServerFileSystemTest/";
 
   @Test
-  public void get_jdbc_driver() {
+  public void get_jdbc_driver() throws Exception {
     Database database = mock(Database.class);
     when(database.getDialect()).thenReturn(new MySql());
-    File driver = new DefaultServerFileSystem(database, TestUtils.getResource(PATH + "testGetJdbcDriver"), null).getJdbcDriver();
+    File file = new File(Resources.getResource(PATH + "testGetJdbcDriver").toURI());
+    File driver = new DefaultServerFileSystem(database, file, null).getJdbcDriver();
     assertThat(driver).isNotNull();
   }
 
@@ -54,31 +55,31 @@ public class DefaultServerFileSystemTest {
   }
 
   @Test(expected = IllegalStateException.class)
-  public void fail_if_jdbc_driver_not_found() {
+  public void fail_if_jdbc_driver_not_found() throws Exception {
     Database database = mock(Database.class);
 
     Dialect fakeDialect = mock(Dialect.class);
     when(fakeDialect.getId()).thenReturn("none");
     when(database.getDialect()).thenReturn(fakeDialect);
 
-    new DefaultServerFileSystem(database, TestUtils.getResource(PATH + "testGetJdbcDriver"), null).getJdbcDriver();
+    new DefaultServerFileSystem(database, new File(Resources.getResource(PATH + "testGetJdbcDriver").toURI()), null).getJdbcDriver();
   }
 
   @Test
-  public void find_plugins() {
-    List<File> plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldFindPlugins"), null).getUserPlugins();
+  public void find_plugins() throws Exception {
+    List<File> plugins = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldFindPlugins").toURI()), null).getUserPlugins();
     assertThat(plugins).hasSize(2);
   }
 
   @Test
-  public void not_fail_if_no_plugins() {
-    List<File> plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoPlugins"), null).getUserPlugins();
+  public void not_fail_if_no_plugins() throws Exception {
+    List<File> plugins = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldNotFailIfNoPlugins").toURI()), null).getUserPlugins();
     assertThat(plugins).isEmpty();
   }
 
   @Test
-  public void find_checkstyle_extensions() {
-    ServerFileSystem fs = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldFindCheckstyleExtensions"), null);
+  public void find_checkstyle_extensions() throws Exception {
+    ServerFileSystem fs = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldFindCheckstyleExtensions").toURI()), null);
 
     List<File> xmls = fs.getExtensions("checkstyle", "xml");
     assertThat(xmls).hasSize(1);
@@ -88,8 +89,8 @@ public class DefaultServerFileSystemTest {
   }
 
   @Test
-  public void not_fail_if_no_checkstyle_extensions() {
-    ServerFileSystem fs = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions"), null);
+  public void not_fail_if_no_checkstyle_extensions() throws Exception {
+    ServerFileSystem fs = new DefaultServerFileSystem(null, new File(Resources.getResource(PATH + "shouldNotFailIfNoCheckstyleExtensions").toURI()), null);
     List<File> xmls = fs.getExtensions("checkstyle", "xml");
     assertThat(xmls).isEmpty();
 
index c5404935d8d0d7437beb1fb32179fe3d5d4a10b4..be40c087f8839f0e018d3165f32d2ede0c737f55 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.plugins;
 
+import com.google.common.io.Resources;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
@@ -31,10 +32,8 @@ import org.sonar.api.platform.ServerUpgradeStatus;
 import org.sonar.api.utils.MessageException;
 import org.sonar.core.persistence.Database;
 import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
-import java.io.IOException;
 
 import static org.fest.assertions.Assertions.assertThat;
 import static org.fest.assertions.Fail.fail;
@@ -57,7 +56,7 @@ public class ServerPluginJarsInstallerTest {
   ServerUpgradeStatus upgradeStatus = mock(ServerUpgradeStatus.class);
 
   @Before
-  public void before() throws IOException {
+  public void before() throws Exception {
     when(server.getVersion()).thenReturn("3.1");
     when(server.getDeployDir()).thenReturn(temp.newFolder("deploy"));
 
@@ -75,8 +74,8 @@ public class ServerPluginJarsInstallerTest {
     jarsInstaller = new ServerPluginJarsInstaller(server, upgradeStatus, fileSystem, jarInstaller);
   }
 
-  private File jar(String name) {
-    return TestUtils.getResource(ServerPluginJarsInstallerTest.class, name);
+  private File jar(String name) throws Exception {
+    return new File(Resources.getResource(getClass(), "ServerPluginJarsInstallerTest/" + name).toURI());
   }
 
   @Test
@@ -124,7 +123,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void deploy_installed_plugin() throws IOException {
+  public void deploy_installed_plugin() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
 
@@ -144,7 +143,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void ignore_non_plugin_jars() throws IOException {
+  public void ignore_non_plugin_jars() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("not-a-plugin.jar"), pluginsDir);
 
@@ -157,7 +156,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void fail_if_plugin_requires_greater_SQ_version() throws IOException {
+  public void fail_if_plugin_requires_greater_SQ_version() throws Exception {
     exception.expect(IllegalStateException.class);
     exception.expectMessage("Plugin switchoffviolations needs a more recent version of SonarQube than 2.0. At least 2.5 is expected");
 
@@ -169,7 +168,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void move_downloaded_plugins() throws IOException {
+  public void move_downloaded_plugins() throws Exception {
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), downloadsDir);
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
 
@@ -181,7 +180,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void downloaded_plugins_overrides_existing_plugin() throws IOException {
+  public void downloaded_plugins_overrides_existing_plugin() throws Exception {
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
     FileUtils.copyFileToDirectory(jar("foo-plugin-2.0.jar"), downloadsDir);
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
@@ -194,7 +193,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void downloaded_plugins_overrides_existing_plugin_even_if_same_filename() throws IOException {
+  public void downloaded_plugins_overrides_existing_plugin_even_if_same_filename() throws Exception {
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir, true);
     // foo-plugin-1.0.jar in extensions/downloads is in fact version 2.0. It's used to verify
     // that it has correctly overridden extensions/plugins/foo-plugin-1.0.jar
@@ -213,7 +212,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void delete_trash() throws IOException {
+  public void delete_trash() throws Exception {
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), trashDir);
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
 
@@ -224,7 +223,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void fail_if_two_installed_plugins_with_same_key() throws IOException {
+  public void fail_if_two_installed_plugins_with_same_key() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
     FileUtils.copyFileToDirectory(jar("foo-plugin-2.0.jar"), pluginsDir);
@@ -241,7 +240,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void uninstall_plugin() throws IOException {
+  public void uninstall_plugin() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
 
@@ -254,7 +253,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void cancel_uninstallation() throws IOException {
+  public void cancel_uninstallation() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), pluginsDir);
 
@@ -268,7 +267,7 @@ public class ServerPluginJarsInstallerTest {
   }
 
   @Test
-  public void deploy_core_plugins() throws IOException {
+  public void deploy_core_plugins() throws Exception {
     when(upgradeStatus.isFreshInstall()).thenReturn(false);
     FileUtils.copyFileToDirectory(jar("foo-plugin-1.0.jar"), coreDir);
 
index 3e4898d03d1408555f586b614e3f9f5d6a16d48f..41a0b4cc6b82e7c0df39248ac053d6d90563c242 100644 (file)
  */
 package org.sonar.server.plugins;
 
+import com.google.common.io.Resources;
 import org.junit.After;
 import org.junit.Test;
 import org.sonar.api.platform.PluginMetadata;
 import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 import java.util.Arrays;
 
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.IsNot.not;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -46,9 +44,9 @@ public class ServerPluginRepositoryTest {
   }
 
   @Test
-  public void testStart() {
+  public void testStart() throws Exception {
     ServerPluginJarsInstaller deployer = mock(ServerPluginJarsInstaller.class);
-    File pluginFile = TestUtils.getResource("/org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar");
+    File pluginFile = new File(Resources.getResource("org/sonar/server/plugins/ServerPluginRepositoryTest/sonar-artifact-size-plugin-0.2.jar").toURI());
     PluginMetadata plugin = DefaultPluginMetadata.create(pluginFile)
       .setKey("artifactsize")
       .setMainClass("org.sonar.plugins.artifactsize.ArtifactSizePlugin")
@@ -58,10 +56,10 @@ public class ServerPluginRepositoryTest {
     repository = new ServerPluginRepository(deployer);
     repository.start();
 
-    assertThat(repository.getPlugin("artifactsize"), not(nullValue()));
-    assertThat(repository.getClassLoader("artifactsize"), not(nullValue()));
-    assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), not(nullValue()));
-    assertThat(repository.getClass("artifactsize", "org.Unknown"), nullValue());
-    assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics"), nullValue());
+    assertThat(repository.getPlugin("artifactsize")).isNotNull();
+    assertThat(repository.getClassLoader("artifactsize")).isNotNull();
+    assertThat(repository.getClass("artifactsize", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics")).isNotNull();
+    assertThat(repository.getClass("artifactsize", "org.Unknown")).isNull();
+    assertThat(repository.getClass("other", "org.sonar.plugins.artifactsize.ArtifactSizeMetrics")).isNull();
   }
 }
index ad5e0a6616bc4d5037d2c5efef86edd32994e452..ee671a8c504a1beb8b7649ff486f0faa0a08a0e1 100644 (file)
 package org.sonar.server.qualityprofile;
 
 import com.github.tlrx.elasticsearch.test.EsSetup;
+import com.google.common.base.Charsets;
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
-import org.apache.commons.io.IOUtils;
+import com.google.common.io.Resources;
 import org.apache.ibatis.session.SqlSession;
 import org.elasticsearch.client.Requests;
 import org.elasticsearch.common.settings.ImmutableSettings;
@@ -45,7 +46,6 @@ import org.sonar.core.qualityprofile.db.ActiveRuleParamDto;
 import org.sonar.server.es.ESIndex;
 import org.sonar.server.es.ESNode;
 import org.sonar.server.rule.RuleRegistry;
-import org.sonar.test.TestUtils;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -53,7 +53,9 @@ import java.util.Date;
 import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
-import static org.elasticsearch.index.query.FilterBuilders.*;
+import static org.elasticsearch.index.query.FilterBuilders.hasChildFilter;
+import static org.elasticsearch.index.query.FilterBuilders.hasParentFilter;
+import static org.elasticsearch.index.query.FilterBuilders.termFilter;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -215,7 +217,7 @@ public class ESActiveRuleTest {
 
   @Test
   public void should_not_fail_on_empty_delete_list() {
-    esActiveRule.deleteActiveRules(ImmutableList.<Integer> of());
+    esActiveRule.deleteActiveRules(ImmutableList.<Integer>of());
   }
 
   @Test
@@ -226,7 +228,7 @@ public class ESActiveRuleTest {
     SqlSession session = mock(SqlSession.class);
     when(myBatis.openSession()).thenReturn(session);
     when(activeRuleDao.selectAll(session)).thenReturn(activeRules);
-    when(activeRuleDao.selectAllParams(session)).thenReturn(Lists.<ActiveRuleParamDto> newArrayList());
+    when(activeRuleDao.selectAllParams(session)).thenReturn(Lists.<ActiveRuleParamDto>newArrayList());
 
     esActiveRule.bulkRegisterActiveRules();
     assertThat(esSetup.exists("rules", "active_rule", "1"));
@@ -245,7 +247,7 @@ public class ESActiveRuleTest {
   }
 
   private String testFileAsString(String testFile) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "ESActiveRuleTest/" + testFile), Charsets.UTF_8);
   }
 
 }
index 0e114e9e98461d705686226502a68d45fbd53628..92626cabaa9e8da446fb1e0e4838ee89bfce735f 100644 (file)
@@ -20,7 +20,8 @@
 package org.sonar.server.qualityprofile;
 
 import com.github.tlrx.elasticsearch.test.EsSetup;
-import org.apache.commons.io.IOUtils;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
 import org.elasticsearch.client.Requests;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.junit.After;
@@ -33,7 +34,6 @@ import org.sonar.server.es.ESIndex;
 import org.sonar.server.es.ESNode;
 import org.sonar.server.paging.Paging;
 import org.sonar.server.rule.RuleRegistry;
-import org.sonar.test.TestUtils;
 
 import java.util.List;
 
@@ -51,7 +51,7 @@ public class QProfileRuleLookupTest {
     esSetup = new EsSetup(ImmutableSettings.builder()
       .loadFromUrl(ESNode.class.getResource("config/elasticsearch.json"))
       .build()
-      );
+    );
     esSetup.execute(EsSetup.deleteAll());
 
     ESNode searchNode = mock(ESNode.class);
@@ -325,17 +325,17 @@ public class QProfileRuleLookupTest {
     esSetup.client().prepareBulk()
       // id = 2303, tags = empty
       .add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_empty.json")))
-      // active rule with parent having no tag
+        // active rule with parent having no tag
       .add(Requests.indexRequest().index("rules").type("active_rule").parent("2303").source(testFileAsString("find_inactive_rules_with_tags/active_rule_empty.json")))
-      // id = 2304, tags = taga
+        // id = 2304, tags = taga
       .add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_a.json")))
-      // id = 2305, tags = taga, tagb
+        // id = 2305, tags = taga, tagb
       .add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_ab.json")))
-      // id = 2306, tags = tagb, tagc
+        // id = 2306, tags = tagb, tagc
       .add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_bc.json")))
-      // id = 2307, tags = taga, tagc, tage
+        // id = 2307, tags = taga, tagc, tage
       .add(Requests.indexRequest().index("rules").type("rule").source(testFileAsString("find_inactive_rules_with_tags/tags_ace.json")))
-      // active rule with parent having tags
+        // active rule with parent having tags
       .add(Requests.indexRequest().index("rules").type("active_rule").parent("2307").source(testFileAsString("find_inactive_rules_with_tags/active_rule_ace.json")))
       .setRefresh(true)
       .execute().actionGet();
@@ -460,6 +460,6 @@ public class QProfileRuleLookupTest {
   }
 
   private String testFileAsString(String testFile) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "QProfileRuleLookupTest/" + testFile), Charsets.UTF_8);
   }
 }
index f4a297a029f32a924436171a2c8bbec2a9351a53..64a307467875a61dcfe1a24a80df30cbdfd234e4 100644 (file)
@@ -21,8 +21,9 @@
 package org.sonar.server.rule;
 
 import com.github.tlrx.elasticsearch.test.EsSetup;
+import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableMap;
-import org.apache.commons.io.IOUtils;
+import com.google.common.io.Resources;
 import org.apache.ibatis.session.SqlSession;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.junit.After;
@@ -36,12 +37,15 @@ import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rule.Severity;
 import org.sonar.core.persistence.MyBatis;
 import org.sonar.core.profiling.Profiling;
-import org.sonar.core.rule.*;
+import org.sonar.core.rule.RuleDao;
+import org.sonar.core.rule.RuleDto;
+import org.sonar.core.rule.RuleParamDto;
+import org.sonar.core.rule.RuleRuleTagDto;
+import org.sonar.core.rule.RuleTagType;
 import org.sonar.core.technicaldebt.db.CharacteristicDao;
 import org.sonar.core.technicaldebt.db.CharacteristicDto;
 import org.sonar.server.es.ESIndex;
 import org.sonar.server.es.ESNode;
-import org.sonar.test.TestUtils;
 
 import java.util.HashMap;
 import java.util.List;
@@ -297,9 +301,9 @@ public class RuleRegistryTest {
   @Test
   public void index_overridden_characteristic_if_both_default_and_overridden_characteristics_exists_when_indexing_one_rule() {
     RuleDto ruleDto = new RuleDto().setId(10).setRepositoryKey("repo").setRuleKey("key1").setSeverity(Severity.MINOR)
-        // default and overridden debt values are set
-        .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("LINEAR").setDefaultRemediationCoefficient("2h")
-        .setSubCharacteristicId(13).setRemediationFunction("LINEAR_OFFSET").setRemediationCoefficient("1h").setRemediationOffset("15min");
+      // default and overridden debt values are set
+      .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("LINEAR").setDefaultRemediationCoefficient("2h")
+      .setSubCharacteristicId(13).setRemediationFunction("LINEAR_OFFSET").setRemediationCoefficient("1h").setRemediationOffset("15min");
 
     when(characteristicDao.selectById(12, session)).thenReturn(new CharacteristicDto().setId(12).setKey("REUSABILITY").setName("Reusability"));
     when(characteristicDao.selectById(13, session)).thenReturn(new CharacteristicDto().setId(13).setKey("MODULARITY").setName("Modularity").setParentId(12));
@@ -320,9 +324,9 @@ public class RuleRegistryTest {
   @Test
   public void index_overridden_function_if_both_default_and_overridden_functions_exists_when_indexing_one_rule() {
     RuleDto ruleDto = new RuleDto().setId(10).setRepositoryKey("repo").setRuleKey("key1").setSeverity(Severity.MINOR)
-        // default and overridden debt values are set
-        .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("15min")
-        .setSubCharacteristicId(11).setRemediationFunction("LINEAR").setRemediationCoefficient("1h");
+      // default and overridden debt values are set
+      .setDefaultSubCharacteristicId(11).setDefaultRemediationFunction("CONSTANT_ISSUE").setDefaultRemediationOffset("15min")
+      .setSubCharacteristicId(11).setRemediationFunction("LINEAR").setRemediationCoefficient("1h");
 
     when(characteristicDao.selectById(10, session)).thenReturn(new CharacteristicDto().setId(10).setKey("REUSABILITY").setName("Reusability"));
     when(characteristicDao.selectById(11, session)).thenReturn(new CharacteristicDto().setId(11).setKey("MODULARITY").setName("Modularity").setParentId(10));
@@ -505,7 +509,7 @@ public class RuleRegistryTest {
   }
 
   private String testFileAsString(String testFile) throws Exception {
-    return IOUtils.toString(TestUtils.getResource(getClass(), testFile).toURI());
+    return Resources.toString(Resources.getResource(getClass(), "RuleRegistryTest/" + testFile), Charsets.UTF_8);
   }
 
 }
index f03d4f86f772cfd1f0658be1033073d3140d04a3..6a87d3119c2e78713939c2dee7892a42ee4c9e76 100644 (file)
@@ -21,11 +21,11 @@ package org.sonar.server.startup;
 
 import com.google.common.base.Charsets;
 import com.google.common.io.Files;
+import com.google.common.io.Resources;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonar.server.platform.DefaultServerFileSystem;
-import org.sonar.test.TestUtils;
 
 import java.io.File;
 
@@ -41,7 +41,7 @@ public class JdbcDriverDeployerTest {
   @Test
   public void test_deploy() throws Exception {
     DefaultServerFileSystem fs = mock(DefaultServerFileSystem.class);
-    File initialDriver = TestUtils.getResource(getClass(), "deploy/my-driver.jar");
+    File initialDriver = new File(Resources.getResource(getClass(), "JdbcDriverDeployerTest/deploy/my-driver.jar").toURI());
     when(fs.getJdbcDriver()).thenReturn(initialDriver);
 
     File deployDir = temp.newFolder("deploy");
index eedcee75337fa78e8c875626d03dd2648ef816a2..e537466d2629372b17ec6f22e40d125b64f6b48a 100644 (file)
  */
 package org.sonar.test;
 
-import org.apache.commons.io.Charsets;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.StringUtils;
-import org.sonar.api.utils.SonarException;
 
 import java.io.File;
-import java.io.IOException;
 import java.net.URL;
 
 /**
@@ -57,19 +53,6 @@ public final class TestUtils {
     return null;
   }
 
-  public static String getResourceContent(String path) {
-    URL url = TestUtils.class.getResource(path);
-    if (url == null) {
-      return null;
-    }
-
-    try {
-      return IOUtils.toString(url, Charsets.UTF_8);
-    } catch (IOException e) {
-      throw new SonarException("Can not load the resource: " + path, e);
-    }
-  }
-
   /**
    * Search for a resource in the classpath. For example calling the method getResource(getClass(), "myTestName/foo.txt") from
    * the class org.sonar.Foo loads the file $basedir/src/test/resources/org/sonar/Foo/myTestName/foo.txt