2

I have the following method in the class CertainBean:

public boolean isOn() {
        InterfaceBean Bean = getBean();
        return Bean.hasBeenSetOn(Param1, Param2);
    }

Now I would like to

assertEquals(CertainBeanInstance.isOn(),true);

In order to do that I need first to mock IntefaceBean. How can I do that?

Thanks in advance

1
  • The constructor of CertainBean does not take an InterfaceBean, so no way of injecting a mocked one.
    – Rollerball
    Dec 23, 2013 at 9:27

1 Answer 1

9

You need to use spy from Mockito 1.8 and mock only the method getBean

CertainBean bean = spy(new CertainBean());

when(bean.getBean()).thenReturn(yourInterfaceMockedBean);

there is more information about mocking real partial objects in this useful link: http://blog.javabien.net/2009/06/21/mockitos-partial-mocks-testing-real-objects-just-got-easier/

and here the changes on Mockito 1.8 https://code.google.com/p/mockito/wiki/ReleaseNotes#Changed_in_1.8.0_(23-07-2009)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.