package com.groupon.seleniumgridextras.tasks;

import com.groupon.seleniumgridextras.config.RuntimeConfig;
import com.sun.net.httpserver.HttpServer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.net.InetSocketAddress;

import static org.junit.Assert.assertEquals;

public class StopGridTest {

  private StopGrid task;
  private HttpServer server;
  private final int port = 9999;


  @Before
  public void setUp() throws Exception {
    task = new StopGrid();
    server = HttpServer.create(new InetSocketAddress(port), 0);
    server.setExecutor(null);
    server.start();
  }

  @After
  public void tearDown() throws Exception {
    server.stop(0);
  }

  @Test
  public void testGetWindowsCommand() throws Exception {
    assertEquals(
        "",task.getWindowsCommand("5555"));
  }

  @Test
  public void testGetLinuxCommand() throws Exception {
    String expected = "kill -9 " + RuntimeConfig.getOS().getCurrentPid();
    assertEquals(expected, task.getLinuxCommand(port));

    final String portToNeverBeFound = "4444444444444444444444444444444";
    assertEquals("", task.getLinuxCommand(portToNeverBeFound));
  }

}

@@ -296,16 +296,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertTrue;
 %0A%0Apublic
@@ -813,27 +813,13 @@
 sert
-Equals(%0A        %22%22,
+True(
 task
@@ -842,16 +842,45 @@
 nd(%225555
+%22).contains(%22taskkill -F -IM 
 %22));%0A  %7D

Improve the stop grid command test