Is it possible to create a mock object that implements multiple interfaces with EasyMock?

后端 未结 6 2042
清酒与你
清酒与你 2020-12-30 18:35

Is it possible to create a mock object that implements several interfaces with EasyMock?

For example, interface Foo and interface Closeable

6条回答
  •  渐次进展
    2020-12-30 19:21

    EasyMock doesn't support this so you're stuck with fallback of the temporary interface.

    As an aside, I smell a little bit of a code wiff - should a method really be treating an object as 2 different things, the Foo and Closeable interface in this case?

    This implies to me that the method is performing multiple operations and while I suspect one of those operations is to 'close' the Closeable, wouldn't it make more sense for the calling code to decide whether or not the 'close' is required?

    Structuring the code this way keeps the 'open' and 'close' in the same try ... finally block and IMHO makes the code more readable not to mention the method more general and allows you to pass objects that only implement Foo.

提交回复
热议问题