]> source.dussan.org Git - sonarqube.git/commitdiff
Improve quality
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 1 Oct 2015 16:10:47 +0000 (18:10 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 1 Oct 2015 16:10:47 +0000 (18:10 +0200)
sonar-batch/src/test/java/org/sonar/batch/cache/GlobalPersistentCacheProviderTest.java
sonar-home/src/main/java/org/sonar/home/cache/FileCacheBuilder.java

index e009ddcc795f85ed66c62633014fd8816902bbad..b34e6fcd7f54a489bf32da2b197346b8539c83a8 100644 (file)
@@ -21,8 +21,11 @@ package org.sonar.batch.cache;
 
 import org.sonar.home.cache.PersistentCache;
 
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.HashMap;
 
+import static org.junit.Assert.*;
 import static org.assertj.core.api.Assertions.assertThat;
 import org.sonar.batch.bootstrap.GlobalProperties;
 import org.junit.Before;
@@ -53,4 +56,28 @@ public class GlobalPersistentCacheProviderTest {
       .resolve("http%3A%2F%2Flocalhost%3A9000")
       .resolve("global"));
   }
+
+  @Test
+  public void test_singleton() {
+    assertTrue(provider.provide(globalProperties) == provider.provide(globalProperties));
+  }
+
+  @Test
+  public void test_without_sonar_home() {
+    globalProperties = new GlobalProperties(new HashMap<String, String>());
+    PersistentCache cache = provider.provide(globalProperties);
+    assertThat(cache.getDirectory().toAbsolutePath().toString()).startsWith(findHome().toAbsolutePath().toString());
+
+  }
+
+  private static Path findHome() {
+    String home = System.getenv("SONAR_USER_HOME");
+
+    if (home != null) {
+      return Paths.get(home);
+    }
+
+    home = System.getProperty("user.home");
+    return Paths.get(home, ".sonar");
+  }
 }
index e8027081aac04bfba9ef27c0ec45fbb9274f71a4..602a92e9df3179e2ab8bea417b67628ffb2d21a5 100644 (file)
@@ -49,7 +49,7 @@ public class FileCacheBuilder {
     return FileCache.create(cacheDir, logger);
   }
   
-  private File findHome() {
+  private static File findHome() {
     String path = System.getenv("SONAR_USER_HOME");
     if (path == null) {
       // Default