Skip to content
Advertisement

Mockito mock objects returns null

I try to implement some tests for my JSF application and for the mocks I am using mockito. (I also use spring)

JavaScript

The test succeeds, but when I want to retrieve the instance with the getInstance method. All Parameters which I have set before (via the constructor before) are null. I am new to mocked objects, so is this behavior normal, or is there a mistake in my code?

Advertisement

Answer

It really depends on GeneralConfigService#getInstance() implementation. Also you can simplify your test code a lot if you use @InjectMocks annotation.

When using MockitoJUnitRunner you don’t need to initialize mocks and inject your dependencies manually:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement