I am trying to Mock the function block
@Mock
private EntityManager entityManager;
@Mock
private CriteriaBuilder criteriaBuilder;
@Mock
CriteriaQuery<Entity> criteriaQuery;
@Mock
TypedQuery<Entity> typedQuery;
@Mock
Predicate predicate;
@Mock
Root<Entity> EntityRoot;
criteriaQuery.where(criteriaBuilder.and(
EntityRoot.get(ID).in(request.getIdList()),
criteriaBuilder.greaterThanOrEqualTo(EntityRoot.get(columnName),
Request.getTimeRangeFilter().getStartDate())));
ID - Static String
i tried mocking with the below code
when(criteriaQuery.where(criteriaBuilder.and(predicate, predicate))).thenReturn(criteriaQuery);
but for the line EntityRoot.get(ID).in(request.getIdList())
i get the below error
What am i doing wrong here
@Mock
Path<Object> path;
when(EntityRoot.get(anyString())).thenReturn(path);
when(path.in(Mockito.anyList())).thenReturn(predicate);
This solution worked finally.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.