title: mock a CrudRepository findById ("111").get ()
body: <p>I need to mock Spring crudRepository findById("111").get() from my test class</p>
  
  <p>my code look like below and it return null even if I follow below steps.</p>
  
  <p>(1) I need to test my Service class and I created serviceTest class and used mokito and powermock</p>
  
  <p>(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</p>
  
  <p>(3) moking the test method like this</p>
  
  <pre><code>//configuration codes working well
  .
  .
  .
  tesst123 () {
  .
  .
  //here some code working well
  .
  .
  .
  when (mockRepository.findById("111").get()).thenReturn (new User());
  
  }
  </code></pre>
  
  <p>in above i can mock the mockRepository and while debugging it showed the created object.</p>
  
  <p>But if I evaluate mockRepository.findById("111") part while debugging, it return null</p>
  
  <p>if I evaluate mockRepository.findById("111").get() part  while debugging, it return nullPointer exception</p>
  
  <p>**** finally I sow .get() method return Optional.class and it is final class </p>
  
  <p>So is there any way to mock this kind of scenarios ? </p>