title: Criteria Query Mockito unit test - NullPointerException
body: <p>I have a method that i'm trying to test using mockito. Below is the method i'm trying to test. I'm getting a null pointer exception when I run my test. I'm mocking Root but at accountEntity.get I'm getting null pointer. What am I missing here?</p>
  
  <pre><code>     public List&lt;AccountEntity&gt; createCriteriaQuery(final List&lt;String&gt; accountIdList,
                      final MultiValueMap&lt;String, String&gt; allRequestParams) {
  
                  final CriteriaBuilder cb = entityManager.getCriteriaBuilder();           
                  final CriteriaQuery&lt;AccountEntity&gt; cq = cb.createQuery(AccountEntity.class);
                  final Root&lt;AccountEntity&gt; accountEntity = cq.from(AccountEntity.class);
  
                  final Join&lt;AccountEntity, PlanEntity&gt; account = accountEntity.join(AccountEntity_.planEntity);
  
                  final List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  
          //Getting null pointer at the below call.        
  
  **predicates.add(accountEntity.get(AccountEntity_.id).in(accountIdList));**
  
      /*remaining code here/
  </code></pre>
  
  <p>below is my test. </p>
  
  <pre><code>@InjectMocks
  private AccountsDAO                         accountsDao;
  @Mock
  EntityManagerFactory                        entityManagerFactory;
  @Mock
  EntityManager                               entityManager;
  @Mock
  CriteriaBuilder                             cb;
  @Mock
  CriteriaQuery&lt;AccountEntity&gt;                cq;
  @Mock
  Root&lt;AccountEntity&gt;                         rootAccountEntity;
      @Test
          public void canGetAllAccountsInfo() {
          when(entityManagerFactory.createEntityManager()).thenReturn(entityManager);
          when(entityManager.getCriteriaBuilder()).thenReturn(cb); when(cb.createQuery(AccountEntity.class)).thenReturn(cq);
          when(cq.from(AccountEntity.class)).thenReturn(rootAccountEntity);
  //Null pointer in the actual method call
              accountEntityList = accountsDao.createCriteriaQuery(accounIdList, allRequestParams);        
            }
  </code></pre>