Fix problem with recovering from test failure

When recovering from test failure a special --skipPast
option is passed to the TestRunner which specifies the name of
the previously failing test. The TestRunner is then expected to
skip over all tests until it gets to the one after the
previously failing test. Unfortunately, the code to parse and
remove the --skipPast option from the arguments list was
running after the argument list was being passed to
Caliper causing a failure because Caliper didn't recognize the
option.

Change-Id: Ia19c597c558b39d1449c22fc4228a8fb76a3f847
diff --git a/src/vogar/target/TestRunner.java b/src/vogar/target/TestRunner.java
index e351097..2fcf491 100644
--- a/src/vogar/target/TestRunner.java
+++ b/src/vogar/target/TestRunner.java
@@ -16,6 +16,7 @@
 
 package vogar.target;
 
+import com.google.common.annotations.VisibleForTesting;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -46,7 +47,7 @@
     private final Integer monitorPort;
 
     /** use an atomic reference so the runner can null it out when it is encountered. */
-    private final AtomicReference<String> skipPastReference;
+    @VisibleForTesting final AtomicReference<String> skipPastReference;
     private final int timeoutSeconds;
 
     private final RunnerFactory runnerFactory;
@@ -74,15 +75,6 @@
         boolean profileThreadGroup
                 = Boolean.parseBoolean(properties.getProperty(TestProperties.PROFILE_THREAD_GROUP));
 
-        boolean testOnly = Boolean.parseBoolean(properties.getProperty(TestProperties.TEST_ONLY));
-        if (testOnly) {
-            runnerFactory = new CompositeRunnerFactory(new JUnitRunnerFactory());
-        } else {
-            runnerFactory = new CompositeRunnerFactory(
-                    new JUnitRunnerFactory(),
-                    new CaliperRunnerFactory(argsList),
-                    new MainRunnerFactory());
-        }
         for (Iterator<String> i = argsList.iterator(); i.hasNext(); ) {
             String arg = i.next();
             if (arg.equals("--monitorPort")) {
@@ -97,6 +89,16 @@
             }
         }
 
+        boolean testOnly = Boolean.parseBoolean(properties.getProperty(TestProperties.TEST_ONLY));
+        if (testOnly) {
+            runnerFactory = new CompositeRunnerFactory(new JUnitRunnerFactory());
+        } else {
+            runnerFactory = new CompositeRunnerFactory(
+                    new JUnitRunnerFactory(),
+                    new CaliperRunnerFactory(argsList),
+                    new MainRunnerFactory());
+        }
+
         this.monitorPort = monitorPort;
         this.skipPastReference = new AtomicReference<>(skipPast);
         this.profile = profile;
diff --git a/test/test.properties b/test/test.properties
new file mode 100644
index 0000000..dcccf11
--- /dev/null
+++ b/test/test.properties
@@ -0,0 +1,22 @@
+#
+# Copyright (C) 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Default settings for TestRunnerTest
+timeout=10
+monitorPort=9999
+profileDepth=0
+profileInterval=2
+profileFile=profile-file
diff --git a/test/vogar/AllTests.java b/test/vogar/AllTests.java
index bcba1f2..8827f1a 100644
--- a/test/vogar/AllTests.java
+++ b/test/vogar/AllTests.java
@@ -24,6 +24,7 @@
 import vogar.android.HostRuntimeLocalTargetTest;
 import vogar.target.AssertTest;
 import vogar.target.JUnitRunnerTest;
+import vogar.target.TestRunnerTest;
 
 /**
  * Run the selection of tests that we know work.
@@ -37,7 +38,8 @@
         DeviceRuntimeSshTargetTest.class,
         HostRuntimeLocalTargetTest.class,
         JUnitRunnerTest.class,
-        ScriptBuilderEscapingTest.class
+        ScriptBuilderEscapingTest.class,
+        TestRunnerTest.class,
 })
 @RunWith(Suite.class)
 public class AllTests {
diff --git a/test/vogar/target/TestRunnerTest.java b/test/vogar/target/TestRunnerTest.java
new file mode 100644
index 0000000..0f2c7e4
--- /dev/null
+++ b/test/vogar/target/TestRunnerTest.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package vogar.target;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link TestRunner}
+ */
+@RunWith(JUnit4.class)
+public class TestRunnerTest {
+
+    @Test
+    public void testConstructor_WithSkipPast() {
+        TestRunner runner = new TestRunner(new ArrayList<>(Arrays.asList("--skipPast", "fred")));
+        String skipPast = runner.skipPastReference.get();
+        assertEquals("fred", skipPast);
+    }
+}
\ No newline at end of file