Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #153 from sbtqa/fix-default-collection-passing
Browse files Browse the repository at this point in the history
fix NPE in case of no data tag in feature
  • Loading branch information
clicman authored Oct 5, 2018
2 parents 9f244e3 + 97bb049 commit bf2e349
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<maven.source.plugin.version>2.2.1</maven.source.plugin.version>
<maven.javadoc.plugin.version>2.9.1</maven.javadoc.plugin.version>
<maven.gpg.plugin.version>1.5</maven.gpg.plugin.version>
<datajack.version>4.0.3</datajack.version>
<datajack.version>4.0.4</datajack.version>
</properties>
<distributionManagement>
<snapshotRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
import gherkin.ast.TableCell;
import gherkin.ast.TableRow;
import gherkin.ast.Tag;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.reflect.FieldUtils;
import ru.sbtqa.tag.datajack.exceptions.DataException;
import ru.sbtqa.tag.qautils.properties.Props;

import static ru.sbtqa.tag.datajack.providers.AbstractDataProvider.PATH_PARSE_REGEX;

public class DataParser {
Expand All @@ -30,9 +34,10 @@ public class DataParser {
public void replaceDataPlaceholders(List<CucumberFeature> cucumberFeatures) throws DataException, IllegalAccessException {

for (CucumberFeature cucumberFeature : cucumberFeatures) {
featureDataTagValue = "$" + Props.get("data.initial.collection");
GherkinDocument gherkinDocument = cucumberFeature.getGherkinFeature();
Feature feature = gherkinDocument.getFeature();

if (feature == null) {
continue;
}
Expand Down Expand Up @@ -98,6 +103,10 @@ private String replaceDataPlaceholders(String raw) throws DataException {

String builtPath = collection == null ? "$" + value : "$" + collection + value;
String parsedValue = DataFactory.getDataProvider().getByPath(builtPath).getValue();
if (parsedValue == null) {
throw new DataException(String.format("Could not parse value for %s. Maybe it is not full. Possible path continuations: %s",
builtPath, DataFactory.getDataProvider().getByPath(builtPath).getKeySet()));
}
replacedStep = replacedStep.replace(stepDataMatcher.start(), stepDataMatcher.end(), parsedValue);
stepDataMatcher = stepDataPattern.matcher(replacedStep);
}
Expand All @@ -109,7 +118,9 @@ private void parseDataTagValue(String tag) throws DataException {
}

private void setFeatureDataTag(String featureDataTag) {
this.featureDataTagValue = featureDataTag;
if (featureDataTag != null) {
this.featureDataTagValue = featureDataTag;
}
}

private void setCurrentScenarioTag(String currentScenarioDataTag) {
Expand Down

0 comments on commit bf2e349

Please sign in to comment.