Class TextSnapshot
- java.lang.Object
-
- de.skuzzle.test.snapshots.data.text.TextSnapshot
-
- All Implemented Interfaces:
StructuredDataProvider
@API(status=STABLE) public final class TextSnapshot extends java.lang.Object implements StructuredDataProvider
Take snapshots usingObject.toString(). By default, whitespace changes of any kind will be ignored during comparison. This behavior can be changed usingwithIgnoreWhitespaces(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, but only if set
withIgnoreWhitespaces(boolean)to false.By default, rendered diffs will display 5 lines of context around a detected change. This can be changed using
withContextLines(int). Note thatSnapshotTestOptions.textDiffContextLines()does not apply to text snapshots.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTextSnapshot.DiffFormatFormat in which diffs will be rendered within assertion failure messages.
-
Field Summary
Fields Modifier and Type Field Description static StructuredDatatextTake Snapshots usingObject.toString()and compare the results using a generic String diff algorithm.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StructuredDatabuild()Provides theStructuredDatainstance which defines the serialization format and the way in which serialized objects are compared.static TextSnapshottext()Creates a customizableTextSnapshotinstance.TextSnapshotwithContextLines(int contextLines)Configures the amount of contextual lines that are printed around a detected change.TextSnapshotwithDiffFormat(TextSnapshot.DiffFormat diffFormat)Specify the format of how diffs are rendered within our assertion failure messages.TextSnapshotwithIgnoreWhitespaces(boolean ignoreWhitespaces)Allows to customize the whitespace comparison behavior.
-
-
-
Field Detail
-
text
public static final StructuredData text
Take Snapshots usingObject.toString()and compare the results using a generic String diff algorithm. Comparison ignores whitespace changes of any kind.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 customizableTextSnapshotinstance. You can also use the static constanttextwhen 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.Defaults to false.
- 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.Defaults to 5
- Parameters:
contextLines- The amount of lines to print around a detected change in the unified diffs.- Returns:
- This instance.
- Since:
- 1.5.0
-
withDiffFormat
@API(status=EXPERIMENTAL, since="1.7.0") public TextSnapshot withDiffFormat(TextSnapshot.DiffFormat diffFormat)Specify the format of how diffs are rendered within our assertion failure messages.Defaults to
TextSnapshot.DiffFormat.UNIFIED- Parameters:
diffFormat- The diff format to use.- Returns:
- This instance.
- Since:
- 1.7.0
-
build
public StructuredData build()
Description copied from interface:StructuredDataProviderProvides theStructuredDatainstance which defines the serialization format and the way in which serialized objects are compared.- Specified by:
buildin interfaceStructuredDataProvider- Returns:
- The
StructuredDatainstance.
-
-