### Question:
Checks { public static <S, T extends Iterable<S>> T returnOrThrowIfEmpty( T value, NullaryFunction<? extends RuntimeException> exceptionFactory) { return orThrowIf( value, !value.iterator().hasNext(), exceptionFactory); }  static T returnOrThrowIfNull(T value, NullaryFunction<? extends RuntimeException> exceptionFactory); static T returnOrThrowIfEmpty(
            T value, NullaryFunction<? extends RuntimeException> exceptionFactory); static T returnOrThrowIfContainsNull(T iterable);  }### Answer:
@Test public void shouldReturnTheIterableIfItIsNotEmpty() throws Exception { Iterable<String> input = iterableWith("one", "two"); Iterable<String> output = Checks.returnOrThrowIfEmpty(input, runtimeFactory("Oops")); assertThat(output, is(input)); }
@Test public void shouldThrowTheSuppliedExceptionIfEmpty() throws Exception { Iterable<String> input = iterable(); try { Checks.returnOrThrowIfEmpty(input, illegalArgumentFactory("Oops")); fail("Expected the supplied exception to be thrown."); } catch (Throwable exception) { assertThat(exception, instanceOf(IllegalArgumentException.class)); assertThat(exception.getMessage(), is("Oops")); } }
@Test(expected = NullPointerException.class) public void shouldThrowANullPointerExceptionIfIterableSuppliedToEmptyCheckIsNull() throws Exception { Iterable<String> input = null; Checks.returnOrThrowIfEmpty(input, runtimeFactory()); }