]> source.dussan.org Git - sonarqube.git/commitdiff
Cut many dependencies on sonar-testing-harness 722/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 19 Jan 2016 10:14:50 +0000 (11:14 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 19 Jan 2016 13:45:02 +0000 (14:45 +0100)
14 files changed:
plugins/sonar-xoo-plugin/pom.xml
sonar-batch-protocol/pom.xml
sonar-batch-protocol/src/test/java/org/sonar/batch/protocol/input/GlobalRepositoriesTest.java
sonar-batch/pom.xml
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionDictionnaryTest.java
sonar-batch/src/test/java/org/sonar/batch/cache/WSLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/index/BucketTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java [deleted file]
sonar-batch/src/test/java/org/sonar/batch/scan/ProjectReactorBuilderTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/report/JSONReportTest.java
sonar-batch/src/test/resources/org/sonar/batch/scan/report/JSONReportTest/report.json
sonar-colorizer/pom.xml
sonar-duplications/pom.xml
sonar-home/pom.xml

index 79bb2d61254da65673b42f365ca173379557ce7e..26d2c84fc7c1e4d575b09d5cb190add1d7bf7975 100644 (file)
 
     <!-- unit testing -->
     <dependency>
-      <groupId>org.sonarsource.sonarqube</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
index 01b9a0e620d2950d127ad24118e3244ced5359ed..183f29e98bd49cdce47b8fce88bb75692d85872b 100644 (file)
 
     <!-- unit tests -->
     <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>net.javacrumbs.json-unit</groupId>
+      <artifactId>json-unit-assertj</artifactId>
+      <version>0.0.15</version>
       <scope>test</scope>
     </dependency>
     <dependency>
index ab6b6b120c73c934a94bfc51c424e12241ab5444..fe0643b5c458cec7d5d9369527d0415eacc4d7b6 100644 (file)
  */
 package org.sonar.batch.protocol.input;
 
+import org.apache.commons.io.IOUtils;
 import org.junit.Test;
-import org.sonar.test.JsonAssert;
 
+import static net.javacrumbs.jsonunit.assertj.JsonAssert.assertThatJson;
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class GlobalRepositoriesTest {
 
   @Test
-  public void to_json() {
+  public void to_json() throws Exception {
     GlobalRepositories ref = new GlobalRepositories();
     ref.addMetric(new Metric(1, "ncloc", "INT", "Description", -1, "NCLOC", true, false, 2.0, 1.0, true));
     ref.addGlobalSetting("prop", "value");
     ref.setTimestamp(10);
 
-    JsonAssert
-      .assertJson(ref.toJson())
-      .isSimilarTo(getClass().getResource("GlobalRepositoriesTest/expected.json"));
+    assertThatJson(ref.toJson())
+      .isEqualTo(IOUtils.toString(getClass().getResource("GlobalRepositoriesTest/expected.json")));
   }
 
   @Test
   public void from_json() {
     GlobalRepositories ref = GlobalRepositories
       .fromJson(
-      "{timestamp:1,"
-        + "metrics:[{id:1,key:ncloc,valueType:DATA,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
-        + "globalSettings:{prop:value}}");
+        "{timestamp:1,"
+          + "metrics:[{id:1,key:ncloc,valueType:DATA,description:Description,direction:-1,name:NCLOC,qualitative:true,userManaged:false,worstValue:2.0,bestValue:1.0,optimizedBestValue:true}],"
+          + "globalSettings:{prop:value}}");
 
     assertThat(ref.timestamp()).isEqualTo(1);
     Metric metric = ref.metrics().iterator().next();
index 276564bb9cff4d3e87ae98bbc72f9d973d94c79d..f8e86b8e5395978ea1f9cb8f6945cf3d17bd13c2 100644 (file)
     </dependency>
 
     <!-- unit tests -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>net.javacrumbs.json-unit</groupId>
+      <artifactId>json-unit-assertj</artifactId>
+      <version>0.0.15</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>sonar-plugin-api</artifactId>
       <artifactId>bean-matchers</artifactId>
       <scope>test</scope>
     </dependency>
-    <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>org.eclipse.jetty</groupId>
       <artifactId>jetty-server</artifactId>
index fad6d8bd7f5fbd2a90f7bc12adf9e9fb4389aff4..77a0021ef315d28600d7c4225ce26691e1a5f9ab 100644 (file)
@@ -20,6 +20,9 @@
 package org.sonar.batch.bootstrap;
 
 import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
 import org.junit.Test;
 import org.sonar.api.BatchExtension;
 import org.sonar.api.batch.BuildBreaker;
@@ -38,14 +41,8 @@ import org.sonar.batch.sensor.DefaultSensorContext;
 import org.sonar.batch.sensor.SensorOptimizer;
 import org.sonar.core.platform.ComponentContainer;
 
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.Matchers.hasItem;
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 
 public class BatchExtensionDictionnaryTest {
@@ -72,7 +69,7 @@ public class BatchExtensionDictionnaryTest {
       }
     });
 
-    assertThat(sensors, hasItem(sensor1));
+    assertThat(sensors).contains(sensor1);
     assertEquals(1, sensors.size());
   }
 
index 851cc3abbdb65e0fc8cebf0faf234936f959c84e..ad7bb763d6726ca1c4374682a5bafbdec5a708ff 100644 (file)
@@ -22,7 +22,6 @@ package org.sonar.batch.cache;
 import java.io.IOException;
 import java.io.InputStream;
 import org.apache.commons.io.IOUtils;
-import org.hamcrest.Matchers;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
@@ -33,7 +32,6 @@ import org.sonar.batch.cache.WSLoader.LoadStrategy;
 import org.sonar.home.cache.PersistentCache;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.MockWsResponse;
-import org.sonarqube.ws.client.WsConnector;
 import org.sonarqube.ws.client.WsRequest;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -188,7 +186,7 @@ public class WSLoaderTest {
     turnServerOffline();
 
     exception.expect(IllegalStateException.class);
-    exception.expectMessage(Matchers.containsString("Server is not available"));
+    exception.expectMessage("Server is not available");
 
     WSLoader loader = new WSLoader(LoadStrategy.SERVER_ONLY, cache, ws);
     loader.loadString(ID);
@@ -200,7 +198,7 @@ public class WSLoaderTest {
     turnCacheEmpty();
 
     exception.expect(IllegalStateException.class);
-    exception.expectMessage(Matchers.is("Server is not accessible and data is not cached"));
+    exception.expectMessage("Server is not accessible and data is not cached");
 
     WSLoader loader = new WSLoader(LoadStrategy.SERVER_FIRST, cache, ws);
     loader.loadString(ID);
@@ -211,7 +209,7 @@ public class WSLoaderTest {
     turnCacheEmpty();
 
     exception.expect(IllegalStateException.class);
-    exception.expectMessage(Matchers.is("Data is not cached"));
+    exception.expectMessage("Data is not cached");
 
     WSLoader loader = new WSLoader(LoadStrategy.CACHE_ONLY, cache, ws);
     loader.loadString(ID);
index e9c9374ea5c722b94542192b2622c3160ee97d91..a6a5f90008826f5af354f733803572ea9b5a46fe 100644 (file)
@@ -24,12 +24,9 @@ import org.sonar.api.measures.Metric;
 import org.sonar.api.resources.Directory;
 import org.sonar.api.resources.File;
 
-import static org.hamcrest.Matchers.hasItem;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNot.not;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
 
 public class BucketTest {
 
@@ -43,9 +40,8 @@ public class BucketTest {
     Bucket fileBucket = new Bucket(javaFile);
     fileBucket.setParent(packageBucket);
 
-    assertThat(fileBucket.getParent(), is(packageBucket));
-    assertThat(packageBucket.getChildren().size(), is(1));
-    assertThat(packageBucket.getChildren(), hasItem(fileBucket));
+    assertThat(fileBucket.getParent()).isEqualTo(packageBucket);
+    assertThat(packageBucket.getChildren()).containsExactly(fileBucket);
   }
 
   @Test
@@ -57,6 +53,6 @@ public class BucketTest {
   @Test
   public void shouldNotBeEquals() {
     assertFalse(new Bucket(directory).equals(new Bucket(javaFile)));
-    assertThat(new Bucket(directory).hashCode(), not(is(new Bucket(javaFile).hashCode())));
+    assertThat(new Bucket(directory).hashCode()).isNotEqualTo(new Bucket(javaFile).hashCode());
   }
 }
diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/Benchmark.java
deleted file mode 100644 (file)
index 766dc2c..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.mediumtest;
-
-import org.hamcrest.Matchers;
-import org.junit.rules.ErrorCollector;
-import org.slf4j.LoggerFactory;
-
-public class Benchmark extends ErrorCollector {
-
-  private static final boolean ENABLED = "true".equals(System.getProperty("enableBenchmarkAssertions"));
-
-  static {
-    if (ENABLED) {
-      LoggerFactory.getLogger(Benchmark.class).warn("Assertions are calibrated for SonarSource dedicated box. " +
-        "They can be disabled by setting the property -DenableBenchmarkAssertions=false.");
-    }
-  }
-
-  public void expectLessThanOrEqualTo(String label, long val, long max) {
-    if (ENABLED) {
-      checkThat(label, val, Matchers.lessThan(max));
-    }
-  }
-
-}
index 21aa0fa27c2f99654fe36b17d4541ee2d970cad8..24b6bca3fc9cff2d95eabb4d8a6db5e512019497 100644 (file)
@@ -23,10 +23,12 @@ import com.google.common.collect.Maps;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Before;
 import org.junit.Rule;
@@ -38,7 +40,6 @@ import org.sonar.api.batch.bootstrap.ProjectReactor;
 import org.sonar.api.utils.log.LogTester;
 import org.sonar.api.utils.log.LoggerLevel;
 import org.sonar.batch.analysis.AnalysisProperties;
-import org.sonar.test.TestUtils;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -74,7 +75,7 @@ public class ProjectReactorBuilderTest {
   public void shouldFailIfUnexistingSourceDirectory() {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = "
-      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
+      + getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")");
 
     loadProjectDefinition("simple-project-with-unexisting-source-dir");
   }
@@ -133,9 +134,9 @@ public class ProjectReactorBuilderTest {
     assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(rootProject.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root"));
     assertThat(rootProject.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar"));
 
     // CHECK MODULES
     List<ProjectDefinition> modules = rootProject.getSubProjects();
@@ -143,7 +144,7 @@ public class ProjectReactorBuilderTest {
 
     // Module 1
     ProjectDefinition module1 = modules.get(0);
-    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
     assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
     assertThat(module1.getName()).isEqualTo("module1");
     assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
@@ -157,13 +158,13 @@ public class ProjectReactorBuilderTest {
     assertThat(module1.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(module1.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
     assertThat(module1.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_module1"));
 
     // Module 2
     ProjectDefinition module2 = modules.get(1);
-    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
     assertThat(module2.getKey()).isEqualTo("com.foo.project:com.foo.project.module2");
     assertThat(module2.getName()).isEqualTo("Foo Module 2");
     assertThat(module2.getVersion()).isEqualTo("1.0-SNAPSHOT");
@@ -176,9 +177,9 @@ public class ProjectReactorBuilderTest {
     assertThat(module2.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(module2.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-all-in-root/module2"));
     assertThat(module2.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-all-in-root"), ".sonar/com.foo.project_com.foo.project.module2"));
   }
 
   // SONAR-4876
@@ -216,19 +217,19 @@ public class ProjectReactorBuilderTest {
 
     // Module 1
     ProjectDefinition module1 = modules.get(0);
-    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root"));
     assertThat(module1.getSourceDirs()).contains("src/main/java");
     // and module properties must have been cleaned
     assertThat(module1.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_java-module"));
 
     // Module 2
     ProjectDefinition module2 = modules.get(1);
-    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"));
+    assertThat(module2.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-language-definitions-all-in-root"));
     assertThat(module2.getSourceDirs()).contains("src/main/groovy");
     // and module properties must have been cleaned
     assertThat(module2.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-language-definitions-all-in-root"), ".sonar/example_groovy-module"));
   }
 
   @Test
@@ -243,7 +244,7 @@ public class ProjectReactorBuilderTest {
   public void shouldFailIfUnexistingModuleBaseDir() {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("The base directory of the module 'module1' does not exist: "
-      + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1");
+      + getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1");
 
     loadProjectDefinition("multi-module-with-unexisting-basedir");
   }
@@ -252,7 +253,7 @@ public class ProjectReactorBuilderTest {
   public void shouldFailIfUnexistingSourceFolderInheritedInMultimodule() {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = "
-      + TestUtils.getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)");
+      + getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)");
 
     loadProjectDefinition("multi-module-with-unexisting-source-dir");
   }
@@ -261,7 +262,7 @@ public class ProjectReactorBuilderTest {
   public void shouldFailIfExplicitUnexistingTestFolder() {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("The folder 'tests' does not exist for 'com.foo.project' (base directory = "
-      + TestUtils.getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath());
+      + getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath());
 
     loadProjectDefinition("simple-project-with-unexisting-test-dir");
   }
@@ -270,7 +271,7 @@ public class ProjectReactorBuilderTest {
   public void shouldFailIfExplicitUnexistingTestFolderOnModule() {
     thrown.expect(IllegalStateException.class);
     thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = "
-      + TestUtils.getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)");
+      + getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)");
 
     loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir");
   }
@@ -364,15 +365,15 @@ public class ProjectReactorBuilderTest {
 
   @Test
   public void shouldGetRelativeFile() {
-    assertThat(ProjectReactorBuilder.resolvePath(TestUtils.getResource(this.getClass(), "/"), "shouldGetFile/foo.properties"))
-      .isEqualTo(TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties"));
+    assertThat(ProjectReactorBuilder.resolvePath(getResource(this.getClass(), "/"), "shouldGetFile/foo.properties"))
+      .isEqualTo(getResource(this.getClass(), "shouldGetFile/foo.properties"));
   }
 
   @Test
   public void shouldGetAbsoluteFile() {
-    File file = TestUtils.getResource(this.getClass(), "shouldGetFile/foo.properties");
+    File file = getResource(this.getClass(), "shouldGetFile/foo.properties");
 
-    assertThat(ProjectReactorBuilder.resolvePath(TestUtils.getResource(this.getClass(), "/"), file.getAbsolutePath()))
+    assertThat(ProjectReactorBuilder.resolvePath(getResource(this.getClass(), "/"), file.getAbsolutePath()))
       .isEqualTo(file);
   }
 
@@ -509,11 +510,11 @@ public class ProjectReactorBuilderTest {
 
   private Map<String, String> loadProps(String projectFolder) {
     Map<String, String> props = Maps.<String, String>newHashMap();
-    Properties runnerProps = toProperties(TestUtils.getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
+    Properties runnerProps = toProperties(getResource(this.getClass(), projectFolder + "/sonar-project.properties"));
     for (final String name : runnerProps.stringPropertyNames()) {
       props.put(name, runnerProps.getProperty(name));
     }
-    props.put("sonar.projectBaseDir", TestUtils.getResource(this.getClass(), projectFolder).getAbsolutePath());
+    props.put("sonar.projectBaseDir", getResource(this.getClass(), projectFolder).getAbsolutePath());
     return props;
   }
 
@@ -575,9 +576,9 @@ public class ProjectReactorBuilderTest {
     assertThat(rootProject.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(rootProject.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix"));
     assertThat(rootProject.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar"));
 
     // CHECK MODULES
     List<ProjectDefinition> modules = rootProject.getSubProjects();
@@ -585,7 +586,7 @@ public class ProjectReactorBuilderTest {
 
     // Module 1
     ProjectDefinition module1 = modules.get(0);
-    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1"));
+    assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1"));
     assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
     assertThat(module1.getName()).isEqualTo("module1");
     assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
@@ -599,13 +600,13 @@ public class ProjectReactorBuilderTest {
     assertThat(module1.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(module1.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1"));
     assertThat(module1.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_module1"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_module1"));
 
     // Module 1 Feature
     ProjectDefinition module1Feature = modules.get(1);
-    assertThat(module1Feature.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
+    assertThat(module1Feature.getBaseDir().getCanonicalFile()).isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
     assertThat(module1Feature.getKey()).isEqualTo("com.foo.project:com.foo.project.module1.feature");
     assertThat(module1Feature.getName()).isEqualTo("Foo Module 1 Feature");
     assertThat(module1Feature.getVersion()).isEqualTo("1.0-SNAPSHOT");
@@ -618,9 +619,9 @@ public class ProjectReactorBuilderTest {
     assertThat(module1Feature.properties().get("module2.sonar.projectKey")).isNull();
     // Check baseDir and workDir
     assertThat(module1Feature.getBaseDir().getCanonicalFile())
-      .isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
+      .isEqualTo(getResource(this.getClass(), "multi-module-definitions-same-prefix/module1.feature"));
     assertThat(module1Feature.getWorkDir().getCanonicalFile())
-      .isEqualTo(new File(TestUtils.getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_com.foo.project.module1.feature"));
+      .isEqualTo(new File(getResource(this.getClass(), "multi-module-definitions-same-prefix"), ".sonar/com.foo.project_com.foo.project.module1.feature"));
   }
 
   @Test
@@ -635,7 +636,7 @@ public class ProjectReactorBuilderTest {
 
   private Map<String, String> loadPropsFromFile(String filePath) throws IOException {
     Properties props = new Properties();
-    try (FileInputStream fileInputStream = new FileInputStream(TestUtils.getResource(this.getClass(), filePath))) {
+    try (FileInputStream fileInputStream = new FileInputStream(getResource(this.getClass(), filePath))) {
       props.load(fileInputStream);
     }
     Map<String, String> result = new HashMap<>();
@@ -645,4 +646,37 @@ public class ProjectReactorBuilderTest {
     return result;
   }
 
+  /**
+   * Search for a test resource in the classpath. For example getResource("org/sonar/MyClass/foo.txt");
+   *
+   * @param path the starting slash is optional
+   * @return the resource. Null if resource not found
+   */
+  public static File getResource(String path) {
+    String resourcePath = path;
+    if (!resourcePath.startsWith("/")) {
+      resourcePath = "/" + resourcePath;
+    }
+    URL url = ProjectReactorBuilderTest.class.getResource(resourcePath);
+    if (url != null) {
+      return FileUtils.toFile(url);
+    }
+    return null;
+  }
+
+  /**
+   * 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
+   *
+   * @return the resource. Null if resource not found
+   */
+  public static File getResource(Class baseClass, String path) {
+    String resourcePath = StringUtils.replaceChars(baseClass.getCanonicalName(), '.', '/');
+    if (!path.startsWith("/")) {
+      resourcePath += "/";
+    }
+    resourcePath += path;
+    return getResource(resourcePath);
+  }
+
 }
index 4990e3cf2a575e2813059fa918097b691a475562..653b26e09bbc0c044f04c6f85152517c86f73e45 100644 (file)
  */
 package org.sonar.batch.scan.report;
 
-import org.sonar.batch.issue.tracking.TrackedIssue;
-
 import com.google.common.collect.Lists;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.StringWriter;
@@ -30,7 +27,7 @@ import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.TimeZone;
-
+import org.apache.commons.io.IOUtils;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
@@ -48,10 +45,12 @@ import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.batch.issue.IssueCache;
+import org.sonar.batch.issue.tracking.TrackedIssue;
 import org.sonar.batch.protocol.input.BatchInput;
 import org.sonar.batch.repository.user.UserRepositoryLoader;
 import org.sonar.batch.scan.filesystem.InputPathCache;
-import org.sonar.test.JsonAssert;
+
+import static net.javacrumbs.jsonunit.assertj.JsonAssert.assertThatJson;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verifyZeroInteractions;
@@ -126,7 +125,7 @@ public class JSONReportTest {
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JsonAssert.assertJson(writer.toString()).isSimilarTo(this.getClass().getResource(this.getClass().getSimpleName() + "/report.json"));
+    assertThatJson(writer.toString()).isEqualTo(IOUtils.toString(this.getClass().getResource(this.getClass().getSimpleName() + "/report.json")));
   }
 
   @Test
@@ -145,17 +144,7 @@ public class JSONReportTest {
     StringWriter writer = new StringWriter();
     jsonReport.writeJson(writer);
 
-    JsonAssert.assertJson(writer.toString()).isSimilarTo(this.getClass().getResource(this.getClass().getSimpleName() + "/report-without-resolved-issues.json"));
-  }
-
-  @Test
-  public void should_ignore_components_without_issue() {
-    when(issueCache.all()).thenReturn(Collections.<TrackedIssue>emptyList());
-
-    StringWriter writer = new StringWriter();
-    jsonReport.writeJson(writer);
-
-    JsonAssert.assertJson(writer.toString()).isSimilarTo("{\"version\":\"3.6\"}");
+    assertThatJson(writer.toString()).isEqualTo(IOUtils.toString(this.getClass().getResource(this.getClass().getSimpleName() + "/report-without-resolved-issues.json")));
   }
 
   @Test
index d05703e5d300eb4958271681c13f45f796a9da8f..a33e06342fa2e445b8a0b8bbb81f029c406a402f 100644 (file)
@@ -4,6 +4,7 @@
     {
       "key": "200",
       "component": "struts:src/main/java/org/apache/struts/Action.java",
+      "line": 1,
       "startLine": 1,
       "startOffset": 3,
       "endLine": 2,
@@ -15,7 +16,7 @@
       "isNew": false,
       "assignee": "simon",
       "effortToFix": 3.14,
-      "creationDate": "2013-04-24T00:00:00+0200"
+      "creationDate": "${json-unit.ignore}"
     }
   ],
   "components": [
index 9efd2fee2700416afda897f10560ac1c8dc99561..a93f232260bb4a880e4dc9200f5b7c402ab87436 100644 (file)
     </dependency>
 
     <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
       <scope>test</scope>
     </dependency>
 
index 27b3acb2fd2bf45602e8929b4599266ddf9e8aeb..f62fca72ca19f55d25090f335a868a7268cd0b96 100644 (file)
     </dependency>
 
     <!-- unit tests -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hamcrest</groupId>
+      <artifactId>hamcrest-all</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
-      <scope>test</scope>
-    </dependency>
     <dependency>
       <groupId>ch.qos.logback</groupId>
       <artifactId>logback-classic</artifactId>
index fb52d9ed620947912b73c2ad6938ee7a7c92d4f8..58a57bf1d7c0315477e84287ac43f36ff35d1396 100644 (file)
     </dependency>
 
     <dependency>
-      <groupId>${project.groupId}</groupId>
-      <artifactId>sonar-testing-harness</artifactId>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.assertj</groupId>
+      <artifactId>assertj-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.mockito</groupId>
+      <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>