@CanIgnoreReturnValue
  public GsonBuilder setDateFormat(String pattern) {
    if (pattern != null) {
      try {
        new SimpleDateFormat(pattern);
      } catch (IllegalArgumentException e) {
        // Throw exception if it is an invalid date format
        throw new IllegalArgumentException("The date pattern '" + pattern + "' is not valid", e);
      }
    }
    this.datePattern = pattern;
    return this;
  }
@SuppressWarnings("deprecation") // for GsonBuilder.setDateFormat(int)
  @Test
  public void testSetDateFormatValidStyle() {
    GsonBuilder builder = new GsonBuilder();
    int[] validStyles = {DateFormat.FULL, DateFormat.LONG, DateFormat.MEDIUM, DateFormat.SHORT};

    for (int style : validStyles) {
      // Should not throw an exception
      builder.setDateFormat(style);
      builder.setDateFormat(style, style);
    }
  }