How can I create a mock with Mockito that throws an exception on every method call except on some stubbed calls? Intuitively, I tried it by providing a default answer like this:
Iterator themock = mock(Iterator.class, new ThrowsExceptionClass(UnsupportedOperationException.class)); when(themock.hasNext()).thenReturn(false); assertFalse(themock.hasNext()); but the call themock.hasNext() in the second line already throws an UnsupportedOperationException.