Interface Node

All Known Subinterfaces:
Node.Container<T>, Node.Example, Node.Examples, Node.Feature, Node.Rule, Node.Scenario, Node.ScenarioOutline

@API(status=EXPERIMENTAL) public interface Node
A node in a source file.

A node has a location, a keyword and name. The keyword and name are both optional (e.g. Node.Example and blank scenario names).

Nodes are organized in a tree like structure where Node.Container nodes contain yet more nodes.

A node can be linked to a TestCase by getLocation(). The findPathTo(Predicate) method can be used to find a path from the root node to a node with the same location as a test case.


 Location location = testCase.getLocation();
 Predicate<Node> withLocation = candidate -> location.equals(candidate.getLocation());
 Optional<List<Node>> path = node.findPathTo(withLocation);
 
  • Method Details

    • getLocation

      Location getLocation()
    • getKeyword

      Optional<String> getKeyword()
    • getName

      Optional<String> getName()
    • getParent

      Optional<Node> getParent()
    • map

      default <T> T map(T parent, BiFunction<Node.Feature,T,T> mapFeature, BiFunction<Node.Rule,T,T> mapRule, BiFunction<Node.Scenario,T,T> mapScenario, BiFunction<Node.ScenarioOutline,T,T> mapScenarioOutline, BiFunction<Node.Examples,T,T> mapExamples, BiFunction<Node.Example,T,T> mapExample)
      Recursively maps a node into another tree-like structure.
      Type Parameters:
      T - the type of the target structure
      Parameters:
      parent - the parent node of the target structure
      mapFeature - a function that takes a feature and a parent node and returns a mapped feature
      mapRule - a function that takes a rule and a parent node and returns a mapped rule
      mapScenario - a function that takes a scenario and a parent node and returns a mapped scenario
      mapScenarioOutline - a function that takes a scenario outline and a parent node and returns a mapped scenario outline
      mapExamples - a function that takes an examples and a parent node and returns a mapped examples
      mapExample - a function that takes an example and a parent node and returns a mapped example
      Returns:
      the mapped version of this instance
    • findPathTo

      default Optional<List<Node>> findPathTo(Predicate<Node> predicate)
      Finds a path down tree starting at this node to the first node that matches the predicate using depth first search.
      Parameters:
      predicate - to match the target node.
      Returns:
      a path to the first node or an empty optional if none was found.