Skip to content
Advertisement

How to mock a method call in a constructor?

I have class class1, which has 2 member variables:

JavaScript

I want to test the method fun, so I will have to write a test-class and a test method for that. But, how do I mock the method call config.getEnablingStatus(), while creating an object of type classA in the test class?

I am thinking of doing something like this [see the below piece of code].Is it correct? But what is the right way to do it?

TestClassForClassA:

JavaScript

Advertisement

Answer

Do not use @InjectMocks

Try something like this

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