CollectionUtil { public static <T> TreeSet<T> treeSet(final T item) { final TreeSet<T> treeSet = new TreeSet<>(); if (null != item) { treeSet.add(item); } return treeSet; } private  CollectionUtil(); static Iterable[] toIterableArray(final Collection<? extends Iterable> collection); static TreeSet<T> treeSet(final T item); static TreeSet<T> treeSet(final T[] items); static void toMapWithClassKeys(final Map<String, V> mapAsStrings, final Map<Class<? extends K>, V> map); static Map<Class<? extends K>, V> toMapWithClassKeys(final Map<String, V> mapAsStrings); static void toMapWithStringKeys(final Map<Class<? extends K>, V> map, final Map<String, V> mapAsStrings); static Map<String, V> toMapWithStringKeys(final Map<Class<? extends K>, V> map); static boolean containsAny(final Collection collection, final Object[] objects); static boolean anyMissing(final Collection collection, final Object[] objects); static boolean distinct(final Collection<T> collection);  }
@Test public void shouldReturnTreeSetWithProvidedItem() { final String item = "test item"; final TreeSet<String> treeSet = CollectionUtil.treeSet(item); assertEquals(1, treeSet.size()); assertTrue(treeSet.contains(item)); }
@Test public void shouldReturnTreeSetWithWithOutNullItem() { final TreeSet<String> treeSet = CollectionUtil.treeSet(null); assertEquals(0, treeSet.size()); }
@Test public void shouldReturnTreeSetWithProvidedItems() { final String[] items = {"test item 1", "test item 2", null}; final TreeSet<String> treeSet = CollectionUtil.treeSet(items); assertEquals(2, treeSet.size()); for (final String item : items) { if (null != item) { assertTrue(treeSet.contains(item)); } } }
@Test public void shouldReturnTreeSetWithNoItemsForNullArray() { final TreeSet<String> treeSet = CollectionUtil.treeSet(null); assertEquals(0, treeSet.size()); }