Something doesn't look right there.
You are mocking the controller you want to test.
I'm going to guess that the result of that is Sping's call to the read method will result in a default response by the mocked controller.
I would have expected you to @InjectMocks into the controller, and @Mock the PositionRepository attribute?
thanks for the post , i'm a newbie in spring and unit testing, i thought @Mock will create a Reference instance to the original class,so i don't understand what's @InjeckMoks is used for?
so if you can explain a little bit what's the difference between them.
And it works:)
Now ,i updated my controller code, with a new line (to make it easy for me)
I know it's not a clear code , but i would like to have your opinion , if possible.
to execute LINE M in Mockito test method(Got a NPE in this line), do i have to Mock the others classes,Like what I do for the Repository interface
or is there any other method to include the execution of this line on code in Test ambiant
Also, i put a breakpoint in Read() method , and i started the appliaction in debug mode but it doesn't stop,is it
normal when using Mocking url?
@Mock tells mockito you want to create a mock version of that class. That is, a version you can then handle all interaction with.
You don't mock out the class you are testing, you mock out the dependencies of that class.
Now, for Util it is going to be harder as it is a class of static methods, and mocking works best with interfaces.
It can be done, but in this case it's not necessary as all the class does is get something from the HttpSession...which you can mock out. So just mock that call and return a suitable InfoSession object (possibly itself another mocked object).