Lists { public static <T> List<T> emptyToNull(final List<T> list) { if (isEmpty(list)) { return null; } else { return list; } } private  Lists(); static List<T> createWhenNull(final List<T> list); static List<T> create(final T item); static T firstEntry(final List<T> list); static boolean isEmpty(final List<?> list); static boolean isNotEmpty(final List<?> list); static boolean sizeIs(final List<?> list, final int size); static List<T> emptyToNull(final List<T> list);  }
@Test public void testEmptyToNull() { final List<Integer> nullList = null; final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithOneEntry = Arrays.asList(1); assertThat(Lists.emptyToNull(nullList), is(nullValue())); assertThat(Lists.emptyToNull(listWithoutEntries), is(nullValue())); assertThat(Lists.emptyToNull(listWithOneEntry), is(notNullValue())); }