In the following example:
Execution execution = mock(Execution.class); when(execution.getLastQty()).thenReturn(1000.0); when(execution.getLastPrice()).thenReturn(75.0); order.onFillReceived(execution); assertEquals(0, order.getLeavesQty(), 0); Execution has many other methods that should not be called. Only the two methods that have been mocked should be used within this test and should be called. If any other methods are called, then the test should fail.
How to I tell Mockito to fail if any other methods are called?
Orderclass happens to call other methods of theExecutionclass, and it doesn't affect the outcome of the behaviour that you're testing, then why would you want the test to fail?