@Test public void get_first_non_null_java () { String first = null; String second = "Stomp the Hawks, Badgers!"; String firstNullObject = null; if (first == null) { if (second != null) { firstNullObject = second; } } assertEquals(second, firstNullObject); }
@Test public void get_first_non_null_guava () { String first = null; String second = "Go Badgers!"; String firstNullObject = Objects.firstNonNull(first, second); assertEquals(second, firstNullObject); }
@Test public void get_first_non_null_apache () { String first = null; String second = "On, Wisconsin!"; String firstNullObject = ObjectUtils.firstNonNull(first, second); assertEquals(second, firstNullObject); }