如何模拟CriteriaQuery.where()后跟order by

时间:2018-02-24 08:24:24

标签: java jpa criteria predicate

我有班级

CriteriaQuery<Entity> cq=criteriaQuery.root<Entity>();
.....
.....
cq.where(predictes.toArray(new Predicate[0])).orderBy(criteriaBuilder.asc(root.get(ENTITY.COLUMNNAME))

我需要模仿这一行,无法通过这一行。 我试过了

mockito.doReturn(Path).when(root).get(....);
mockito.doReturn(Order).when(criteriabuilder).asc(Path);

这也无助于我实现

1 个答案:

答案 0 :(得分:0)

我建议在mock类中使用类似的东西来模拟存储库方法而不是CriteriaQuery构造:

    @Mock
    CustomRepository customRepository;
    Mockito.when(customRepository.findEntity(Matchers.any()))
            .thenReturn(entity);