diff --git a/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java b/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java index 7ad12c9bfa..c75a5c8e68 100644 --- a/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java @@ -4,10 +4,13 @@ import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import cucumber.runtime.CucumberException; +import gherkin.ParserException.CompositeParserException; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.junit.experimental.ParallelComputer; +import org.junit.rules.ExpectedException; import org.junit.runner.Description; import org.junit.runner.Request; import org.junit.runner.RunWith; @@ -22,15 +25,17 @@ import static java.util.Collections.emptyList; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.isA; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.hamcrest.CoreMatchers.containsString; import static org.mockito.ArgumentMatchers.argThat; public class CucumberTest { + @Rule + public ExpectedException thrownException = ExpectedException.none(); private String dir; @Before @@ -61,15 +66,11 @@ public void finds_features_based_on_explicit_root_package() throws Initializatio assertEquals("Feature: Feature A", cucumber.getChildren().get(0).getName()); } - @Test - public void testThatParsingErrorsIsNicelyReported() throws Exception { - try { - new Cucumber(LexerErrorFeature.class); - fail("Expecting error"); - } catch (CucumberException e) { - assertThat(e.getCause().toString(), containsString("gherkin.ParserException$CompositeParserException: Parser errors:")); - } - } + @Test + public void testThatParsingErrorsIsNicelyReported() throws Exception { + thrownException.expectCause(isA(CompositeParserException.class)); + new Cucumber(LexerErrorFeature.class); + } @Test public void testThatFileIsNotCreatedOnParsingError() throws Exception {