]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3895 Use proper temp folder
authorDavid Gageot <david@gageot.net>
Wed, 24 Oct 2012 14:58:53 +0000 (16:58 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 24 Oct 2012 14:58:53 +0000 (16:58 +0200)
sonar-core/src/main/java/org/sonar/core/persistence/LocalDatabaseFactory.java
sonar-core/src/test/java/org/sonar/core/persistence/LocalDatabaseFactoryTest.java

index f9bd10e9f1fc84f5fdd0f73acc268e22e2bff31c..a2e265bd5cd04f0c94b8276734dca7a4b12c3c8d 100644 (file)
@@ -47,8 +47,7 @@ public class LocalDatabaseFactory implements ServerComponent {
   }
 
   public byte[] createDatabaseForLocalMode() {
-    // serverFileSystem.getTempDir()
-    String name = System.getenv("java.io") + System.nanoTime(); // TODO
+    String name = serverFileSystem.getTempDir().getAbsolutePath() + "db-" + System.nanoTime();
 
     try {
       BasicDataSource destination = create(DIALECT, DRIVER, USER, PASSWORD, URL + name);
index 79ac446b7ec3fc8b776b86bbe6297580103dc4ca..3486fb9638a13248e594d9b2a1bbdde87a86b911 100644 (file)
@@ -26,15 +26,20 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import org.sonar.api.platform.ServerFileSystem;
 
 import java.io.File;
 import java.io.IOException;
 import java.sql.SQLException;
 
 import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
   private LocalDatabaseFactory localDatabaseFactory;
+
+  private ServerFileSystem serverFileSystem = mock(ServerFileSystem.class);
   private BasicDataSource dataSource;
 
   @Rule
@@ -42,7 +47,7 @@ public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
 
   @Before
   public void setUp() {
-    localDatabaseFactory = new LocalDatabaseFactory(getDatabase(), null);
+    localDatabaseFactory = new LocalDatabaseFactory(getDatabase(), serverFileSystem);
   }
 
   @After
@@ -56,6 +61,8 @@ public class LocalDatabaseFactoryTest extends AbstractDaoTestCase {
   public void should_create_database() throws IOException {
     setupData("should_create_database");
 
+    when(serverFileSystem.getTempDir()).thenReturn(temporaryFolder.getRoot());
+
     byte[] database = localDatabaseFactory.createDatabaseForLocalMode();
     dataSource = createDatabase(database);