aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--sonar-application/pom.xml14
-rw-r--r--sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java6
4 files changed, 42 insertions, 18 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");
}
}
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml
index ee68ed3ce4a..26844b97f93 100644
--- a/sonar-application/pom.xml
+++ b/sonar-application/pom.xml
@@ -155,18 +155,8 @@
<!-- 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>
diff --git a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
index 11bcb2f5631..49a66bc590c 100644
--- a/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
+++ b/sonar-application/src/test/java/org/sonar/application/DefaultSettingsTest.java
@@ -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);
+ }
}