This issue seems you need to load the test class using MockitoAnnotations.initMocks. Because , there is certain steps you need to do / setup the data before executing the test method.
@InjectMocks
private TokenServiceFormatter tokenServiceFormatter ;
As above I have already injected the respective class, that I want to inject. But, while running its showing the tokenServiceFormatter (injected object ) is null. So, inside the setup() method you need to load the test class as below.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
@Testpublic void testMethod(){//Do your test here}
Happy Mockinggggggggggggg.
Hope this will help you and will save your all day :::)
thank you for sharing this is awesome information
ReplyDeleteYou are welcome!!!!!
ReplyDelete