I have a situation where first argument of method findUser is something I cant mock Session.get(), So it will throw exception but still I want mock findUser. Any clue guys how to do this. I am using Mockito here.


Emp emp = findUser(Session.get(), "Admin");

Note Where Session isn't a static class. It is a static variable of the same class.

1 Answers

JavaJd On

There is a library called PowerMockito --> https://www.baeldung.com/intro-to-powermock . You should be able to mock your Session varg as a mock or spy and handle the return get(). This should then allow you to mock your findUser method passing in the argument types to be expected. Cheers!