@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;
  }
@Test
  public void testSetDateFormatWithValidPattern() {
    GsonBuilder builder = new GsonBuilder();
    String validPattern = "yyyy-MM-dd";
    // Should not throw an exception
    builder.setDateFormat(validPattern);
  }