tw.teddysoft.ezspec.keyword.Background Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ezspec-core Show documentation
Show all versions of ezspec-core Show documentation
ezspec is a framework for adopting Gherkin in Java testing.
The newest version!
package tw.teddysoft.ezspec.keyword;
import static java.lang.String.format;
/**
* {@code Background} is a class for representing Gherkin background.
*
* @author Teddy Chen
* @since 1.0
*/
public class Background extends RuntimeScenario {
public static final String KEYWORD = "Background";
public static final Background DEFAULT = new Background("", Rule.Empty());
/**
* Instantiates a new Background.
*
* @param name the name of this background
* @param rule the rule of this background
*/
public Background(String name, Rule rule){
super(name, rule);
}
/**
* Background text string including background name, step name
* and step description.
*
* @return the string
*/
@Override
public String toString() {
if (steps().isEmpty()) return "";
StringBuilder sb = new StringBuilder();
sb.append(format("Background: %s", getReplacedUnderscoresName()));
for(var each : steps()){
sb.append(format("\n%s %s", each.getName(), each.description()));
}
return sb.toString();
}
@Override
public Scenario withRule(String ruleName) {
this.rule.setBackground(Background.DEFAULT);
super.withRule(ruleName);
this.runtime = ScenarioEnvironment.create();
this.rule.setBackground(this);
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy