### Question:
Algorithm { static <E, Ite extends Iterable<E>> Ite removeIf(Ite input, Predicate<E> predicate) { for( Iterator<E> iterator = input.iterator(); iterator.hasNext();) if(predicate.test(iterator.next())) iterator.remove(); return input; }  static ArrayList<E> findAll(Ite input, Predicate<E> predicate);  }### Answer:
@Test public void testRemoveIfWithEmptyIterable() { Iterable<Boolean> iterable = new ArrayList<Boolean>(); removeIf(iterable, new Predicate<Boolean>() { @Override public boolean test(Boolean aBoolean) { fail("The predicate should not be called with empty iterable"); return false; } }); }
@Test public void testRemoveIfWithNonEmptyIterable() { List<Boolean> list = new ArrayList<Boolean>(Arrays.asList(Boolean.TRUE, Boolean.FALSE)); final AtomicBoolean predicateCheck = new AtomicBoolean(false); removeIf(list, new Predicate<Boolean>() { @Override public boolean test(Boolean aBoolean) { predicateCheck.set(true); return aBoolean.booleanValue(); } }); assertThat("RemoveIf should have removed one element", list.size(), is(1)); assertThat("The remaining element in list should be Boolean.FALSE", list.get(0), is(Boolean.FALSE)); assertThat("During evaluation, the predicate should have set check to true", predicateCheck.get(), is(true)); }