Clean up the test runner code a bit.

Small steps towards #1150.

--
MOS_MIGRATED_REVID=125158135
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
index b99b06c..baa4ee8 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/BUILD
@@ -21,7 +21,6 @@
         "//third_party:dagger",
         "//third_party:guava",
         "//third_party:joda_time",
-        "//third_party:jsr305",
         "//third_party:junit4",
     ],
 )
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal/BUILD
index 149420b..2c9a488 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal/BUILD
@@ -5,8 +5,6 @@
     srcs = glob(["*.java"]),
     deps = [
         "//third_party:guava",
-        "//third_party:joda_time",
-        "//third_party:jsr305",
         "//third_party:jsr330_inject",
         "//third_party:junit4",
     ],
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
index f5f2ecd..819ad9f 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/BUILD
@@ -23,7 +23,6 @@
         "//src/java_tools/junitrunner/java/com/google/testing/junit/runner/util",
         "//third_party:dagger",
         "//third_party:guava",
-        "//third_party:joda_time",
         "//third_party:jsr305",
         "//third_party:jsr330_inject",
         "//third_party:junit4",
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
index a25d3a3..9f76bd8 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Config.java
@@ -15,7 +15,6 @@
 package com.google.testing.junit.runner.junit4;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Function;
 import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 
@@ -74,16 +73,11 @@
    */
   public Optional<Path> getXmlOutputPath() {
     if (!xmlOutputPath.isPresent()) {
-      Optional<String> envXmlOutputPath =
-          Optional.fromNullable(System.getenv(XML_OUTPUT_FILE_ENV_VAR));
-      return envXmlOutputPath.transform(new Function<String, Path>() {
-          @Override
-          public Path apply(String path) {
-            return FileSystems.getDefault().getPath(path);
-          }
-        });
+      String envXmlOutputPath = System.getenv(XML_OUTPUT_FILE_ENV_VAR);
+      return envXmlOutputPath == null
+          ? Optional.<Path>absent()
+          : Optional.of(FileSystems.getDefault().getPath(envXmlOutputPath));
     }
-
     return xmlOutputPath;
   }
 
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java
index 966478d..10f7a72 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4InstanceModules.java
@@ -73,12 +73,12 @@
     @Provides
     @Singleton
     JUnit4Options options() {
-      return JUnit4Options.parse(System.getenv(), ImmutableList.copyOf(args));
+      return JUnit4Options.parse(System.getenv(), args);
     }
 
     @Provides
     @Singleton
-    JUnit4Config config(JUnit4Options options) {
+    static JUnit4Config config(JUnit4Options options) {
       return new JUnit4Config(
           options.getTestIncludeFilter(), options.getTestExcludeFilter(), Optional.<Path>absent());
     }
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java
index d421774..13e6e57 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4Options.java
@@ -15,9 +15,9 @@
 package com.google.testing.junit.runner.junit4;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -44,8 +44,8 @@
    * object representing the parsed arguments.
    */
   static JUnit4Options parse(Map<String, String> envVars, List<String> args) {
-    ImmutableList.Builder<String> unparsedArgsBuilder = ImmutableList.builder();
-    Map<String, String> optionsMap = Maps.newHashMap();
+    List<String> unparsedArgs = new ArrayList<>();
+    Map<String, String> optionsMap = new HashMap<>();
 
     optionsMap.put(TEST_INCLUDE_FILTER_OPTION, null);
     optionsMap.put(TEST_EXCLUDE_FILTER_OPTION, null);
@@ -68,7 +68,7 @@
         optionsMap.put(arg, it.next());
         continue;
       }
-      unparsedArgsBuilder.add(arg);
+      unparsedArgs.add(arg);
     }
     // If TESTBRIDGE_TEST_ONLY is set in the environment, forward it to the
     // --test_filter flag.
@@ -77,10 +77,9 @@
       optionsMap.put(TEST_INCLUDE_FILTER_OPTION, testFilter);
     }
 
-    ImmutableList<String> unparsedArgs = unparsedArgsBuilder.build();
     return new JUnit4Options(optionsMap.get(TEST_INCLUDE_FILTER_OPTION),
                              optionsMap.get(TEST_EXCLUDE_FILTER_OPTION),
-                             unparsedArgs.toArray(new String[unparsedArgs.size()]));
+                             unparsedArgs.toArray(new String[0]));
   }
 
   private final String testIncludeFilter;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
index 609591b..d76c7f6 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4/JUnit4TestXmlListener.java
@@ -39,7 +39,6 @@
  */
 @Singleton
 class JUnit4TestXmlListener extends RunListener  {
-
   private final Supplier<TestSuiteModel> modelSupplier;
   private final CancellableRequestFactory requestFactory;
   private final SignalHandlers signalHandlers;
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
index 98a6cb1..3d18567 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestCaseNode.java
@@ -24,8 +24,6 @@
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.LinkedListMultimap;
 import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 import com.google.common.collect.Multimaps;
 import com.google.common.collect.Multiset;
 import com.google.testing.junit.runner.model.TestResult.Status;
@@ -35,9 +33,11 @@
 import org.junit.runner.Description;
 
 import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 import javax.annotation.Nullable;
@@ -47,7 +47,7 @@
  */
 class TestCaseNode extends TestNode implements TestPropertyExporter.Callback {
   private final TestSuiteNode parent;
-  private final Map<String, String> properties = Maps.newConcurrentMap();
+  private final Map<String, String> properties = new ConcurrentHashMap<>();
   private final Multiset<String> repeatedPropertyNames = ConcurrentHashMultiset.create();
   private final Queue<Throwable> globalFailures = new ConcurrentLinkedQueue<>();
   private final ListMultimap<Description, Throwable> dynamicTestToFailures =
@@ -177,7 +177,7 @@
 
     // For now, we give each dynamic test an empty properties map and the same
     // run time and status as its parent test case, but this may change.
-    List<TestResult> childResults = Lists.newLinkedList();
+    List<TestResult> childResults = new LinkedList<>();
     for (Description dynamicTest : getDescription().getChildren()) {
       childResults.add(buildDynamicResult(dynamicTest, getRuntime(), getTestResultStatus()));
     }
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java
index 758ab35..a7f14ab 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteModel.java
@@ -24,7 +24,6 @@
 import com.google.common.base.Preconditions;
 import com.google.common.base.Ticker;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
 import com.google.testing.junit.junit4.runner.DynamicTestException;
 import com.google.testing.junit.runner.sharding.ShardingEnvironment;
 import com.google.testing.junit.runner.sharding.ShardingFilters;
@@ -37,6 +36,7 @@
 import java.io.OutputStream;
 import java.io.StringWriter;
 import java.util.Collection;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -285,7 +285,7 @@
     }
 
     private Filter getShardingFilter(Description... topLevelSuites) {
-      Collection<Description> tests = Lists.newLinkedList();
+      Collection<Description> tests = new LinkedList<>();
       for (Description suite : topLevelSuites) {
         collectTests(suite, tests);
       }
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
index f6656e4..265c2c0 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/TestSuiteNode.java
@@ -18,12 +18,12 @@
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
 import com.google.testing.junit.runner.model.TestResult.Status;
 
 import org.joda.time.Interval;
 import org.junit.runner.Description;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
@@ -32,8 +32,7 @@
  * A parent node in the test suite model.
  */
 class TestSuiteNode extends TestNode {
-
-  private final List<TestNode> children = Lists.newArrayList();
+  private final List<TestNode> children = new ArrayList<>();
 
   TestSuiteNode(Description description) {
     super(description);
@@ -97,7 +96,7 @@
   protected TestResult buildResult() {
     Interval runTime = null;
     int numTests = 0, numFailures = 0;
-    LinkedList<TestResult> childResults = Lists.newLinkedList();
+    LinkedList<TestResult> childResults = new LinkedList<>();
 
     for (TestNode child : children) {
       TestResult childResult = child.getResult();
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/XmlWriter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/XmlWriter.java
index 97636ed..ed37314 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/XmlWriter.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/model/XmlWriter.java
@@ -19,7 +19,6 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
 import com.google.common.xml.XmlEscapers;
 
 import java.io.IOException;
@@ -27,6 +26,7 @@
 import java.io.OutputStreamWriter;
 import java.io.StringWriter;
 import java.io.Writer;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -40,7 +40,7 @@
   private final Writer writer;
   private boolean started;
   private boolean inElement;
-  private final List<String> elementStack = Lists.newArrayList();
+  private final List<String> elementStack = new ArrayList<>();
 
   /**
    * Creates an XML writer that writes to the given {@code OutputStream}.
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/HashBackedShardingFilter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/HashBackedShardingFilter.java
index 9225ca2..aa641a4 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/HashBackedShardingFilter.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/HashBackedShardingFilter.java
@@ -23,8 +23,7 @@
  * Sharding filter that uses the hashcode of the test description to
  * assign it to a shard.
  */
-class HashBackedShardingFilter extends Filter {
-
+final class HashBackedShardingFilter extends Filter {
   private final int shardIndex;
   private final int totalShards;
 
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/RoundRobinShardingFilter.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/RoundRobinShardingFilter.java
index 38d9f11..09c9e31 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/RoundRobinShardingFilter.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/RoundRobinShardingFilter.java
@@ -16,15 +16,15 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
 
 import org.junit.runner.Description;
 import org.junit.runner.manipulation.Filter;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -40,7 +40,6 @@
  * sharding, but are done so that this filter can be compared in tests.
  */
 public final class RoundRobinShardingFilter extends Filter {
-
   @VisibleForTesting
   final Map<Description, Integer> testToShardMap;
   @VisibleForTesting
@@ -63,11 +62,11 @@
    */
   private static Map<Description, Integer> buildTestToShardMap(
       Collection<Description> testDescriptions) {
-    Map<Description, Integer> map = Maps.newHashMap();
+    Map<Description, Integer> map = new HashMap<>();
 
     // Sorting this list is incredibly important to correctness. Otherwise,
     // "shuffled" suites would break the sharding protocol.
-    List<Description> sortedDescriptions = Lists.newArrayList(testDescriptions);
+    List<Description> sortedDescriptions = new ArrayList<>(testDescriptions);
     Collections.sort(sortedDescriptions, new DescriptionComparator());
 
     // If we get two descriptions that are equal, the shard number for the second
@@ -110,5 +109,4 @@
       return d1.getDisplayName().compareTo(d2.getDisplayName());
     }
   }
-
 }
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/ShardingFilterFactory.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/ShardingFilterFactory.java
index 71cb9ea..5e6da3d 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/ShardingFilterFactory.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/ShardingFilterFactory.java
@@ -24,7 +24,6 @@
  * no-argument constructor.
  */
 public interface ShardingFilterFactory {
-
   /**
    * Creates a test sharding filter.
    *  
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/WeightStrategy.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/WeightStrategy.java
index 3ee6458..567bc23 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/WeightStrategy.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/api/WeightStrategy.java
@@ -20,7 +20,6 @@
  * Extracts the weight associated with a test for use by sharding filters.
  */
 public interface WeightStrategy {
-  
   /**
    * Returns the weight of a test extracted from its description.
    * 
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/RoundRobinShardingFilterFactory.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/RoundRobinShardingFilterFactory.java
index 45af5de..d6c4cc2 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/RoundRobinShardingFilterFactory.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/RoundRobinShardingFilterFactory.java
@@ -25,11 +25,10 @@
 /**
  * Creates a {@link RoundRobinShardingFilter} for use in tests.
  */
-public class RoundRobinShardingFilterFactory implements ShardingFilterFactory {
-
-    @Override
-    public Filter createFilter(
-        Collection<Description> testDescriptions, int shardIndex, int totalShards) {
-      return new RoundRobinShardingFilter(testDescriptions, shardIndex, totalShards);
-    }
+public final class RoundRobinShardingFilterFactory implements ShardingFilterFactory {
+  @Override
+  public Filter createFilter(
+      Collection<Description> testDescriptions, int shardIndex, int totalShards) {
+    return new RoundRobinShardingFilter(testDescriptions, shardIndex, totalShards);
+  }
 }
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/ShardingFilterTestCase.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/ShardingFilterTestCase.java
index 1cffdb7..668c790 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/ShardingFilterTestCase.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding/testing/ShardingFilterTestCase.java
@@ -19,7 +19,6 @@
 import com.google.common.collect.ArrayListMultimap;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ListMultimap;
-import com.google.common.collect.Lists;
 import com.google.testing.junit.runner.sharding.api.ShardingFilterFactory;
 
 import junit.framework.TestCase;
@@ -29,13 +28,13 @@
 import org.junit.runner.manipulation.Filter;
 
 import java.util.Deque;
+import java.util.LinkedList;
 import java.util.List;
 
 /**
  * Common base class for all sharding filter tests.
  */
 public abstract class ShardingFilterTestCase extends TestCase {
-
   static final List<Description> TEST_DESCRIPTIONS = createGenericTestCaseDescriptions(6);
 
   /**
@@ -166,7 +165,7 @@
     if (descriptions.isEmpty()) {
       return ArrayListMultimap.create();
     }
-    Deque<Description> mutatingDescriptions = Lists.newLinkedList(descriptions);
+    Deque<Description> mutatingDescriptions = new LinkedList<>(descriptions);
     ListMultimap<Filter, Description> descriptionsRun = ArrayListMultimap.create();
 
     for (Filter filter : filters) {
diff --git a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/TestNameProvider.java b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/TestNameProvider.java
index 3767e64..6348ebf 100644
--- a/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/TestNameProvider.java
+++ b/src/java_tools/junitrunner/java/com/google/testing/junit/runner/util/TestNameProvider.java
@@ -24,5 +24,5 @@
   /**
    * Gets the description of the current test.
    */
-  public Description get();
+  Description get();
 }