@Test public void addFromMandatoryProperty_supports_spaces_inside_options() { properties.put(randomPropertyName, "-foo bar -duck"); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); assertThat(underTest.getAll()).containsOnly("-foo bar", "-duck"); }
@Test public void addFromMandatoryProperty_accepts_property_equal_to_mandatory_option_and_does_not_add_it_twice() { JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); properties.put(randomPropertyName, randomPrefix + randomValue); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); assertThat(underTest.getAll()).containsOnly(randomPrefix + randomValue); }
@Test public void addFromMandatoryProperty_checks_against_mandatory_options_is_case_sensitive() { String[] optionOverrides = { randomPrefix, randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(2), randomPrefix + randomValue.substring(3), randomPrefix + randomValue.substring(3) + randomAlphanumeric(1), randomPrefix + randomValue.substring(3) + randomAlphanumeric(2), randomPrefix + randomValue.substring(3) + randomAlphanumeric(3), randomPrefix + randomValue + randomAlphanumeric(1) }; JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); for (String optionOverride : optionOverrides) { properties.setProperty(randomPropertyName, optionOverride.toUpperCase(Locale.ENGLISH)); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); } }
@Test public void addFromMandatoryProperty_fails_with_IAE_if_property_does_not_exist() { expectMissingPropertyIAE(this.randomPropertyName); underTest.addFromMandatoryProperty(new Props(properties), this.randomPropertyName); }
@Test @UseDataProvider("variousEmptyStrings") public void addFromMandatoryProperty_adds_options_of_property_with_trimming(String emptyString) { properties.put(randomPropertyName, emptyString + "-foo" + emptyString + " -bar" + emptyString + " -duck" + emptyString); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); assertThat(underTest.getAll()).containsOnly("-foo", "-bar", "-duck"); }
@Test public void addFromMandatoryProperty_fails_with_IAE_if_property_contains_an_empty_value() { expectMissingPropertyIAE(this.randomPropertyName); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); }
@Test @UseDataProvider("variousEmptyStrings") public void addFromMandatoryProperty_adds_single_option_of_property_with_trimming(String emptyString) { properties.put(randomPropertyName, emptyString + "-foo" + emptyString); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); assertThat(underTest.getAll()).containsOnly("-foo"); }
@Test @UseDataProvider("variousEmptyStrings") public void addFromMandatoryProperty_fails_with_MessageException_if_property_does_not_start_with_dash_after_trimmed(String emptyString) { properties.put(randomPropertyName, emptyString + "foo -bar"); expectJvmOptionNotEmptyAndStartByDashMessageException(randomPropertyName, "foo"); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); }
@Test public void addFromMandatoryProperty_reports_all_overriding_options_in_single_exception() { String overriding1 = randomPrefix; String overriding2 = randomPrefix + randomValue + randomAlphanumeric(1); properties.setProperty(randomPropertyName, "-foo " + overriding1 + " -bar " + overriding2); JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); expectedException.expect(MessageException.class); expectedException.expectMessage("a JVM option can't overwrite mandatory JVM options. " + "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + overriding1 + " overwrites " + randomPrefix + randomValue + ", " + overriding2 + " overwrites " + randomPrefix + randomValue); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); }
@Test public void addFromMandatoryProperty_throws_IAE_if_option_starts_with_prefix_of_mandatory_option_but_has_different_value() { String[] optionOverrides = { randomPrefix, randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(1), randomPrefix + randomValue.substring(2), randomPrefix + randomValue.substring(3), randomPrefix + randomValue.substring(3) + randomAlphanumeric(1), randomPrefix + randomValue.substring(3) + randomAlphanumeric(2), randomPrefix + randomValue.substring(3) + randomAlphanumeric(3), randomPrefix + randomValue + randomAlphanumeric(1) }; JvmOptions underTest = new JvmOptions(ImmutableMap.of(randomPrefix, randomValue)); for (String optionOverride : optionOverrides) { try { properties.put(randomPropertyName, optionOverride); underTest.addFromMandatoryProperty(new Props(properties), randomPropertyName); fail("an MessageException should have been thrown"); } catch (MessageException e) { assertThat(e.getMessage()) .isEqualTo("a JVM option can't overwrite mandatory JVM options. " + "The following JVM options defined by property '" + randomPropertyName + "' are invalid: " + optionOverride + " overwrites " + randomPrefix + randomValue); } } }