### Question:
FindWithinGenerator implements BinaryFunction<Generator<? extends E>, Predicate<? super E>, E> { public E evaluate(Generator<? extends E> left, Predicate<? super E> right) { FindProcedure<E> findProcedure = new FindProcedure<E>(right); left.run(findProcedure); if (!findProcedure.wasFound) { if (useIfNone) { return ifNone; } throw new NoSuchElementException("No element matching " + right + " was found."); } return findProcedure.found; } FindWithinGenerator();  FindWithinGenerator(E ifNone); E evaluate(Generator<? extends E> left, Predicate<? super E> right); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString(); static FindWithinGenerator<Object> instance(); static final FindWithinGenerator<Object> INSTANCE; }### Answer:
@Test(expected = NoSuchElementException.class) public void testDetect() { assertEquals(Integer.valueOf(3), new FindWithinGenerator<Integer>().evaluate( IteratorToGeneratorAdapter.adapt(numbers.iterator()), equalsThree)); new FindWithinGenerator<Integer>().evaluate(IteratorToGeneratorAdapter.adapt(numbers.iterator()), equalsTwentyThree); }
@Test public void testDetectIfNone() { assertEquals( Integer.valueOf(3), new FindWithinGenerator<Integer>(Integer.valueOf(3)).evaluate( IteratorToGeneratorAdapter.adapt(numbers.iterator()), equalsThree)); assertEquals("Xyzzy", new FindWithinGenerator<String>("Xyzzy").evaluate( IteratorToGeneratorAdapter.adapt(strings.iterator()), equalsXyZ)); }