Enum Class CukesContext

java.lang.Object
java.lang.Enum<CukesContext>
org.chenile.cucumber.CukesContext
All Implemented Interfaces:
Serializable, Comparable<CukesContext>, Constable

public enum CukesContext extends Enum<CukesContext>
A singleton object that is used in all the methods to store and retrieve values
Cucumber recommends an enum since it acts like a perfect singleton. We could have also used a static instance as an alternative.
  • Enum Constant Details

  • Field Details

  • Constructor Details

    • CukesContext

      private CukesContext()
      Pushes a hash map into the thread local so that we can now use the hash map to store and retrieve stuff
  • Method Details

    • values

      public static CukesContext[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CukesContext valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • context

      public Map<String,Object> context()
      This uses a Thread Local to set and retrieve values
      Returns:
      a map of all the current values stored within the thread.
    • set

      public void set(String key, Object value)
      A convenience method that retrieves the thread local and stores stuff into it.
      Parameters:
      key - the key to store against
      value - the value to store in the key
    • get

      public <T> T get(String key)
      A convenience method that retrieves the thread local and retrieves values against keys
      Type Parameters:
      T - this avoids the need to cast the results.
      Parameters:
      key - the key to use
      Returns:
      the value stored in the key
    • reset

      public void reset()
      Resets the map. Happens at the end of every scenario.