title: Mockito Predicate JPA not run correctly
body: <p>In Unit Test Class:</p>
  <pre><code>    @Mock
      EntityManager entityManager;
  
      @Mock
      Root&lt;RedFox&gt; redFoxRoot;
  
      @Mock
      Expression expression;
  
      @Mock
      Path path;
  
      @Mock
      Predicate predicate;
  
      @Test 
      public void filterTest(){
        TypedQuery&lt;RedFox&gt; redFoxQuery = (TypedQuery&lt;RedFox&gt;) Mockito.mock(TypedQuery.class);
  
        CriteriaQuery&lt;RedFox&gt; redFoxCriteriaQuery = Mockito.mock(CriteriaQuery.class);
  
        Mockito.when(redFoxCriteriaQuery.where(Mockito.any(Predicate[].class)))
        .thenReturn(redFoxQuery); 
   
        Mockito.when(redFoxCriteriaQuery.orderBy(Mockito.anyList())).thenReturn(redFoxCriteriaQuery);
  
        CriteriaBuilder builder = Mockito.mock(CriteriaBuilder.class);
  
        Mockito.when(redFoxRoot.get(&quot;isDeleted&quot;)).thenReturn(path);
  
        Mockito.when(path.isNull()).thenReturn(predicate);
  
        Mockito.when(builder.literal(Mockito.any())).thenReturn(expression);
  
        Mockito.when(redFoxCriteriaQuery.from(RedFox.class)).thenReturn(redFoxRoot);      
   
        Mockito.when(entityManager.createQuery(redFoxCriteriaQuery)).thenReturn(redFoxQuery);
  
        List&lt;RedFox&gt; redFoxs = new ArrayList&lt;&gt;();
        RedFox redFox = new RedFox();
        redFox.setTitle(&quot;abc&quot;);
        redFox.setRedFoxStatus(&quot;&quot;);
        redFox.setId(UUID.randomUUID());
        redFoxs.add(redFox);
     
        Mockito.when(redFoxQuery.getResultList()).thenReturn(redFoxs);
        
    }
  </code></pre>
  <p>In class service:</p>
  <pre><code>     public List&lt;RedFox&gt; filter(){
              CriteriaBuilder builder = em.getCriteriaBuilder();
              CriteriaQuery&lt;RedFox&gt; redFoxCriteriaQuery = builder.createQuery(RedFox.class);
              Root&lt;RedFox&gt; root = redFoxCriteriaQuery.from(RedFox.class);
              redFoxCriteriaQuery.select(root);
              List&lt;Predicate&gt; searchClause = new ArrayList&lt;&gt;();
  
              searchClause.add(builder.isFalse(root.get(&quot;isDeleted&quot;)));//root cause error
  
              Predicate[] searchClauses = searchClause.toArray(Predicate[]::new);
              Query executingQuery = em.createQuery(redFoxCriteriaQuery.where(searchClauses)
                                     .orderBy(orderBys));//Null pointer exception
              List&lt;RedFox&gt; resultData = executingQuery
                      .getResultList();
              ..............................
  }
  </code></pre>
  <p>My problem is when I comment the searchClause.add(builder.isFalse(root.get(&quot;isDeleted&quot;))), it mean that the searchClauses is empty Array, then the code execute successfully.</p>
  <p>But when the search clauses is not empty, then redFoxCriteriaQuery.where(searchClauses) not use the result I mocked but return null, and it will cause the null pointer exception.</p>
  <p>I've been tucked 2 days but still don't know why so please help me with this issue.</p>