title: Unable to Mock EntityManager Criteria API
body: <p>I want to write the junit for EntityManager but unable to mock the EntityManager. My service class method listed below:</p>
  <pre><code>@PersistenceContext
  private EntityManager em;
  
  public List&lt;Items&gt; getItems() {
      Order order = Order.desc(&quot;ASC&quot;);
      Criteria crit = em.unwrap(Session.class).createCriteria(Items.class);
      Criteria critRowCount = em.unwrap(Session.class).createCriteria(Items.class);
      crit.add(Restrictions.eq(&quot;createdBy&quot;, &quot;John&quot;));
      critRowCount.add(Restrictions.eq(&quot;createdBy&quot;, &quot;John&quot;));
  
      crit.setFirstResult((pageNo - 1) * pageSize);
      crit.setMaxResults(pageSize);
      crit.addOrder(order);
      List&lt;Items&gt; items = crit.list();
      critRowCount.add(Restrictions.sqlRestriction(&quot;Query&quot;));
  
      critRowCount.setProjection(Projections.rowCount()).uniqueResult();
      return items;
  }
  </code></pre>
  <p>I used in my tast case:</p>
  <pre><code>@MockBean
  private EntityManager em;
  </code></pre>
  <p>and when I called below method in service</p>
  <pre><code>List&lt;Items&gt; items = crit.list();
  </code></pre>
  <p>This will hit DB. Please halp me to resolve the problem.</p>
  <p>Thanks in Advance!</p>