### Question:
Check { @Nonnull public static <T> T notNull(T object, String fieldName) { return that(object, NOT_NULL, NOT_NULL_FMT, fieldName); } private  Check(); @Nonnull static T notNull(T object, String fieldName); @Nonnull static String notNullOrEmpty(String string, String fieldName); @Nonnull static I notNullOrEmpty(I iterable, String fieldName); @Nonnull static C notNullOrEmpty(C collection, String fieldName); @Nonnull static M notNullOrEmpty(M map, String fieldName); static void that(boolean expression, String message); static void that(boolean expression, String messageFormat, Object arg1); static void that(boolean expression, String messageFormat, Object arg1, Object arg2); static void that(boolean expression, String messageFormat, Object arg1, Object arg2, Object arg3, Object... rest); static T that(T value, Predicate<? super T> predicate, String message); static T that(T value, Predicate<? super T> predicate, String messageFormat, Object arg1); static T that(T value, Predicate<? super T> predicate, String messageFormat, Object arg1, Object arg2); static T that(T value, Predicate<? super T> predicate, String messageFormat, Object arg1, Object arg2, Object arg3, Object... rest); static final String NOT_NULL_FMT; static final String NOT_EMPTY_FMT; static final Predicate<Boolean> IS_TRUE; static final Predicate<Object> NOT_NULL; static final Predicate<String> NOT_EMPTY_STRING; static final Predicate<Iterable<?>> NOT_EMPTY_ITERABLE; static final Predicate<Collection<?>> NOT_EMPTY_COLLECTION; static final Predicate<Map<?, ?>> NOT_EMPTY_MAP; }### Answer:
@Test public void notNull() { String result = Check.notNull("result", "result"); assertThat(result).isEqualTo("result"); }
@Test public void notNull_error() { try { Check.notNull(null, "result"); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("result should not be null"); } }
@Test public void notNullOrEmptyString_null_error() { try { Check.notNull(null, "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be null"); } }
@Test public void notNullOrEmptyString_empty_error() { try { Check.notNull("", "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be empty"); } }
@Test public void notNullOrEmptyIterable_null_error() { try { Iterable<String> input = null; Check.notNull(input, "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be null"); } }
@Test public void notNullOrEmptyIterator_empty_error() { try { Iterable<String> input = ImmutableList.of(); Check.notNull(input, "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be empty"); } }
@Test public void notNullOrEmptyCollection_null_error() { try { List<String> input = null; Check.notNull(input, "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be null"); } }
@Test public void notNullOrEmptyCollection_empty_error() { try { List<String> input = ImmutableList.of(); Check.notNull(input, "field"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("field should not be empty"); } }
@Test public void notNullOrEmptyMap_null_error() { try { Map<String, String> input = null; Check.notNull(input, "mapField"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("mapField should not be null"); } }
@Test public void notNullOrEmptyMap_empty_error() { try { Map<String, String> input = com.google.common.collect.ImmutableMap.of(); Check.notNull(input, "mapField"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("mapField should not be empty"); } }