How to mock DocumentNotFoundException?

I am trying to unit test my READ operations and I want to mock my READ call to throw a DocumentNotFoundException. However, all the methods inside the exception are protected or private making it impossible to mockk anything.

How can I unit test my function?

The constructor is public and can take a null argument. Do you need anything beyond than that?

Thanks! The constructor is public but I was finding it difficult to mock ErrorContext which is an arg to the constructor. I had to mock errorContext.exportAsString(any()) for it to work!

Thank you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.