title: Not able to mock persistenceContext in spring boot test
body: <p>I am using spring-boot test with Mockito framework to test my application. One of the repository classes EntityManager as reference.</p>
  
  <p>My class looks like below.</p>
  
  <pre><code>    @Repository
      @Transactional
      @Slf4j
      public class SomeRepositoryService {
  
          @PersistenceContext
          private EntityManager entityManager;
  
          public List&lt;Run&gt; findBySearchCriteria(String searchCriteria,Integer 
   offset,Integer limit,Integer userId) {
          //code 
         }
      }
  </code></pre>
  
  <p>And test class looks like :</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class RunRepositoryServiceTests {
  
      @MockBean
      EntityManager entityManager; 
  
  
      @Autowired
      private RunRepositoryService runRepositoryService;
  
      @Test
      public void testFindBySearchCriteria() {
  //code to test
      }
  }
  </code></pre>
  
  <p>When i run this, i am getting </p>
  
  <pre><code>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.jpa.repository.support.DefaultJpaContext]: Constructor threw exception; nested exception is java.lang.NullPointerException
  
      Caused by: java.lang.NullPointerException: null
          at org.springframework.data.jpa.repository.support.DefaultJpaContext.&lt;init&gt;(DefaultJpaContext.java:53) ~[spring-data-jpa-2.0.9.RELEASE.jar:2.0.9.RELEASE]
  </code></pre>
  
  <p>can anyone let me know how to test this or solve this issue?</p>