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

后端 未结 6 2035
清酒与你
清酒与你 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:22

    Another way to solve this problem is to use a CGLib mixin:

    final Interface1 interface1 = mockery.mock(Interface1.class);
    final Interface2 interface2 = mockery.mock(Interface2.class);
    
    service.setDependence(Mixin.create(new Object[]{ interface1, interface2 }));
    
    mockery.checking(new Expectations(){{
        oneOf(interface1).doSomething();
        oneOf(interface2).doNothing();
    }});
    
    service.execute();
    

    Whether or not this is a good idea, it's something up to discussion...

提交回复
热议问题