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

1671Re: [easymock] Re: Intercepting any method invocation on a mock

Expand Messages
  • Eduardo Simioni
    Aug 13, 2013
      Hi,

      This option didn't work as is with EasyMock 3.2.
      ClassProxyFactory is not generic and the createProxy method receives more parameters.
      I'll try to figure it out when I have some time.

      Thanks,

      Eduardo.


      On Mon, Aug 12, 2013 at 7:14 PM, joshuaball65495 <joshuaball65495@...> wrote:
       



      Here's one way:

      InputStream inputStream = new ClassProxyFactory<InputStream>().createProxy(InputStream.class, new InvocationHandler() {
      @Override
      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {


      throw new IOException("Broken stream!");
      }
      });

      --- In easymock@yahoogroups.com, "nofxcwb" <simioni.eduardo@...> wrote:
      >
      > 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