FeatureFileParser { public FeatureFile loadFeatureFile(final File featureFile) { AssertHelper.assertTrue("Feature file: " + featureFile.getAbsolutePath() + " does not exist!", featureFile.exists()); FileContents currentFileContents = FileContents.fromFile(featureFile); return getFeatureFile(currentFileContents); }  FeatureFile loadFeatureFile(final File featureFile); FeatureFile getFeatureFile(FileContents fileContents); static String stripComments(final String line);  }
@Test public void testABigishFeature() { final FeatureFileParser parser = new FeatureFileParser(); final String featureFile = "./target/test-classes/features/abigishfeature.feature"; final FeatureFile feature = parser.loadFeatureFile(new File(featureFile)); Assert.assertNotNull(feature); }
@Test public void testLineNumbersAndParsing() { final FeatureFileParser parser = new FeatureFileParser(); final String featureFile = "./target/test-classes/features/lineNumbers.feature"; final FeatureFile feature = parser.loadFeatureFile(new File(featureFile)); Assert.assertNotNull(feature); final List<Scenario> scenarios = feature.getScenarios(); Assert.assertThat(scenarios.size(), is(4)); final Scenario sc1 = scenarios.get(0); Assert.assertThat(sc1.getSourceStartOffset(), is(not(-1))); Assert.assertThat(sc1.getSourceStartLineNumber(), is(13)); final List<Step> steps = sc1.getSteps(); Assert.assertThat(steps.size(), is(7)); final Step s1 = steps.get(0); Assert.assertThat(s1.getSourceLineNumber(), is(14)); final Step s2 = steps.get(1); Assert.assertThat(s2.getSourceLineNumber(), is(15)); final Step s3 = steps.get(2); Assert.assertThat(s3.getSourceLineNumber(), is(16)); final Step s4 = steps.get(3); Assert.assertThat(s4.getSourceLineNumber(), is(17)); final Step s5 = steps.get(4); Assert.assertThat(s5.getSourceLineNumber(), is(18)); final Step s6 = steps.get(5); Assert.assertThat(s6.getSourceLineNumber(), is(19)); final Step s7 = steps.get(6); Assert.assertThat(s7.getSourceLineNumber(), is(20)); final Scenario sc2 = scenarios.get(1); Assert.assertThat(sc2.getSourceStartLineNumber(), is(23)); Assert.assertThat(sc2.getSteps().get(0).getSourceLineNumber(), is(24)); final Scenario sc3 = scenarios.get(2); Assert.assertThat(sc3.getSourceStartLineNumber(), is(30)); final Scenario sc4 = scenarios.get(3); Assert.assertThat(sc4.getSteps().get(3).getSourceLineNumber(), is(56)); }
@Test public void testLineNumbersAndParsingWhenCommentIsPresentBetweenSteps() { final FeatureFileParser parser = new FeatureFileParser(); final String featureFile = "./target/test-classes/features/lineNumbers-with-comments.feature"; final FeatureFile feature = parser.loadFeatureFile(new File(featureFile)); Assert.assertNotNull(feature); final List<Scenario> scenarios = feature.getScenarios(); Assert.assertThat(scenarios.size(), is(1)); final Scenario sc1 = scenarios.get(0); Assert.assertThat(sc1.getSourceStartOffset(), is(not(-1))); Assert.assertThat(sc1.getSourceStartLineNumber(), is(8)); final List<Step> steps = sc1.getSteps(); Assert.assertThat(steps.size(), is(3)); final Step s1 = steps.get(0); Assert.assertThat(s1.getSourceLineNumber(), is(9)); final Step s2 = steps.get(1); Assert.assertThat(s2.getSourceLineNumber(), is(11)); final Step s3 = steps.get(2); Assert.assertThat(s3.getSourceLineNumber(), is(13)); }
@Test public void testFeatureFileParsing() { final FeatureFileParser parser = new FeatureFileParser(); final FeatureFile ff = parser.loadFeatureFile(new File("./target/test-classes/features/example2.feature")); Assert.assertNotNull(ff); Assert.assertNotNull(ff.getName()); Assert.assertNotNull(ff.getScenarios()); Assert.assertThat(ff.getScenarios().size(), is(4)); final Scenario sc1 = ff.getScenarios().get(1); Assert.assertTrue(sc1.hasBackground()); Assert.assertThat(sc1.getBackground().getSteps().size(), is(1)); Assert.assertThat(sc1.getSteps().size(), is(4)); final Step withEmailAddress = ff.getScenarios().get(0).getSteps().get(0); Assert.assertThat(withEmailAddress.getLine(), is("Given something with an@emailaddress.com")); final Scenario sc2 = ff.getScenarios().get(2); Assert.assertTrue(sc2.isOutline()); Assert.assertThat(sc2.getSteps().size(), is(6)); Assert.assertThat(sc2.getExampleParameters().size(), is(8)); final Scenario sc3 = ff.getScenarios().get(3); Assert.assertThat(sc3.getSteps().size(), is(5)); final Step step = sc3.getSteps().get(2); Assert.assertThat(step.getInlineTable().size(), is(1)); final Map<String, String> inlineTableRow0 = step.getInlineTable().get(0); Assert.assertThat(inlineTableRow0.size(), is(4)); Assert.assertFalse(ff.getScenarios().get(0).getTags().isEmpty()); final Set<String> tags = ff.getScenarios().get(0).getTags(); Assert.assertNotNull(tags); Assert.assertTrue(tags.contains("@tag1")); Assert.assertTrue(tags.contains("@tag2")); final Set<String> tags2 = ff.getScenarios().get(1).getTags(); Assert.assertNotNull(tags2); Assert.assertThat(tags2, hasSize(1)); Assert.assertTrue(tags2.contains("@tag3")); }