Class UniqueId

java.lang.Object
org.junit.platform.engine.UniqueId
All Implemented Interfaces:
Serializable, Cloneable

@API(status=STABLE, since="1.0") public class UniqueId extends Object implements Cloneable, Serializable
UniqueId encapsulates the creation, parsing, and display of unique IDs for TestDescriptors.

Instances of this class have value semantics and are immutable.

Since:
1.0
See Also:
  • Method Details

    • parse

      public static UniqueId parse(String uniqueId) throws JUnitException
      Parse a UniqueId from the supplied string representation using the default format.
      Parameters:
      uniqueId - the string representation to parse; never null or blank
      Returns:
      a properly constructed UniqueId
      Throws:
      JUnitException - if the string cannot be parsed
    • forEngine

      public static UniqueId forEngine(String engineId)
      Create an engine's unique ID from its engineId using the default format.

      The engine ID will be stored in a UniqueId.Segment with type "engine".

      Parameters:
      engineId - the engine ID; never null or blank
      See Also:
    • root

      public static UniqueId root(String segmentType, String value)
      Create a root unique ID from the supplied segmentType and value using the default format.
      Parameters:
      segmentType - the segment type; never null or blank
      value - the value; never null or blank
      See Also:
    • getEngineId

      public final Optional<String> getEngineId()
      Get the engine ID stored in this UniqueId, if available.
      See Also:
    • getSegments

      public final List<UniqueId.Segment> getSegments()
      Get the immutable list of segments that make up this UniqueId.
    • append

      public final UniqueId append(String segmentType, String value)
      Construct a new UniqueId by appending a new UniqueId.Segment, based on the supplied segmentType and value, to the end of this UniqueId.

      This UniqueId will not be modified.

      Neither the segmentType nor the value may contain any of the special characters used for constructing the string representation of this UniqueId.

      Parameters:
      segmentType - the type of the segment; never null or blank
      value - the value of the segment; never null or blank
    • append

      @API(status=STABLE, since="1.1") public final UniqueId append(UniqueId.Segment segment)
      Construct a new UniqueId by appending a new UniqueId.Segment to the end of this UniqueId.

      This UniqueId will not be modified.

      Parameters:
      segment - the segment to be appended; never null
      Since:
      1.1
    • appendEngine

      @API(status=EXPERIMENTAL, since="1.8") public UniqueId appendEngine(String engineId)
      Construct a new UniqueId by appending a new UniqueId.Segment, based on the supplied engineId, to the end of this UniqueId.

      This UniqueId will not be modified.

      The engine ID will be stored in a UniqueId.Segment with type "engine".

      Parameters:
      engineId - the engine ID; never null or blank
      Since:
      1.8
    • hasPrefix

      @API(status=STABLE, since="1.1") public boolean hasPrefix(UniqueId potentialPrefix)
      Determine if the supplied UniqueId is a prefix for this UniqueId.
      Parameters:
      potentialPrefix - the UniqueId to be checked; never null
      Since:
      1.1
    • removeLastSegment

      @API(status=STABLE, since="1.5") public UniqueId removeLastSegment()
      Construct a new UniqueId and removing the last UniqueId.Segment of this UniqueId.

      This UniqueId will not be modified.

      Returns:
      a new UniqueId; never null
      Throws:
      PreconditionViolationException - if this UniqueId contains a single segment
      Since:
      1.5
    • getLastSegment

      @API(status=STABLE, since="1.5") public UniqueId.Segment getLastSegment()
      Get the last UniqueId.Segment of this UniqueId.
      Returns:
      the last Segment; never null
      Since:
      1.5
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Generate the unique, formatted string representation of this UniqueId using the configured UniqueIdFormat.
      Overrides:
      toString in class Object