Record Class PathProvider

java.lang.Object
java.lang.Record
org.approvej.approve.PathProvider
Record Components:
directory - the Path containing the approvedPath() and the receivedPath()
baseFilename - the first part of the filename used to identify the test class and case the files belong to
filenameAffix - an addition to the baseFilename to identify multiple files belonging to the same test case
approvedLabel - a label to identify the approved file – usually "approved", but can be left empty
filenameExtension - the filename extension for the approved and received file

@NullMarked public record PathProvider(Path directory, String baseFilename, String filenameAffix, String approvedLabel, String filenameExtension) extends Record
A record to provide the paths of the approved and received files.

Generally, the constructor should not be used, but one of the PathProviders initializers.

  • Field Details

    • RECEIVED

      public static final String RECEIVED
      The infix of the file containing the latest received value that didn't match the previously approved.
      See Also:
    • APPROVED

      public static final String APPROVED
      The infix of the file containing a previously approved value.
      See Also:
  • Constructor Details

    • PathProvider

      public PathProvider(Path directory, String baseFilename, String filenameAffix, String approvedLabel, String filenameExtension)
      Creates an instance of a PathProvider record class.
      Parameters:
      directory - the value for the directory record component
      baseFilename - the value for the baseFilename record component
      filenameAffix - the value for the filenameAffix record component
      approvedLabel - the value for the approvedLabel record component
      filenameExtension - the value for the filenameExtension record component
  • Method Details

    • directory

      public PathProvider directory(Path directory)
      Set the directory where the approved and received files are stored.
      Parameters:
      directory - the Path where the approved and received files are stored
      Returns:
      a copy of this with the given directory
    • filenameAffix

      public PathProvider filenameAffix(String filenameAffix)
      Extends the baseFilename with the given String.
      Parameters:
      filenameAffix - affix to add to the base filename
      Returns:
      a copy of this using the baseFilename affixed by the given String
    • filenameExtension

      public PathProvider filenameExtension(String filenameExtension)
      Creates a new PathProvider with the current values and the given filenameExtension, unless the currently set filenameExtension is not empty and given is the default "txt"<T>.
      Parameters:
      filenameExtension - the filename extension to use
      Returns:
      a copy of this with using the given filenameExtension
    • approvedPath

      public Path approvedPath()
      Resolves and returns the Path to the received file in the directory, using the baseFilename, followed by approvedLabel (if any), followed by the filenameExtension (if any).
      Returns:
      the absolute and normalized Path to the approved file
    • receivedPath

      public Path receivedPath()
      Resolves and returns the Path to the received file in the directory, using the baseFilename, followed by "received" (if any), followed by the filenameExtension (if any).
      Returns:
      the absolute and normalized Path to the received file
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • directory

      public Path directory()
      Returns the value of the directory record component.
      Returns:
      the value of the directory record component
    • baseFilename

      public String baseFilename()
      Returns the value of the baseFilename record component.
      Returns:
      the value of the baseFilename record component
    • filenameAffix

      public String filenameAffix()
      Returns the value of the filenameAffix record component.
      Returns:
      the value of the filenameAffix record component
    • approvedLabel

      public String approvedLabel()
      Returns the value of the approvedLabel record component.
      Returns:
      the value of the approvedLabel record component
    • filenameExtension

      public String filenameExtension()
      Returns the value of the filenameExtension record component.
      Returns:
      the value of the filenameExtension record component