I need to mock Spring crudRepository findById("111").get() from my test class
my code look like below and it return null even if I follow below steps.
(1) I need to test my Service class and I created serviceTest class and used mokito and powermock
(2) there is method ,i need to get User giving a id where service class method just calling to repository findById("111").get () and return the User object
(3) moking the test method like this
//configuration codes working well
.
.
.
tesst123 () {
.
.
//here some code working well
.
.
.
when (mockRepository.findById("111").get()).thenReturn (new User());
}
in above i can mock the mockRepository and while debugging it showed the created object.
But if I evaluate mockRepository.findById("111") part while debugging, it return null
if I evaluate mockRepository.findById("111").get() part while debugging, it return nullPointer exception
**** finally I sow .get() method return Optional.class and it is final class
So is there any way to mock this kind of scenarios ?