All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hope.kola.contract.Background Maven / Gradle / Ivy

There is a newer version: 1.1.2-RELEASE
Show newest version
package hope.kola.contract;

import com.squareup.javapoet.CodeBlock;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
import hope.kola.contract.validation.Validatable;

public class Background implements Validatable {

  protected String description;

  private Variables variables;

  /** Before all script before each feature, equal to {@code org.junit.jupiter.api.BeforeAll} */
  private CodeBlock.Builder beforeAll;

  /**
   * Before each, script executed before all scenario, equal to {@code
   * org.junit.jupiter.api.BeforeEach}
   */
  private CodeBlock.Builder beforeEach;

  public String description() {
    return description;
  }

  public Background description(String description) {
    this.description = description;
    return this;
  }

  public Variables variables() {
    return variables;
  }

  public boolean hasVariables() {
    return variables != null && variables.hasEntries();
  }

  /**
   * (JAVA) add variables shared in this feature
   *
   * @param variables the {@link Variables}
   */
  public void setVariables(final Variables variables) {
    this.variables = variables;
  }

  /**
   * Add variables shared in this feature
   *
   * @param consumer function to set up the {@link Variables}
   */
  public void variables(@DelegatesTo(Variables.class) Closure consumer) {
    this.variables = new Variables();
    consumer.setDelegate(variables);
    consumer.call();
  }

  /**
   * (JAVA) set Before all script before each feature, equal to {@code
   * org.junit.jupiter.api.BeforeAll}
   */
  public void setBeforeAll(CodeBlock.Builder beforeAll) {
    this.beforeAll = beforeAll;
  }

  public CodeBlock.Builder getBeforeAll() {
    return beforeAll;
  }

  /**
   * Set Before all script before each feature, equal to {@code org.junit.jupiter.api.BeforeAll}
   *
   * @param consumer function to define this before all script
   */
  public void beforeAll(@DelegatesTo(CodeBlock.Builder.class) Closure consumer) {
    this.beforeAll = CodeBlock.builder();
    consumer.setDelegate(beforeAll);
    consumer.call();
  }

  /**
   * (JAVA) Set Before all script before each scenario, equal to {@code
   * org.junit.jupiter.api.BeforeEach}
   *
   * @param beforeEach before each script
   */
  public void setBeforeEach(CodeBlock.Builder beforeEach) {
    this.beforeEach = beforeEach;
  }

  public CodeBlock.Builder getBeforeEach() {
    return beforeEach;
  }

  /**
   * Set Before all script before each scenario, equal to {@code org.junit.jupiter.api.BeforeEach}
   *
   * @param consumer function to define this before each script
   */
  public void beforeEach(@DelegatesTo(CodeBlock.Builder.class) Closure consumer) {
    this.beforeEach = CodeBlock.builder();
    consumer.setDelegate(beforeEach);
    consumer.call();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy