public void testInvokesFirstMatchingExpectationInGroup() throws Throwable { MockExpectation expectation1 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT); MockExpectation expectation2 = new MockExpectation(true, NOT_RELEVANT, NOT_RELEVANT); MockExpectation expectation3 = new MockExpectation(true, NOT_RELEVANT, NOT_RELEVANT); InvocationDispatcher dispatcher = new InvocationDispatcher(); dispatcher.add(expectation1); dispatcher.add(expectation2); dispatcher.add(expectation3); expectation1.shouldNotBeInvoked(); expectation2.shouldBeInvokedWith(invocation); expectation3.shouldNotBeInvoked(); dispatcher.dispatch(invocation); assertTrue("expectation2 should have been invoked", expectation2.wasInvoked); }
public void testThrowsExpectationErrorIfNoExpectationsMatchAnInvocation() throws Throwable { MockExpectation expectation1 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT); MockExpectation expectation2 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT); MockExpectation expectation3 = new MockExpectation(false, NOT_RELEVANT, NOT_RELEVANT); InvocationDispatcher dispatcher = new InvocationDispatcher(); dispatcher.add(expectation1); dispatcher.add(expectation2); dispatcher.add(expectation3); expectation1.shouldNotBeInvoked(); expectation2.shouldNotBeInvoked(); expectation3.shouldNotBeInvoked(); try { dispatcher.dispatch(invocation); fail("should have thrown ExpectationError"); } catch (ExpectationError e) { // expected } }