From 8a89ac604d0cf5289e6a6fe252973523753d9b1e Mon Sep 17 00:00:00 2001 From: Yatharth Zutshi Date: Sun, 7 Apr 2019 11:38:51 +0530 Subject: [PATCH 1/4] Adding respirce path to parser exception --- core/src/main/java/cucumber/runtime/model/FeatureParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/cucumber/runtime/model/FeatureParser.java b/core/src/main/java/cucumber/runtime/model/FeatureParser.java index d473e7e6ef..60ce7ae9e2 100644 --- a/core/src/main/java/cucumber/runtime/model/FeatureParser.java +++ b/core/src/main/java/cucumber/runtime/model/FeatureParser.java @@ -37,7 +37,7 @@ public static CucumberFeature parseResource(Resource resource) { List pickleEvents = compilePickles(gherkinDocument, resource); return new CucumberFeature(gherkinDocument, path, source, pickleEvents); } catch (ParserException e) { - throw new CucumberException(e); + throw new CucumberException("Failed to parse resourse : " + path.getPath(), e); } } From 5f930e7e6de336faffc778d870af538b7c03aeac Mon Sep 17 00:00:00 2001 From: Yatharth Zutshi Date: Sun, 7 Apr 2019 13:12:35 +0530 Subject: [PATCH 2/4] Updating Junit --- core/src/main/java/cucumber/runtime/model/FeatureParser.java | 2 +- junit/src/test/java/cucumber/runtime/junit/CucumberTest.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/cucumber/runtime/model/FeatureParser.java b/core/src/main/java/cucumber/runtime/model/FeatureParser.java index 60ce7ae9e2..eac31a1eb5 100644 --- a/core/src/main/java/cucumber/runtime/model/FeatureParser.java +++ b/core/src/main/java/cucumber/runtime/model/FeatureParser.java @@ -37,7 +37,7 @@ public static CucumberFeature parseResource(Resource resource) { List pickleEvents = compilePickles(gherkinDocument, resource); return new CucumberFeature(gherkinDocument, path, source, pickleEvents); } catch (ParserException e) { - throw new CucumberException("Failed to parse resourse : " + path.getPath(), e); + throw new CucumberException("Failed to parse resourse at: " + path.toString(), e); } } diff --git a/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java b/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java index bbcd2fb1f5..7ad12c9bfa 100644 --- a/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/runtime/junit/CucumberTest.java @@ -18,7 +18,6 @@ import org.mockito.Mockito; import java.io.File; -import java.io.IOException; import java.util.List; import static java.util.Collections.emptyList; @@ -27,7 +26,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.CoreMatchers.containsString; import static org.mockito.ArgumentMatchers.argThat; public class CucumberTest { @@ -68,7 +67,7 @@ public void testThatParsingErrorsIsNicelyReported() throws Exception { new Cucumber(LexerErrorFeature.class); fail("Expecting error"); } catch (CucumberException e) { - assertThat(e.getMessage(), startsWith("gherkin.ParserException$CompositeParserException: Parser errors:")); + assertThat(e.getCause().toString(), containsString("gherkin.ParserException$CompositeParserException: Parser errors:")); } } From 5a70a1069f2bb0d2ccef4ef040ba977fedf076d0 Mon Sep 17 00:00:00 2001 From: "M.P. Korstanje" Date: Sun, 7 Apr 2019 19:22:24 +0530 Subject: [PATCH 3/4] Update core/src/main/java/cucumber/runtime/model/FeatureParser.java Co-Authored-By: gazler22 <34692418+gazler22@users.noreply.github.com> --- core/src/main/java/cucumber/runtime/model/FeatureParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/cucumber/runtime/model/FeatureParser.java b/core/src/main/java/cucumber/runtime/model/FeatureParser.java index eac31a1eb5..0de23a4893 100644 --- a/core/src/main/java/cucumber/runtime/model/FeatureParser.java +++ b/core/src/main/java/cucumber/runtime/model/FeatureParser.java @@ -37,7 +37,7 @@ public static CucumberFeature parseResource(Resource resource) { List pickleEvents = compilePickles(gherkinDocument, resource); return new CucumberFeature(gherkinDocument, path, source, pickleEvents); } catch (ParserException e) { - throw new CucumberException("Failed to parse resourse at: " + path.toString(), e); + throw new CucumberException("Failed to parse resource at: " + path.toString(), e); } } From 15eda70dccfb5715485b85c0af6777b87289dfcb Mon Sep 17 00:00:00 2001 From: Yatharth Zutshi Date: Sun, 7 Apr 2019 20:12:36 +0530 Subject: [PATCH 4/4] Updating JUnit with ExpectedException --- .../cucumber/runtime/junit/CucumberTest.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) 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 {