public void testIllegalArguments() {
    try {
      if (randomBoolean()) {
        new RangeQueryBuilder(null);
      } else {
        new RangeQueryBuilder("");
      }
      fail("cannot be null or empty");
    } catch (IllegalArgumentException e) {
      // expected
    }

    RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder("test");
    try {
      if (randomBoolean()) {
        rangeQueryBuilder.timeZone(null);
      } else {
        rangeQueryBuilder.timeZone("badID");
      }
      fail("cannot be null or unknown id");
    } catch (IllegalArgumentException e) {
      // expected
    }

    try {
      if (randomBoolean()) {
        rangeQueryBuilder.format(null);
      } else {
        rangeQueryBuilder.format("badFormat");
      }
      fail("cannot be null or bad format");
    } catch (IllegalArgumentException e) {
      // expected
    }
  }
 @Override
 protected RangeQueryBuilder doCreateTestQueryBuilder() {
   RangeQueryBuilder query;
   // switch between numeric and date ranges
   switch (randomIntBetween(0, 2)) {
     case 0:
       // use mapped integer field for numeric range queries
       query = new RangeQueryBuilder(INT_FIELD_NAME);
       query.from(randomIntBetween(1, 100));
       query.to(randomIntBetween(101, 200));
       break;
     case 1:
       // use mapped date field, using date string representation
       query = new RangeQueryBuilder(DATE_FIELD_NAME);
       query.from(
           new DateTime(
                   System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC)
               .toString());
       query.to(
           new DateTime(
                   System.currentTimeMillis() + randomIntBetween(0, 1000000), DateTimeZone.UTC)
               .toString());
       // Create timestamp option only then we have a date mapper,
       // otherwise we could trigger exception.
       if (createShardContext().getMapperService().fullName(DATE_FIELD_NAME) != null) {
         if (randomBoolean()) {
           query.timeZone(randomTimeZone());
         }
         if (randomBoolean()) {
           query.format("yyyy-MM-dd'T'HH:mm:ss.SSSZZ");
         }
       }
       break;
     case 2:
     default:
       query = new RangeQueryBuilder(STRING_FIELD_NAME);
       query.from("a" + randomAsciiOfLengthBetween(1, 10));
       query.to("z" + randomAsciiOfLengthBetween(1, 10));
       break;
   }
   query.includeLower(randomBoolean()).includeUpper(randomBoolean());
   if (randomBoolean()) {
     query.from(null);
   }
   if (randomBoolean()) {
     query.to(null);
   }
   return query;
 }