public Object dispatch(Invocation invocation) throws Throwable { for (Expectation expectation : expectations) { if (expectation.matches(invocation)) { return expectation.invoke(invocation); } } throw ExpectationError.unexpected("unexpected invocation", invocation); }