ServiceUtil { public static Service[] discardNulls(Service... services) { List<Service> list = new ArrayList<>(); for (Service s : services) { if (s != null) { list.add(s); } } return list.toArray(new Service[0]); }  static Service[] discardNulls(Service... services); static Service rewriteConnectionsForTesting(Service service);  }
@Test public void testDiscardNull() throws Exception { assertEquals(2, discardNulls(new NullService(), new NullService()).length); assertEquals(1, discardNulls(new NullService(), null, null).length); assertEquals(0, discardNulls().length); }