Out of the following two test cases in BundleProcessorTest.java, i am getting below exception, although, my first test case passes successfully.
Simple, Should use @Spy annotation with @InjectMocks annotation.
You are using mockito anyString()
while calling the test method, it should be used only for verifying a mock object to ensure a certain method is called with any string parameter inside the test, but not to invoke the test itself. For your test use empty string ""
instead to anyString()
.
Ideally anyString() should not be used outside the mock or verify block.I was facing the same issue.Changing the anyString() to some string ("xyz") value works fine.
Note : Make a note that you might use anyString() to some other methods that leads in failure of some other method. It wasted my one hour to figure it out. My actual test method was getting passes individually but when i was trying to run that in a hole it was getting failed because of the reason that some other test case was using anyString() outside to mock or verify block.