I am trying to create a Mockito class mock object with rather heavy network and transactional behavior, which I do not want to deal with in the current unit test that I am writing. However, it looks like Mockito calls the default constructor for the real class when creating the layout instance. The default constructor performs all sorts of actions that cause problems in the context of this unit test.
Is Mockito supposed to use the default constructor? And is there a way to avoid this behavior?
This is how I create an object layout:
ConcreteClassWithComplexDefaultConstructor mockObject = mock(ConcreteClassWithComplexDefaultConstructor.class);
EDIT: I realized what was going on. By default, the constructor of a particular class is NOT activated (as Luciano pointed out). However, it calls the static constructor of the class. As far as I know, static things and Mockito don't work very well, but is there any way to handle this, anyway, so that it ignores the static constructor. I have no particular hopes, however ...
source share