diff --git a/pitest/src/main/java/org/pitest/plugin/FeatureParser.java b/pitest/src/main/java/org/pitest/plugin/FeatureParser.java index 4c3f4e358..900a23cc4 100644 --- a/pitest/src/main/java/org/pitest/plugin/FeatureParser.java +++ b/pitest/src/main/java/org/pitest/plugin/FeatureParser.java @@ -54,7 +54,11 @@ private void extractValue(String part, Map> vals) { if (current == null) { current = new ArrayList<>(); } - current.add(pairs[i + 1].trim()); + if (i + 1 < pairs.length) { + current.add(pairs[i + 1].trim()); + } else { + throw new RuntimeException("Could not parse feature. Parameters should be configured with +feature(param[value], param2[value2])"); + } vals.put(key, current); } } diff --git a/pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java b/pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java index f89ffa428..dc29dc200 100644 --- a/pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java +++ b/pitest/src/test/java/org/pitest/plugin/FeatureParserTest.java @@ -1,6 +1,7 @@ package org.pitest.plugin; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatCode; import java.util.Collections; import java.util.List; @@ -11,17 +12,12 @@ import java.util.Optional; public class FeatureParserTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - FeatureParser testee = new FeatureParser(); @Test public void shouldRejectInputNotStartingWithPlusOrMinus() { - this.thrown.expect(RuntimeException.class); - final FeatureSetting actual = parse("FOO"); - assertThat(actual.addsFeature()).isFalse(); + assertThatCode( () -> parse("FOO")) + .hasMessageContaining("Could not parse FOO"); } @Test @@ -88,6 +84,12 @@ public void shouldParseListValues() { assertThat(actual.getList("things")).contains("1","2","3","4"); } + @Test + public void failsCleanlyWhenBracketsWrongWayRound() { + assertThatCode(() -> parse("+BAR[things(1])]")) + .hasMessageContaining("Could not parse feature. Parameters should be configured with +feature(param[value], param2[value2])"); + } + private FeatureSetting parse(String dsl) { final List actual = this.testee.parseFeatures(Collections.singletonList(dsl));