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

com.github.aoreshin.junit5.allure.steps.StepWrapperSteps Maven / Gradle / Ivy

There is a newer version: 83
Show newest version
package com.github.aoreshin.junit5.allure.steps;

import io.qameta.allure.model.Status;

/** Steps to create nested Allure steps directly in test code */
@SuppressWarnings("unchecked")
public abstract class StepWrapperSteps> {
  private static final ThreadLocal stepWrapperThreadLocal =
      ThreadLocal.withInitial(StepWrapper::new);

  public final T startStep(String stepName) {
    stepWrapper().startStep(stepName);
    return (T) this;
  }

  public final T stopStep() {
    stepWrapper().stopStep(Status.PASSED);
    return (T) this;
  }

  public final T step(String stepName, Runnable runnable) {
    stepWrapper().startStep(stepName);

    try {
      runnable.run();
      stepWrapper().stopStep(Status.PASSED);
    } catch (Exception e) {
      stepWrapper().stopStep(Status.BROKEN);
      throw e;
    }

    return (T) this;
  }

  private StepWrapper stepWrapper() {
    return stepWrapperThreadLocal.get();
  }

  /** Only for testing */
  static void setStepWrapper(StepWrapper stepWrapper) {
    stepWrapperThreadLocal.set(stepWrapper);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy