public static String generateResourceId(
      String baseString,
      Pattern illegalChars,
      String replaceChar,
      int targetLength,
      DateTimeFormatter timeFormat) {
    // first, make sure the baseString, typically the test ID, is not empty
    checkArgument(baseString.length() != 0, "baseString cannot be empty.");

    // next, replace all illegal characters from given string with given replacement character
    String illegalCharsRemoved =
        illegalChars.matcher(baseString.toLowerCase()).replaceAll(replaceChar);

    // finally, append the date/time and return the substring that does not exceed the length limit
    LocalDateTime localDateTime = LocalDateTime.now(ZoneId.of(TIME_ZONE));
    String timeAddOn = localDateTime.format(timeFormat);
    return illegalCharsRemoved.subSequence(
            0, min(targetLength - timeAddOn.length() - 1, illegalCharsRemoved.length()))
        + replaceChar
        + localDateTime.format(timeFormat);
  }
@Test
  public void testGenerateResourceIdShouldReplaceUpperCaseLettersWithLowerCase() {
    String testBaseString = "Test-Instance";

    String actual =
        generateResourceId(
            testBaseString,
            ILLEGAL_INSTANCE_CHARS,
            REPLACE_INSTANCE_CHAR,
            MAX_INSTANCE_ID_LENGTH,
            TIME_FORMAT);

    assertThat(actual).matches("test-instance-\\d{8}-\\d{6}-\\d{6}");
  }