Fix tests for benchmarking system.

Change-Id: Ifd8fb3738e3a528f5135189017cfab39193d3418
diff --git a/benchmarks/src/test/java/com/google/gwt/benchmark/framework/client/BenchmarkFrameworkGwtTest.java b/benchmarks/src/test/java/com/google/gwt/benchmark/framework/client/BenchmarkFrameworkGwtTest.java
index df55659..e674260 100644
--- a/benchmarks/src/test/java/com/google/gwt/benchmark/framework/client/BenchmarkFrameworkGwtTest.java
+++ b/benchmarks/src/test/java/com/google/gwt/benchmark/framework/client/BenchmarkFrameworkGwtTest.java
@@ -34,8 +34,8 @@
     MockBenchmark benchmark = new MockBenchmark();
     BenchmarkExecutor executor = new BenchmarkExecutor();
     BenchmarkResult benchmarkResult = executor.executeWithFixedTime(benchmark);
-    assertEquals(2000, benchmarkResult.getTotalTimePassedMs(), 100);
-    assertEquals(40, benchmarkResult.getNumberOfRuns(), 2);
+    assertEquals(4000, benchmarkResult.getTotalTimePassedMs(), 100);
+    assertEquals(80, benchmarkResult.getNumberOfRuns(), 2);
     assertTrue(benchmark.isTearDownOneTimeCalled());
   }
 }
diff --git a/benchmarks/src/test/java/com/google/gwt/benchmark/framework/server/BenchmarkFrameworkTest.java b/benchmarks/src/test/java/com/google/gwt/benchmark/framework/server/BenchmarkFrameworkTest.java
index d02c433..c9ca97d 100644
--- a/benchmarks/src/test/java/com/google/gwt/benchmark/framework/server/BenchmarkFrameworkTest.java
+++ b/benchmarks/src/test/java/com/google/gwt/benchmark/framework/server/BenchmarkFrameworkTest.java
@@ -32,8 +32,8 @@
     MockBenchmark benchmark = new MockBenchmark();
     BenchmarkExecutor executor = new BenchmarkExecutor();
     BenchmarkResult benchmarkResult = executor.executeWithFixedTime(benchmark);
-    Assert.assertEquals(2000, benchmarkResult.getTotalTimePassedMs(), 100);
-    Assert.assertEquals(40, benchmarkResult.getNumberOfRuns(), 2);
+    Assert.assertEquals(4000, benchmarkResult.getTotalTimePassedMs(), 100);
+    Assert.assertEquals(80, benchmarkResult.getNumberOfRuns(), 2);
     Assert.assertTrue(benchmark.isTearDownOneTimeCalled());
   }
 }
diff --git a/cli/src/main/java/com/google/j2cl/benchmark/cli/CliInteractor.java b/cli/src/main/java/com/google/j2cl/benchmark/cli/CliInteractor.java
index 44c6c5f..c1f530a 100644
--- a/cli/src/main/java/com/google/j2cl/benchmark/cli/CliInteractor.java
+++ b/cli/src/main/java/com/google/j2cl/benchmark/cli/CliInteractor.java
@@ -164,10 +164,10 @@
       thread.start();
 
       int exitValue = process.waitFor();
+      thread.join();
       if (exitValue != 0) {
-        thread.join();
         logger.warning("Command returned with " + exitValue + " " + output);
-        throw new CliException("Command returned with " + exitValue);
+        throw new CliException("Command returned with " + exitValue + " " + output);
       }
 
       return output.toString();
diff --git a/server/src/main/java/com/google/j2cl/benchmark/server/BenchmarkUploadServlet.java b/server/src/main/java/com/google/j2cl/benchmark/server/BenchmarkUploadServlet.java
index b4c8b47..024dfe0 100644
--- a/server/src/main/java/com/google/j2cl/benchmark/server/BenchmarkUploadServlet.java
+++ b/server/src/main/java/com/google/j2cl/benchmark/server/BenchmarkUploadServlet.java
@@ -44,12 +44,12 @@
  */
 public class BenchmarkUploadServlet extends HttpServlet {
 
-  private static class JobIdResponse {
+  static class JobIdResponse {
     @SuppressWarnings("unused")
     JobId jobId;
   }
 
-  private static class JobResponse {
+  static class JobResponse {
     @SuppressWarnings("unused")
     Job job;
   }
diff --git a/server/src/test/java/com/google/j2cl/benchmark/server/BenchmarkUploadServletTest.java b/server/src/test/java/com/google/j2cl/benchmark/server/BenchmarkUploadServletTest.java
index 8c7d447..4db09db 100644
--- a/server/src/test/java/com/google/j2cl/benchmark/server/BenchmarkUploadServletTest.java
+++ b/server/src/test/java/com/google/j2cl/benchmark/server/BenchmarkUploadServletTest.java
@@ -17,8 +17,12 @@
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.Lists;
+import com.google.gson.GsonBuilder;
 import com.google.j2cl.benchmark.common.runner.Job;
+import com.google.j2cl.benchmark.common.runner.Job.Status;
 import com.google.j2cl.benchmark.common.runner.JobId;
+import com.google.j2cl.benchmark.common.runner.RunnerConfig;
+import com.google.j2cl.benchmark.common.runner.RunnerConfigJson;
 import com.google.j2cl.benchmark.common.runner.RunnerConfigs;
 
 import static org.junit.Assert.fail;
@@ -29,6 +33,7 @@
 import org.apache.commons.fileupload.FileItem;
 import org.junit.Before;
 import org.junit.Test;
+import org.mockito.ArgumentCaptor;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -101,16 +106,23 @@
     HttpServletResponse response = mock(HttpServletResponse.class);
     PrintWriter writer = mock(PrintWriter.class);
     when(response.getWriter()).thenReturn(writer);
+
     servlet.doGet(request, response);
-    verify(writer).write("{\"job\":{\"jobId\":{\"id\":\"jobId1\"},\"status\":\"CREATED\","
-        + "\"counter\":0,\"failedCounter\":0,\"expectedResults\":4,\"jobResultsByRunnerId\":"
-        + "{\"windows ie IE11\":{\"succeded\":false,\"result\":0.0,\"ran\":false,\"runnerConfig\":"
-        + "\"windows ie IE11\"},\"windows ie IE10\":{\"succeded\":false,\"result\":0.0,\"ran\":"
-        + "false,\"runnerConfig\":\"windows ie IE10\"},\"linux chrome\":{\"succeded\":false,"
-        + "\"result\":0.0,\"ran\":false,\"runnerConfig\":\"linux chrome\"},\"linux firefox\""
-        + ":{\"succeded\":false,\"result\":0.0,\"ran\":false,\"runnerConfig\":\"linux firefox\"}}"
-        + ",\"runnerConfigs\":[\"linux firefox\",\"linux chrome\",\"windows ie IE10\""
-        + ",\"windows ie IE11\"],\"creationTimeInMsEpoch\":1}}");
+
+    ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
+    verify(writer).write(stringCaptor.capture());
+
+
+    String json = stringCaptor.getValue();
+    BenchmarkUploadServlet.JobResponse jobResponse = new GsonBuilder()
+        .registerTypeAdapter(RunnerConfig.class, new RunnerConfigJson())
+        .create()
+        .fromJson(json, BenchmarkUploadServlet.JobResponse.class);
+    assertThat(jobResponse.job).isNotNull();
+
+    assertThat(jobResponse.job.getJobId().getId()).isEqualTo("jobId1");
+    assertThat(jobResponse.job.getStatus()).isEqualTo(Status.CREATED);
+    assertThat(jobResponse.job.getJobResults()).hasSize(4);
   }
 
   @Test