From: Simon Brandhof Date: Wed, 23 Apr 2014 18:29:35 +0000 (+0200) Subject: Remove some usage of TestUtils X-Git-Tag: 4.4-RC1~1416 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6a565e856b3041aff353a1fb7d896fe5487e5b61;p=sonarqube.git Remove some usage of TestUtils --- diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java index b94c87630d9..02e00bacb0a 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/IssueChangesEmailTemplateTest.java @@ -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(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java index 0592c2158d4..2e29bf1f8e2 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java @@ -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); diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java index e5815b89286..10d5241c5a3 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java @@ -20,20 +20,18 @@ 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 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 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 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 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 lineRanges = Sets.newHashSet(); lineRanges.add(new LineRange(21, 29)); diff --git a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java b/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java index be1fd2cfe3e..e9b449a63a4 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/maven/MavenProjectConverterTest.java @@ -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); diff --git a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java index 2004a1e259b..c232c3344f5 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/scan/report/JsonReportTest.java @@ -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.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 diff --git a/sonar-server/pom.xml b/sonar-server/pom.xml index 36162c19afe..94df0eb2f2a 100644 --- a/sonar-server/pom.xml +++ b/sonar-server/pom.xml @@ -185,11 +185,6 @@ dbunit test - - org.codehaus.sonar - sonar-testing-harness - test - com.github.tlrx elasticsearch-test diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java index 89f10f109f7..41ad62857a2 100644 --- a/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java @@ -20,10 +20,10 @@ 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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java index 5629a09dbcb..8251e6095ca 100644 --- a/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java @@ -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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java b/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java index 3b4b5612dbe..80181a91100 100644 --- a/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java +++ b/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java @@ -20,12 +20,12 @@ 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 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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/es/ESNodeTest.java b/sonar-server/src/test/java/org/sonar/server/es/ESNodeTest.java index c0275ca1b9a..19b66f6e3ef 100644 --- a/sonar-server/src/test/java/org/sonar/server/es/ESNodeTest.java +++ b/sonar-server/src/test/java/org/sonar/server/es/ESNodeTest.java @@ -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 { diff --git a/sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java b/sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java index 8f22e23a815..4f86c1d81ae 100644 --- a/sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java +++ b/sonar-server/src/test/java/org/sonar/server/platform/DefaultServerFileSystemTest.java @@ -19,13 +19,13 @@ */ 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 plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldFindPlugins"), null).getUserPlugins(); + public void find_plugins() throws Exception { + List 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 plugins = new DefaultServerFileSystem(null, TestUtils.getResource(PATH + "shouldNotFailIfNoPlugins"), null).getUserPlugins(); + public void not_fail_if_no_plugins() throws Exception { + List 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 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 xmls = fs.getExtensions("checkstyle", "xml"); assertThat(xmls).isEmpty(); diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java index c5404935d8d..be40c087f88 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginJarsInstallerTest.java @@ -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); diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java index 3e4898d03d1..41a0b4cc6b8 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerPluginRepositoryTest.java @@ -19,18 +19,16 @@ */ 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(); } } diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ESActiveRuleTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ESActiveRuleTest.java index ad5e0a6616b..ee671a8c504 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/ESActiveRuleTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/ESActiveRuleTest.java @@ -20,11 +20,12 @@ 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. of()); + esActiveRule.deleteActiveRules(ImmutableList.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. newArrayList()); + when(activeRuleDao.selectAllParams(session)).thenReturn(Lists.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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java index 0e114e9e984..92626cabaa9 100644 --- a/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java +++ b/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileRuleLookupTest.java @@ -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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java index f4a297a029f..64a30746787 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RuleRegistryTest.java @@ -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); } } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java b/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java index f03d4f86f77..6a87d3119c2 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java @@ -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"); diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java index eedcee75337..e537466d262 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/TestUtils.java @@ -19,14 +19,10 @@ */ 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