### Question:
CollectionUtils { static <T> T getElementAtPosition(Iterable<T> iterable, int pos) { if (iterable instanceof List) { List<T> list = (List<T>) iterable; return list.get(pos); } else { Iterator<T> iterator = iterable.iterator(); T element = iterator.next(); for (int i = 0; i < pos; i++) { element = iterator.next(); } return element; } } private  CollectionUtils(); static T getSingleElement(Iterable<T> iterable); static T getLastElement(List<T> list); static T getSingleElement(Iterable<T> iterable, Supplier<? extends RuntimeException> exceptionSupplier); static T removeAll(T map, Collection<K> keysToRemove);  }### Answer:
@Test void testGetElementAtPosition_list() throws Exception { List<String> list = Arrays.asList("a", "b", "c"); assertThat(CollectionUtils.getElementAtPosition(list, 0)).isEqualTo("a"); assertThat(CollectionUtils.getElementAtPosition(list, 1)).isEqualTo("b"); assertThat(CollectionUtils.getElementAtPosition(list, 2)).isEqualTo("c"); assertThatExceptionOfType(ArrayIndexOutOfBoundsException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(list, 3)); assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(Collections.emptyList(), 0)); assertThatExceptionOfType(IndexOutOfBoundsException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(Collections.emptyList(), 3)); }
@Test void testGetElementAtPosition_set() throws Exception { Set<String> set = new LinkedHashSet<>(); set.add("a"); set.add("b"); set.add("c"); assertThat(CollectionUtils.getElementAtPosition(set, 0)).isEqualTo("a"); assertThat(CollectionUtils.getElementAtPosition(set, 1)).isEqualTo("b"); assertThat(CollectionUtils.getElementAtPosition(set, 2)).isEqualTo("c"); assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(set, 3)); assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(Collections.emptySet(), 0)); assertThatExceptionOfType(NoSuchElementException.class) .isThrownBy(() -> CollectionUtils.getElementAtPosition(Collections.emptySet(), 3)); }