]> source.dussan.org Git - sonarqube.git/commitdiff
fix coverage of DefaultProcessCommands
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 24 Aug 2016 10:31:34 +0000 (12:31 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 25 Aug 2016 13:05:41 +0000 (15:05 +0200)
server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java

index 42679895aad1001eba2ca893e6b412e4e9a5cf6f..8836fe6551298333643aaf0b575573546c062942 100644 (file)
@@ -54,79 +54,116 @@ public class DefaultProcessCommandsTest {
   }
 
   @Test
-  public void child_process_update_the_mapped_memory() throws Exception {
+  public void main_clears_the_memory_space_of_the_specified_process_number() throws IOException {
     File dir = temp.newFolder();
 
-    DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER);
-    assertThat(commands.isUp()).isFalse();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      commands.setUp();
+      commands.setHttpUrl("bla");
+      commands.setOperational();
+    }
 
-    commands.setUp();
-    assertThat(commands.isUp()).isTrue();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      assertThat(commands.isUp()).isFalse();
+      assertThat(commands.getHttpUrl()).isEmpty();
+      assertThat(commands.isOperational()).isFalse();
+    }
   }
 
   @Test
-  public void reset_clears_only_the_memory_space_of_specified_process_number() throws IOException {
+  public void secondary_does_not_clear_the_memory_space_of_the_specified_process_number() throws IOException {
     File dir = temp.newFolder();
 
-    AllProcessesCommands commands = new AllProcessesCommands(dir);
-    for (int i = 0; i < MAX_PROCESSES; i++) {
-      commands.setOperational(i);
-      commands.setUp(i);
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      commands.setUp();
+      commands.setHttpUrl("bla");
+      commands.setOperational();
     }
 
-    int resetProcess = 3;
-    DefaultProcessCommands.reset(dir, resetProcess);
-    for (int i = 0; i < MAX_PROCESSES; i++) {
-      assertThat(commands.isOperational(i)).isEqualTo(i != resetProcess);
-      assertThat(commands.isUp(i)).isEqualTo(i != resetProcess);
+    try (DefaultProcessCommands commands = DefaultProcessCommands.secondary(dir, PROCESS_NUMBER)) {
+      assertThat(commands.isUp()).isTrue();
+      assertThat(commands.getHttpUrl()).isEqualTo("bla");
+      assertThat(commands.isOperational()).isTrue();
+    }
+  }
+
+  @Test
+  public void child_process_update_the_mapped_memory() throws Exception {
+    File dir = temp.newFolder();
+
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      assertThat(commands.isUp()).isFalse();
+      commands.setUp();
+      assertThat(commands.isUp()).isTrue();
+    }
+  }
+
+  @Test
+  public void reset_clears_only_the_memory_space_of_specified_process_number() throws IOException {
+    File dir = temp.newFolder();
+
+    try (AllProcessesCommands commands = new AllProcessesCommands(dir)) {
+      for (int i = 0; i < MAX_PROCESSES; i++) {
+        commands.setOperational(i);
+        commands.setUp(i);
+      }
+
+      int resetProcess = 3;
+      DefaultProcessCommands.reset(dir, resetProcess);
+      for (int i = 0; i < MAX_PROCESSES; i++) {
+        assertThat(commands.isOperational(i)).isEqualTo(i != resetProcess);
+        assertThat(commands.isUp(i)).isEqualTo(i != resetProcess);
+      }
     }
-    commands.close();
   }
 
   @Test
   public void ask_for_stop() throws Exception {
     File dir = temp.newFolder();
 
-    DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER);
-    assertThat(commands.askedForStop()).isFalse();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      assertThat(commands.askedForStop()).isFalse();
 
-    commands.askForStop();
-    assertThat(commands.askedForStop()).isTrue();
+      commands.askForStop();
+      assertThat(commands.askedForStop()).isTrue();
+    }
   }
 
   @Test
   public void ask_for_restart() throws Exception {
     File dir = temp.newFolder();
 
-    DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER);
-    assertThat(commands.askedForRestart()).isFalse();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      assertThat(commands.askedForRestart()).isFalse();
 
-    commands.askForRestart();
-    assertThat(commands.askedForRestart()).isTrue();
+      commands.askForRestart();
+      assertThat(commands.askedForRestart()).isTrue();
+    }
   }
 
   @Test
   public void acknowledgeAskForRestart_has_no_effect_when_no_restart_asked() throws Exception {
     File dir = temp.newFolder();
 
-    DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER);
-    assertThat(commands.askedForRestart()).isFalse();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      assertThat(commands.askedForRestart()).isFalse();
 
-    commands.acknowledgeAskForRestart();
-    assertThat(commands.askedForRestart()).isFalse();
+      commands.acknowledgeAskForRestart();
+      assertThat(commands.askedForRestart()).isFalse();
+    }
   }
 
   @Test
   public void acknowledgeAskForRestart_resets_askForRestart_has_no_effect_when_no_restart_asked() throws Exception {
     File dir = temp.newFolder();
 
-    DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER);
-
-    commands.askForRestart();
-    assertThat(commands.askedForRestart()).isTrue();
+    try (DefaultProcessCommands commands = DefaultProcessCommands.main(dir, PROCESS_NUMBER)) {
+      commands.askForRestart();
+      assertThat(commands.askedForRestart()).isTrue();
 
-    commands.acknowledgeAskForRestart();
-    assertThat(commands.askedForRestart()).isFalse();
+      commands.acknowledgeAskForRestart();
+      assertThat(commands.askedForRestart()).isFalse();
+    }
   }
 
   @Test
@@ -135,7 +172,10 @@ public class DefaultProcessCommandsTest {
 
     expectProcessNumberNoValidIAE(processNumber);
 
-    DefaultProcessCommands.main(temp.newFolder(), processNumber);
+
+    try (DefaultProcessCommands main = DefaultProcessCommands.main(temp.newFolder(), processNumber)) {
+
+    }
   }
 
   @Test
@@ -144,15 +184,20 @@ public class DefaultProcessCommandsTest {
 
     expectProcessNumberNoValidIAE(processNumber);
 
-    DefaultProcessCommands.main(temp.newFolder(), processNumber);
+    try (DefaultProcessCommands main = DefaultProcessCommands.main(temp.newFolder(), processNumber)) {
+
+    }
   }
+
   @Test
   public void main_fails_if_processNumber_is_MAX_PROCESSES() throws Exception {
     int processNumber = MAX_PROCESSES;
 
     expectProcessNumberNoValidIAE(processNumber);
 
-    DefaultProcessCommands.main(temp.newFolder(), processNumber);
+    try (DefaultProcessCommands main = DefaultProcessCommands.main(temp.newFolder(), processNumber)) {
+
+    }
   }
 
   @Test
@@ -170,7 +215,9 @@ public class DefaultProcessCommandsTest {
 
     expectProcessNumberNoValidIAE(processNumber);
 
-    DefaultProcessCommands.secondary(temp.newFolder(), processNumber);
+    try (DefaultProcessCommands secondary = DefaultProcessCommands.secondary(temp.newFolder(), processNumber)) {
+
+    }
   }
 
   @Test