Is it possible to create a mock object that implements several interfaces with EasyMock?
For example, interface Foo and interface Closeable
An alternative of the most voted answer still based on Mockito but with annotations. You can set the extraInterfaces directly from the Mock annotation as next:
@RunWith(MockitoJUnitRunner.class)
public class MyTest {
@Mock(extraInterfaces = Closeable.class)
private Foo foo;
...
}
NB: extraInterfaces is of type Class>[] so you can specify several interfaces if needed.
If you need to mock method calls of the extra interfaces you will need to cast your mock. For example let's say that I want to throw an IOException when I call close() on my mock foo, the corresponding code would then be:
Mockito.doThrow(IOException.class).when((Closeable) foo).close();