### Question:
Filter { <T extends Model> void constructQuery(CriteriaBuilder builder, CriteriaQuery<?> query, Root<T> root) { if (!conditions.isEmpty()) { List<Predicate> predicates = new ArrayList<Predicate>(); for (Condition condition : conditions) { predicates.add(condition.constructQuery(builder, root)); } query.where(predicates.toArray(new Predicate[0])); } if (!sortFields.isEmpty()) { List<Order> orders = new ArrayList<Order>(); for (SortField sortField : sortFields) { orders.add(sortField.getOrder(builder, root)); } query.orderBy(orders); } } Filter(Class<?> clazz);  Filter(int perPage, int pageNo, Condition... conditions);  Filter();  Filter(Condition... conditions); Filter condition(String name, Object value); Filter condition(String name, Operator operator, Object value); Filter page(int pageNo, int perPage); Filter sortBy(String name, boolean asc); Filter sortBy(SortField sortField); Filter cacheable(boolean cacheable); Filter clone(boolean paginate); List<T> list(); long count(); void delete();  }### Answer:
@Test public void shouldConstructCriteriaQuery() { Filter filter = new Filter(mock(Condition.class), mock(Condition.class)); CriteriaBuilder builder = mock(CriteriaBuilder.class); Root root = mock(Root.class); Predicate p1 = mock(Predicate.class); Predicate p2 = mock(Predicate.class); when(filter.getConditions().get(0).constructQuery(builder, root)).thenReturn(p1); when(filter.getConditions().get(1).constructQuery(builder, root)).thenReturn(p2); CriteriaQuery query = mock(CriteriaQuery.class); filter.constructQuery(builder, query, root); verify(query).where(p1, p2); }
@Test public void shouldConstructCriteriaDeleteQuery() { Filter filter = new Filter(mock(Condition.class), mock(Condition.class)); CriteriaBuilder builder = mock(CriteriaBuilder.class); Root root = mock(Root.class); Predicate p1 = mock(Predicate.class); Predicate p2 = mock(Predicate.class); when(filter.getConditions().get(0).constructQuery(builder, root)).thenReturn(p1); when(filter.getConditions().get(1).constructQuery(builder, root)).thenReturn(p2); CriteriaDelete query = mock(CriteriaDelete.class); filter.constructQuery(builder, query, root); verify(query).where(p1, p2); }