### Question:
KMeansUtils { public static Pair<ClusterInfo,Double> closestCluster(List<ClusterInfo> clusters, DistanceFn<double[]> distanceFn, double[] vector) { Preconditions.checkArgument(!clusters.isEmpty()); double closestDist = Double.POSITIVE_INFINITY; ClusterInfo minCluster = null; for (ClusterInfo cluster : clusters) { double distance = distanceFn.applyAsDouble(cluster.getCenter(), vector); if (distance < closestDist) { closestDist = distance; minCluster = cluster; } } Preconditions.checkNotNull(minCluster); Preconditions.checkState(!Double.isInfinite(closestDist) && !Double.isNaN(closestDist)); return new Pair<>(minCluster, closestDist); } private  KMeansUtils(); static Pair<ClusterInfo,Double> closestCluster(List<ClusterInfo> clusters,
                                                        DistanceFn<double[]> distanceFn,
                                                        double[] vector); static double[] featuresFromTokens(String[] data, InputSchema inputSchema); static void checkUniqueIDs(Collection<ClusterInfo> clusters);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testNoClusters() { KMeansUtils.closestCluster(Collections.emptyList(), DISTANCE_FN, new double[] { 1.0 }); }
@Test public void testClosestCluster() { List<ClusterInfo> clusters = Arrays.asList( new ClusterInfo(2, new double[] { 1.0, 2.0 }, 1), new ClusterInfo(4, new double[] { 0.0, -2.0 }, 1), new ClusterInfo(1, new double[] { 3.0, 1.0 }, 1) ); Pair<ClusterInfo,Double> closestPairA = KMeansUtils.closestCluster(clusters, DISTANCE_FN, new double[] { 0.0, -2.0 }); assertEquals(4, closestPairA.getFirst().getID()); assertEquals(0.0, closestPairA.getSecond().doubleValue()); Pair<ClusterInfo,Double> closestPairB = KMeansUtils.closestCluster(clusters, DISTANCE_FN, new double[] { 6.0, 5.0 }); assertEquals(1, closestPairB.getFirst().getID()); assertEquals(5.0, closestPairB.getSecond().doubleValue()); }