### Question:
StreamUtilities { public static <T> List<T> filter(Collection<? extends T> input, Predicate<? super T> predicate) { List<T> list; if (predicate != null) { list = CollectionUtilities.hasContent(input) ? input.stream().filter(predicate).collect(Collectors.toList()) : New.list(); } else { list = New.list(input); } return list; } private  StreamUtilities(); static boolean anyMatch(Iterable<? extends T> input, Predicate<? super T> filter); static List<T> filter(Collection<? extends T> input, Predicate<? super T> predicate); @SuppressWarnings("unchecked") static T[] filter(T[] input, Predicate<? super T> predicate); static T filterOne(Collection<? extends T> input, Predicate<? super T> predicate); @SuppressWarnings("unchecked") static Stream<T> filterDowncast(Stream<?> input, Class<T> type); static Collection<R> map(Collection<? extends T> input, Function<? super T, ? extends R> mapper,
            CollectionProvider<R> collectionProvider); @SuppressWarnings("unchecked") static List<R> map(Iterable<? extends T> input, Function<? super T, ? extends R> mapper);  }### Answer:
@Test public void testFilter() { Collection<String> actual; Collection<String> expected; expected = New.list(0); actual = StreamUtilities.filter(Collections.<String>emptyList(), null); Assert.assertEquals(expected, actual); expected = Arrays.asList(new String[] { "Apple", "Apricot" }); actual = StreamUtilities.filter(INPUT, new Predicate<String>() { @Override public boolean test(String s) { return s.charAt(0) == 'A'; } }); Assert.assertEquals(expected, actual); actual = StreamUtilities.filter(INPUT, new Predicate<Object>() { @Override public boolean test(Object o) { return o.toString().charAt(0) == 'A'; } }); Assert.assertEquals(expected, actual); }
@Test public void testFilterArray() { String[] expected = new String[] { "Apple", "Apricot" }; String[] actual; actual = StreamUtilities.filter(INPUT_ARRAY, new Predicate<String>() { @Override public boolean test(String s) { return s.charAt(0) == 'A'; } }); Assert.assertTrue(Arrays.equals(expected, actual)); }