]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4898 add missing tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 25 Sep 2014 21:41:41 +0000 (23:41 +0200)
committerSimon Brandhof <simon.brandhof@sonarsource.com>
Thu, 25 Sep 2014 21:41:41 +0000 (23:41 +0200)
server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java
sonar-application/pom.xml
sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java

index d79f0f92899359e7a2bc18e7c884549b3e32b442..1c7af0c004eff49ae9914b6b1b0324d2f9ca446a 100644 (file)
@@ -52,6 +52,7 @@ public class ProcessCommands {
     this.stopFile = new File(directory, processKey + ".stop");
   }
 
+  // visible for tests
   ProcessCommands(File readyFile, File stopFile) {
     this.readyFile = readyFile;
     this.stopFile = stopFile;
index e81a537e2ee984da26bac443bb031754db8c997b..984fbed74f7fd32363f3b0f3c8feb585b14586e9 100644 (file)
@@ -37,7 +37,20 @@ public class ProcessCommandsTest {
   public TemporaryFolder temp = new TemporaryFolder();
 
   @Test
-  public void delete_files_on_monitor_startup() throws Exception {
+  public void fail_to_init_if_dir_does_not_exist() throws Exception {
+    File dir = temp.newFolder();
+    FileUtils.deleteQuietly(dir);
+
+    try {
+      new ProcessCommands(dir, "web");
+      fail();
+    } catch (IllegalArgumentException e) {
+      assertThat(e).hasMessage("Not a valid directory: " + dir.getAbsolutePath());
+    }
+  }
+
+  @Test
+  public void delete_files_on_prepare() throws Exception {
     File dir = temp.newFolder();
     assertThat(dir).exists();
     FileUtils.touch(new File(dir, "web.ready"));
@@ -67,18 +80,32 @@ public class ProcessCommandsTest {
 
   @Test
   public void child_process_create_file_when_ready() throws Exception {
-    File readyFile = temp.newFile();
+    File dir = temp.newFolder();
 
-    ProcessCommands commands = new ProcessCommands(readyFile, temp.newFile());
+    ProcessCommands commands = new ProcessCommands(dir, "web");
     commands.prepare();
     assertThat(commands.isReady()).isFalse();
-    assertThat(readyFile).doesNotExist();
+    assertThat(commands.getReadyFile()).doesNotExist();
 
     commands.setReady();
     assertThat(commands.isReady()).isTrue();
-    assertThat(readyFile).exists();
+    assertThat(commands.getReadyFile()).exists().isFile();
 
     commands.endWatch();
-    assertThat(readyFile).doesNotExist();
+    assertThat(commands.getReadyFile()).doesNotExist();
+  }
+
+  @Test
+  public void ask_for_stop() throws Exception {
+    File dir = temp.newFolder();
+
+    ProcessCommands commands = new ProcessCommands(dir, "web");
+    assertThat(commands.askedForStop()).isFalse();
+    assertThat(commands.getStopFile()).doesNotExist();
+
+    commands.askForStop();
+    assertThat(commands.askedForStop()).isTrue();
+    assertThat(commands.getStopFile()).exists().isFile();
+    assertThat(commands.getStopFile().getName()).isEqualTo("web.stop");
   }
 }
index ee68ed3ce4a897865c1bdfe308d387b1a41c8ab3..26844b97f931e90d792c8a0fab8f0c24874732f5 100644 (file)
 
     <!-- unit tests -->
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.hamcrest</groupId>
-      <artifactId>hamcrest-all</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.easytesting</groupId>
-      <artifactId>fest-assert</artifactId>
+      <groupId>org.codehaus.sonar</groupId>
+      <artifactId>sonar-testing-harness</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
index 11bcb2f56312c434194718d50ef2da7d92c28da8..49a66bc590cf560de16a740753d54251874b5955 100644 (file)
@@ -21,6 +21,7 @@ package org.sonar.application;
 
 import org.junit.Test;
 import org.sonar.process.Props;
+import org.sonar.test.TestUtils;
 
 import java.util.Properties;
 
@@ -56,4 +57,9 @@ public class DefaultSettingsTest {
     DefaultSettings.init(props);
     assertThat(props.valueAsInt("sonar.search.port")).isGreaterThan(0);
   }
+
+  @Test
+  public void private_constructor() throws Exception {
+    TestUtils.assertPrivateConstructor(DefaultSettings.class);
+  }
 }