Matcher findingLifecycle = patternToPullLifecycleIntoGroupOne().matcher(beforeScenario);
String lifecycle = findingLifecycle.find() ? findingLifecycle.group(1).trim() : NONE;
Matcher findingBeforeAndAfter = compile(".*" + keywords.before() + "(.*)\\s*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if ( findingBeforeAndAfter.matches() ){
String beforeLifecycle = findingBeforeAndAfter.group(1).trim();
Steps beforeSteps = parseBeforeLifecycle(beforeLifecycle);
String afterLifecycle = findingBeforeAndAfter.group(2).trim();
Steps[] afterSteps = parseAfterLifecycle(afterLifecycle);
return new Lifecycle(beforeSteps, afterSteps);
}
Matcher findingBefore = compile(".*" + keywords.before() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if ( findingBefore.matches() ){
String beforeLifecycle = findingBefore.group(1).trim();
Steps beforeSteps = parseBeforeLifecycle(beforeLifecycle);
return new Lifecycle(beforeSteps, new Steps(new ArrayList<String>()));
}
Matcher findingAfter = compile(".*" + keywords.after() + "(.*)\\s*", DOTALL).matcher(lifecycle);
if ( findingAfter.matches() ){
Steps beforeSteps = Steps.EMPTY;
String afterLifecycle = findingAfter.group(1).trim();
Steps[] afterSteps = parseAfterLifecycle(afterLifecycle);
return new Lifecycle(beforeSteps, afterSteps);
}
return Lifecycle.EMPTY;