Skip to content
Advertisement

Mockito – NullpointerException when invoking method from Service

Hi I am trying to test the method but it returned null and I don’t know why; Method should work properly but still, I have NullPointerException

JavaScript

and the test method, maybe it`s because of final methods or something, I have no idea

JavaScript

there is stacktrace for my program. Some exceprion and error, sorry for screens in comment but i didnt see how to edit

JavaScript

Advertisement

Answer

Your problems stems from the wrong way you do your mocks. In your code you do the following:

JavaScript

Which effectively returns a mocked instance of AzureCloudStorageService. This is not what you want and need for this case, as this is what you need to test (i.e the unit under test). What you need to do though is to manually instantiate the AzureCloudStorageService by calling its constructor and passing in the mocked ModelMapper as well as PropertyResolver.

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