@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 testSetDateFormatWithInvalidPattern() {
    GsonBuilder builder = new GsonBuilder();
    String invalidPattern = "This is an invalid Pattern";
    IllegalArgumentException e =
        assertThrows(IllegalArgumentException.class, () -> builder.setDateFormat(invalidPattern));
    assertThat(e)
        .hasMessageThat()
        .isEqualTo("The date pattern '" + invalidPattern + "' is not valid");
  }