private static <D extends Comparable<? super D>, E> Predicate buildRangePredicate(
     Range<E, D> range, Root<E> root, CriteriaBuilder builder) {
   if (range.isBetween()) {
     return builder.between(root.get(range.getField()), range.getFrom(), range.getTo());
   } else if (range.isFromSet()) {
     return builder.greaterThanOrEqualTo(root.get(range.getField()), range.getFrom());
   } else if (range.isToSet()) {
     return builder.lessThanOrEqualTo(root.get(range.getField()), range.getTo());
   }
   return null;
 }
 @Test
 public void testUntil() {
   Range<Character> range = new Range<>('a').until('z');
   assertThat(range.getTo(), is('z'));
   assertThat(range.isToIncluded(), is(false));
   Helpers.assertThrows(NullPointerException.class, () -> new Range<>("").until(null));
 }
  @Test
  public void testConstruct() {
    Range<Integer> range = new Range<>(1);
    assertThat(range.getFrom(), is(1));

    range = new Range<>(2, 10, i -> i + 2);
    assertThat(range.getFrom(), is(2));
    assertThat(range.getTo(), is(10));
    assertThat(range.isToIncluded(), is(true));
  }