aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-process
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-25 23:41:41 +0200
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-09-25 23:41:41 +0200
commitea1ac3789b9128e394284d82dfeaeab32dd441d8 (patch)
tree3e141637f0f072b113ac54b2e04735f43a2e3c35 /server/sonar-process
parent9654662b48c918b55383846c6575b7f809437108 (diff)
downloadsonarqube-ea1ac3789b9128e394284d82dfeaeab32dd441d8.tar.gz
sonarqube-ea1ac3789b9128e394284d82dfeaeab32dd441d8.zip
SONAR-4898 add missing tests
Diffstat (limited to 'server/sonar-process')
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java1
-rw-r--r--server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java39
2 files changed, 34 insertions, 6 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
index d79f0f92899..1c7af0c004e 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
@@ -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;
diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java
index e81a537e2ee..984fbed74f7 100644
--- a/server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java
+++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessCommandsTest.java
@@ -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");
}
}