From: Simon Brandhof Date: Thu, 25 Sep 2014 21:41:41 +0000 (+0200) Subject: SONAR-4898 add missing tests X-Git-Tag: 4.5-RC3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea1ac3789b9128e394284d82dfeaeab32dd441d8;p=sonarqube.git SONAR-4898 add missing tests --- 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 @@ - junit - junit - test - - - org.hamcrest - hamcrest-all - test - - - org.easytesting - fest-assert + org.codehaus.sonar + sonar-testing-harness test 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); + } }