Context.java

  1. package org.jbehave.core.context;

  2. import org.apache.commons.lang3.builder.ToStringBuilder;
  3. import org.apache.commons.lang3.builder.ToStringStyle;

  4. /**
  5.  * Holds context-related information
  6.  */
  7. public class Context {
  8.    
  9.     private ThreadLocal<String> currentStory = new ThreadLocal<>();
  10.     private ThreadLocal<String> currentScenario = new ThreadLocal<>();

  11.     public String getCurrentStory() {
  12.         return currentStory.get();
  13.     }

  14.     public void setCurrentStory(String currentStory) {
  15.         this.currentStory.set(currentStory);
  16.     }

  17.     public String getCurrentScenario() {
  18.         return currentScenario.get();
  19.     }

  20.     public void setCurrentScenario(String currentScenario) {
  21.         this.currentScenario.set(currentScenario);
  22.     }

  23.     @Override
  24.     public String toString() {
  25.         return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
  26.                 .append("story=" + getCurrentStory())
  27.                 .append("scenario=" + getCurrentScenario())
  28.                 .build();
  29.     }

  30. }