- Revision
- 901
- Author
- mauro
- Date
- 2008-08-28 18:44:32 -0500 (Thu, 28 Aug 2008)
Log Message
Added constructors to parser classes.
Modified Paths
- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java
- trunk/jbehave-core/src/java/org/jbehave/scenario/parser/ScenarioFileLoader.java
Diff
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java (900 => 901)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java 2008-08-28 13:01:44 UTC (rev 900) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/PropertyBasedConfiguration.java 2008-08-28 23:44:32 UTC (rev 901) @@ -16,7 +16,7 @@ public class PropertyBasedConfiguration implements Configuration { public static final String FAIL_ON_PENDING = "org.jbehave.failonpending"; - public static String OUTPUT_ALL = "org.jbehave.outputall"; + public static final String OUTPUT_ALL = "org.jbehave.outputall"; private final Configuration defaults; public PropertyBasedConfiguration() {
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java (900 => 901)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2008-08-28 13:01:44 UTC (rev 900) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/parser/PatternScenarioParser.java 2008-08-28 23:44:32 UTC (rev 901) @@ -6,6 +6,7 @@ import java.util.regex.Pattern; import org.jbehave.Configuration; +import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.ScenarioDefinition; import org.jbehave.scenario.StoryDefinition; import org.jbehave.scenario.definition.Blurb; @@ -14,11 +15,15 @@ private final Configuration configuration; + public PatternScenarioParser() { + this(new PropertyBasedConfiguration()); + } + public PatternScenarioParser(Configuration configuration) { this.configuration = configuration; } - public StoryDefinition defineStoryFrom(String wholeStoryAsString) { + public StoryDefinition defineStoryFrom(String wholeStoryAsString) { Blurb blurb = parseBlurbFrom(wholeStoryAsString); List<ScenarioDefinition> scenarioDefinitions = parseScenariosFrom(wholeStoryAsString); return new StoryDefinition(blurb, scenarioDefinitions); @@ -29,11 +34,12 @@ List<String> scenarios = splitScenarios(wholeStoryAsString); for (String scenario : scenarios) { Matcher findingTitle = patternToPullScenarioTitlesIntoGroupOne().matcher(scenario); - scenarioDefinitions.add(new ScenarioDefinition(findingTitle.find() ? findingTitle.group(1).trim() : "", findSteps(scenario))); + scenarioDefinitions.add(new ScenarioDefinition(findingTitle.find() ? findingTitle.group(1).trim() : "", + findSteps(scenario))); } return scenarioDefinitions; } - + private List<String> findSteps(String scenarioAsString) { Matcher matcher = patternToPullOutSteps().matcher(scenarioAsString); List<String> steps = new ArrayList<String>(); @@ -47,7 +53,8 @@ } private Blurb parseBlurbFrom(String wholeStoryAsString) { - Pattern findStoryBlurb = Pattern.compile("(.*?)(" + configuration.keywords().scenario() + ":).*", Pattern.DOTALL); + Pattern findStoryBlurb = Pattern.compile("(.*?)(" + configuration.keywords().scenario() + ":).*", + Pattern.DOTALL); Matcher matcher = findStoryBlurb.matcher(wholeStoryAsString); if (matcher.find()) { return new Blurb(matcher.group(1).trim()); @@ -62,7 +69,7 @@ int startAt = 0; List<String> scenarios = new ArrayList<String>(); if (matcher.matches()) { - while(matcher.find(startAt)) { + while (matcher.find(startAt)) { scenarios.add(matcher.group(1)); startAt = matcher.start(4); } @@ -74,17 +81,17 @@ } private Pattern patternToPullScenariosIntoGroupFour() { - return Pattern.compile(".*?((Scenario:) (.|\\s)*?)\\s*(\\Z|Scenario:).*".replace("Scenario", configuration.keywords().scenario()), Pattern.DOTALL); + return Pattern.compile(".*?((Scenario:) (.|\\s)*?)\\s*(\\Z|Scenario:).*".replace("Scenario", configuration + .keywords().scenario()), Pattern.DOTALL); } private Pattern patternToPullScenarioTitlesIntoGroupOne() { - String concatenatedKeywords = concatenateWithOr(configuration.keywords().given(), configuration.keywords().when(), configuration.keywords().then(), configuration.keywords().others()); + String concatenatedKeywords = concatenateWithOr(configuration.keywords().given(), configuration.keywords() + .when(), configuration.keywords().then(), configuration.keywords().others()); return Pattern.compile(configuration.keywords().scenario() + ":(.*?)\\s*(" + concatenatedKeywords + ").*"); } - - private String concatenateWithOr(String given, String when, String then, - String[] others) { + private String concatenateWithOr(String given, String when, String then, String[] others) { StringBuilder builder = new StringBuilder(); builder.append(given).append("|"); builder.append(when).append("|"); @@ -95,9 +102,8 @@ private String concatenateWithOr(String... keywords) { return concatenateWithOr(new StringBuilder(), keywords); } - - private String concatenateWithOr(StringBuilder builder, - String[] keywords) { + + private String concatenateWithOr(StringBuilder builder, String[] keywords) { for (String other : keywords) { builder.append(other).append("|"); } @@ -106,7 +112,9 @@ } private Pattern patternToPullOutSteps() { - String givenWhenThen = concatenateWithOr(configuration.keywords().given(), configuration.keywords().when(), configuration.keywords().then(), configuration.keywords().others()); - return Pattern.compile("((" + givenWhenThen + ") (.|\\s)*?)\\s*(\\Z|" + givenWhenThen + "|" + configuration.keywords().scenario()+ ":)"); + String givenWhenThen = concatenateWithOr(configuration.keywords().given(), configuration.keywords().when(), + configuration.keywords().then(), configuration.keywords().others()); + return Pattern.compile("((" + givenWhenThen + ") (.|\\s)*?)\\s*(\\Z|" + givenWhenThen + "|" + + configuration.keywords().scenario() + ":)"); } }
Modified: trunk/jbehave-core/src/java/org/jbehave/scenario/parser/ScenarioFileLoader.java (900 => 901)
--- trunk/jbehave-core/src/java/org/jbehave/scenario/parser/ScenarioFileLoader.java 2008-08-28 13:01:44 UTC (rev 900) +++ trunk/jbehave-core/src/java/org/jbehave/scenario/parser/ScenarioFileLoader.java 2008-08-28 23:44:32 UTC (rev 901) @@ -4,7 +4,6 @@ import java.io.IOException; import java.io.InputStream; -import org.jbehave.scenario.PropertyBasedConfiguration; import org.jbehave.scenario.Scenario; import org.jbehave.scenario.StoryDefinition; import org.jbehave.scenario.errors.InvalidScenarioResourceException; @@ -16,7 +15,7 @@ private final ScenarioParser stepParser; public ScenarioFileLoader() { - this(new UnderscoredCamelCaseResolver(), Thread.currentThread().getContextClassLoader(), new PatternScenarioParser(new PropertyBasedConfiguration())); + this(new UnderscoredCamelCaseResolver(), Thread.currentThread().getContextClassLoader(), new PatternScenarioParser()); } public ScenarioFileLoader(ScenarioParser stepParser) { @@ -27,6 +26,10 @@ this(converter, Thread.currentThread().getContextClassLoader(), parser); } + public ScenarioFileLoader(ScenarioFileNameResolver converter, ClassLoader classLoader) { + this(converter, classLoader, new PatternScenarioParser()); + } + public ScenarioFileLoader(ScenarioFileNameResolver resolver, ClassLoader classLoader, ScenarioParser stepParser) { this.resolver = resolver; this.classLoader = classLoader;
To unsubscribe from this list please visit:
