ArrayUtils { public static <T> T getFirst(final T... array) { return (array != null && array.length > 0 ? array[0] : null); }  static T getElementAtIndex(T[] array, int index, T defaultValue); static T getFirst(final T... array); static String toString(final Object... array); static String toString(final String... array); static Object[] insert(Object[] originalArray, int pos, Object element); static Object[] remove(Object[] originalArray, int pos); static String objectRefString(Object obj); static void objectRefString(Object obj, StringBuilder sb); static String objectString(Object obj); static void objectString(Object obj, StringBuilder sb); static String objectStringNonRecursive(@Unretained Object obj); static boolean areByteArrayArrayEquals(byte[][] v1, byte[][] v2); static void objectStringNonRecursive(@Unretained Object obj, StringBuilder sb); static boolean objectEquals(Object o1, Object o2); static Integer[] toIntegerArray(final int[] array); static Byte[][] toByteArray(final byte[][] array); static byte[][] toBytes(final Byte[][] byteArray); static List<T> asList(T... array);  }
@Test public void getFirst_array_returnsFirstElement() { assertThat(getFirst("first", "second", "third")).isEqualTo("first"); }
@Test public void getFirst_arrayContainingNull_returnsFirstElement() { assertThat(getFirst("null", "nil", null)).isEqualTo("null"); }
@Test public void getFirst_oneElement_returnsFirstElement() { assertThat(getFirst("test")).isEqualTo("test"); }
@Test public void getFirst_null_returnsNull() { Object nullObject = null; assertThat(getFirst(nullObject)).isNull(); }
@Test public void getFirst_empty_returnsNull() { Object[] emptyArray = new Object[0]; assertThat((Object[]) getFirst(emptyArray)).isNull(); }
@Test public void getFirst_arrayOfNullValues_returnsNull() { assertThat((Object) getFirst(null, null, null)).isNull(); }