Class Expect

java.lang.Object
au.com.origin.snapshots.Expect

public class Expect extends Object
  • Constructor Details

    • Expect

      public Expect()
  • Method Details

    • of

      public static Expect of(SnapshotVerifier snapshotVerifier, Method method)
    • toMatchSnapshot

      public void toMatchSnapshot(Object object)
      Make an assertion on the given input parameters against what already exists

      If you were previously using varargs and see an error - you can fix the error using "toMatchSnapshotLegacy", however, a better approach is to use the ".scenario()" feature as future versions of this library will most likely remove the legacy implementation completely.

      Parameters:
      object - snapshot object
    • mask

      public Expect mask(String regex, String replacement)
      Mask all matches of a regular expression in the serialized snapshot body.

      Masks are applied in registration order, after serialization and before saving or comparing the snapshot. Snapshot names, scenarios and headers are not masked.

      The replacement follows Matcher.replaceAll(String) semantics, including capture-group references. Use Matcher.quoteReplacement(String) for literal replacements containing dollar signs or backslashes.

      Parameters:
      regex - regular expression to match
      replacement - replacement for each match
      Returns:
      this
      Throws:
      PatternSyntaxException - if the regular expression is invalid
      NullPointerException - if regex or replacement is null
    • scenario

      public Expect scenario(String scenario)
      Normally a snapshot can be applied only once to a test method.

      For Parameterized tests where the same method is executed multiple times you can supply the scenario() to overcome this restriction. Ensure each scenario is unique.

      Parameters:
      scenario - - unique scenario description
      Returns:
      Snapshot
    • serializer

      public Expect serializer(SnapshotSerializer serializer)
      Apply a custom serializer for this snapshot
      Parameters:
      serializer - your custom serializer
      Returns:
      Snapshot
    • serializer

      public Expect serializer(String name)
      Apply a custom serializer for this snapshot
      Parameters:
      name - - the {name} attribute serializer.{name} from snapshot.properties
      Returns:
      Snapshot
    • comparator

      public Expect comparator(SnapshotComparator comparator)
      Apply a custom comparator for this snapshot
      Parameters:
      comparator - your custom comparator
      Returns:
      Snapshot
    • comparator

      public Expect comparator(String name)
      Apply a custom comparator for this snapshot
      Parameters:
      name - the {name} attribute comparator.{name} from snapshot.properties
      Returns:
      Snapshot
    • reporters

      public Expect reporters(SnapshotReporter... reporters)
      Apply a list of custom reporters for this snapshot This will replace the default reporters defined in the config
      Parameters:
      reporters - your custom reporters
      Returns:
      Snapshot
    • reporters

      public Expect reporters(String name)
      Apply a list of custom reporters for this snapshot This will replace the default reporters defined in the config
      Parameters:
      name - the {name} attribute reporters.{name} from snapshot.properties
      Returns:
      Snapshot
    • serializer

      public Expect serializer(Class<? extends SnapshotSerializer> serializer)
      Apply a custom serializer for this snapshot.
      Parameters:
      serializer - your custom serializer
      Returns:
      this
      See Also:
    • header

      public Expect header(String key, String value)
      Add anything you like to the snapshot header.

      These custom headers can be used in serializers, comparators or reporters to change how they behave.

      Parameters:
      key - key
      value - value
      Returns:
      Expect