Class TextSnapshot

  • All Implemented Interfaces:
    StructuredDataProvider

    @API(status=STABLE)
    public final class TextSnapshot
    extends Object
    implements StructuredDataProvider
    Take snapshots using Object.toString(). By default, whitespace changes of any kind will be ignored during comparison. This behavior can be changed using withIgnoreWhitespaces(boolean).

    When rendering unified diffs as String, changes in line separators are not marked at every occurrence. Instead, detected changes in line separators will result in a single informative message at the beginning of the diff.

    Author:
    Simon Taddiken
    • Field Detail

      • text

        public static final StructuredData text
        Take Snapshots using Object.toString() and compare the results using a generic String diff algorithm. Comparison ignores whitespace changes of any kind and does not limit the size of the unified diff.

        You can create a more customized text comparison by using text() and the several customization options.

        See Also:
        text()
    • Method Detail

      • text

        @API(status=STABLE,
             since="1.4.0")
        public static TextSnapshot text()
        Creates a customizable TextSnapshot instance. You can also use the static constant text when you want to use only defaults.
        Returns:
        The customizable text snapshot StructuredDataProvider.
        Since:
        1.4.0
      • withIgnoreWhitespaces

        @API(status=STABLE,
             since="1.4.0")
        public TextSnapshot withIgnoreWhitespaces​(boolean ignoreWhitespaces)
        Allows to customize the whitespace comparison behavior.
        Parameters:
        ignoreWhitespaces - Whether to ignore whitespaces during comparison.
        Returns:
        This instance.
      • withContextLines

        @API(status=EXPERIMENTAL,
             since="1.5.0")
        public TextSnapshot withContextLines​(int contextLines)
        Configures the amount of contextual lines that are printed around a detected change. Per default, all lines of the full diff will be printed. If you have huge diffs with only little changes, it might be beneficial to reduce this value to a low value like 5 or 10.
        Parameters:
        contextLines - The amount of lines to print around a detected change in the unified diffs.
        Returns:
        This instance.
        Since:
        1.5.0