### Question:
IterableUtils { public static <T> T getSingle(Iterator<T> iterator, String notFoundMessage) { T result = getSingleOrNull(iterator); if (result == null) { throw new NotFoundException(notFoundMessage); } return result; } private  IterableUtils(); static long countNodes(GraphDatabaseService database); static long count(Iterable iterable); static boolean contains(Iterable<T> iterable, T object); static List<T> toList(Iterable<T> iterable); static T random(Iterable<T> iterable); static Iterable<T> random(Iterable<T> iterable, int numberOfSamples); static T getSingle(Iterator<T> iterator, String notFoundMessage); static T getSingle(Iterable<T> iterable, String notFoundMessage); static T getSingle(Iterator<T> iterator); static T getSingle(Iterable<T> iterable); static T getSingleOrNull(Iterator<T> iterator); static T getSingleOrNull(Iterable<T> iterable); static T getFirst(Iterator<T> iterator, String notFoundMessage); static T getFirst(Iterable<T> iterable, String notFoundMessage); static T getFirstOrNull(Iterator<T> iterator); static T getFirstOrNull(Iterable<T> iterable);  }### Answer:
@Test public void singleElementShouldBeReturnedWhenIterableHasOneElement2() { assertEquals("test", getSingle(Collections.singletonList("test"))); }
@Test(expected = NotFoundException.class) public void exceptionShouldBeThrownWhenIterableHasNoElements() { getSingle(Collections.emptyList()); }
@Test public void exceptionShouldBeThrownWhenIterableHasNoElements2() { try { getSingle(Collections.emptyList(), "test"); } catch (NotFoundException e) { assertEquals("test", e.getMessage()); } }
@Test(expected = IllegalStateException.class) public void exceptionShouldBeThrownWhenIterableHasMoreThanOneElement2() { getSingle(Arrays.asList("test1", "test2")); }