Package org.approvej

Class ApprovalBuilder<T>

java.lang.Object
org.approvej.ApprovalBuilder<T>
Type Parameters:
T - the type of the value to approve

@NullMarked public class ApprovalBuilder<T> extends Object
A builder to configure an approval for a given value.

Optionally the value can be "scrubbed" of dynamic data (like timestamps or ID's).

The value will be printed (converted to String) using a Printer. By default, the ObjectPrinter will be applied, which can be changed with the printWith(Function).

  • Field Details

    • DEFAULT_PRINTER

      public static final Printer<Object> DEFAULT_PRINTER
      The default Printer used to print the value.
  • Method Details

    • approve

      public static <T> ApprovalBuilder<T> approve(T originalValue)
      Creates a new builder for the given value.
      Type Parameters:
      T - the type of the value to approve
      Parameters:
      originalValue - the value to approve
      Returns:
      a new ApprovalBuilder for the given value
    • printWith

      public ApprovalBuilder<String> printWith(Function<T,String> printer)
      Uses the given Function to convert the value to a String.
      Parameters:
      printer - the Function used to convert the value to a String
      Returns:
      this
    • printWith

      public ApprovalBuilder<String> printWith(Printer<T> printer)
      Uses the given Printer to convert the value to a String.
      Parameters:
      printer - the printer used to convert the value to a String
      Returns:
      this
    • scrubbedOf

      public ApprovalBuilder<T> scrubbedOf(UnaryOperator<T> scrubber)
      Applies the given scrubber to the current value.
      Parameters:
      scrubber - the UnaryOperator or Scrubber
      Returns:
      this
    • verify

      public void verify(Consumer<String> verifier)
      Uses the given Consumer or Verifier to approve the printed value.
      Parameters:
      verifier - the Consumer or Verifier
      Throws:
      ApprovalError - if the verification fails
    • verify

      public void verify(String previouslyApproved)
      Verifies that the given previouslyApproved value equals the value using an InplaceVerifier.
      Parameters:
      previouslyApproved - the approved value
    • verify

      public void verify()
      Uses the DEFAULT_VERIFIER to approve the printed value.
      Throws:
      ApprovalError - if the verification fails