@Test public void reportsUnexpectedInvocationOnEmptyExpectations() { ReportExpectations expectations = new ReportExpectations(orderedExpectations); String expectedReport = "" + "Expected: Nothing!\n" + "Actual: TestCollaborator.firstMethod()\n" + "What happened before:\n" + " Nothing!\n" + "Unmet Expectations:\n" + " Nothing!\n"; verifyException(expectations, UnexpectedInvocation.class).execute(mockClass, instance, method1, noArguments); assertEquals(expectedReport, caughtException().getMessage()); }
@Override public <MockType> Object execute( Class<MockType> classToMock, MockType instance, Method method, Object[] arguments ) { ExecuteEvent<MockType> executeEvent = new ExecuteEvent<>(classToMock, method, arguments); try { Object result = expectations.execute(classToMock, instance, method, arguments); updateLog(executeEvent); return result; } catch (UnexpectedInvocation e) { return throwUnexpectedInvocation(executeEvent, e); } }
ReportExpectations implements Expectations { @Override public <MockType> Object execute( Class<MockType> classToMock, MockType instance, Method method, Object[] arguments ) { ExecuteEvent<MockType> executeEvent = new ExecuteEvent<>(classToMock, method, arguments); try { Object result = expectations.execute(classToMock, instance, method, arguments); updateLog(executeEvent); return result; } catch (UnexpectedInvocation e) { return throwUnexpectedInvocation(executeEvent, e); } } }
ReportExpectations implements Expectations { @Override public <MockType> Object execute( Class<MockType> classToMock, MockType instance, Method method, Object[] arguments ) { ExecuteEvent<MockType> executeEvent = new ExecuteEvent<>(classToMock, method, arguments); try { Object result = expectations.execute(classToMock, instance, method, arguments); updateLog(executeEvent); return result; } catch (UnexpectedInvocation e) { return throwUnexpectedInvocation(executeEvent, e); } } ReportExpectations(Expectations expectations); }
ReportExpectations implements Expectations { @Override public <MockType> Object execute( Class<MockType> classToMock, MockType instance, Method method, Object[] arguments ) { ExecuteEvent<MockType> executeEvent = new ExecuteEvent<>(classToMock, method, arguments); try { Object result = expectations.execute(classToMock, instance, method, arguments); updateLog(executeEvent); return result; } catch (UnexpectedInvocation e) { return throwUnexpectedInvocation(executeEvent, e); } } ReportExpectations(Expectations expectations); @Override void recordStub(
            Class<MockType> classToMock, MockType instance, Method method, Arguments arguments, ReturnType result
    ); @Override Object execute(
            Class<MockType> classToMock, MockType instance, Method method, Object[] arguments
    ); @Override void verify(); }
ReportExpectations implements Expectations { @Override public <MockType> Object execute( Class<MockType> classToMock, MockType instance, Method method, Object[] arguments ) { ExecuteEvent<MockType> executeEvent = new ExecuteEvent<>(classToMock, method, arguments); try { Object result = expectations.execute(classToMock, instance, method, arguments); updateLog(executeEvent); return result; } catch (UnexpectedInvocation e) { return throwUnexpectedInvocation(executeEvent, e); } } ReportExpectations(Expectations expectations); @Override void recordStub(
            Class<MockType> classToMock, MockType instance, Method method, Arguments arguments, ReturnType result
    ); @Override Object execute(
            Class<MockType> classToMock, MockType instance, Method method, Object[] arguments
    ); @Override void verify();  }