Loading ...
Sorry, an error occurred while loading the content.

1669Intercepting any method invocation on a mock

Expand Messages
  • nofxcwb
    Aug 12, 2013
    • 0 Attachment
      Hi,

      Is it possible to intercept any method invocation on a mock?

      With Mockito I can do this:

      protected InputStream createBrokenInputStream() {
      InputStream in = mock(InputStream.class, new Answer<Object>() {

      @Override
      public Object answer(InvocationOnMock invocation) throws IOException {
      throw new IOException("Broken stream!");
      }
      });
      return in;
      }

      This is very useful to test exception scenarios. I don't know exactly which method will be called on the InputStream and I don't actually care, I just want it to throw an exception when it is ever used.

      I couldn't find a way to do this with EasyMock. Any ideas?

      Thanks!

      Eduardo.
    • Show all 5 messages in this topic