public T add(String str) {
    requireNonNull(str, JVM_OPTION_NOT_NULL_ERROR_MESSAGE);
    String value = str.trim();
    if (isInvalidOption(value)) {
      throw new IllegalArgumentException("a JVM option can't be empty and must start with '-'");
    }
    checkMandatoryOptionOverwrite(value);
    options.add(value);

    return castThis();
  }
@Test
  public void add_throws_MessageException_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() {
    String[] optionOverrides = {
      randomPrefix,
      randomPrefix + randomAlphanumeric(1),
      randomPrefix + randomAlphanumeric(2),
      randomPrefix + randomAlphanumeric(3),
      randomPrefix + randomAlphanumeric(4),
      randomPrefix + randomValue.substring(1),
      randomPrefix + randomValue.substring(2),
      randomPrefix + randomValue.substring(3)
    };

    JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue));

    for (String optionOverride : optionOverrides) {
      try {
        underTest.add(optionOverride);
        fail("an MessageException should have been thrown");
      } catch (MessageException e) {
        assertThat(e.getMessage()).isEqualTo("a JVM option can't overwrite mandatory JVM options. " + optionOverride + " overwrites " + randomPrefix + randomValue);
      }
    }
  }