Lists { public static <T> T firstEntry(final List<T> list) { if (list != null && !list.isEmpty()) { return list.get(0); } else { return null; } } 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 testFirstEntry() { final List<Integer> nullList = null; final List<Integer> listWithoutEntries = new ArrayList<Integer>(); final List<Integer> listWithOneEntry = Arrays.asList(1); final List<Integer> listWithTwoEntries = Arrays.asList(1, 2); assertThat(Lists.firstEntry(nullList), is(nullValue())); assertThat(Lists.firstEntry(listWithoutEntries), is(nullValue())); assertThat(Lists.firstEntry(listWithOneEntry), is(1)); assertThat(Lists.firstEntry(listWithTwoEntries), is(1)); }