Interface ResultChecker
- All Superinterfaces:
Consumer<ScriptResult>
A checker for
ScriptResults that imposes some set of requirements that must be satisfied.
By convention, instances should throw a ResultCheckerException (or some subtype) if a
requirement is not met, specifying a specific SnippetOutcome (by its index) if appropriate.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResultCheckerCreate an instance that verifies that allSnippetOutcomes are successful.default voidcheck(ScriptResult result) Apply this instance to the given result.static ResultCheckercheckSnippets(BiConsumer<? super ScriptResult, ? super Integer> snippetChecker) Create an instance that verifies that everySnippetOutcomes meets some requirement.static ResultCheckerCreate an instance that verifies that the lastSnippetOutcomewas a successful expression returning a value having the specified type.
-
Method Details
-
check
Apply this instance to the given result.This method is a synonym for
accept().- Throws:
IllegalArgumentException- if a requirement is violated
-
allSuccessful
Create an instance that verifies that allSnippetOutcomes are successful.This just checks every
SnippetOutcomeis an instance ofSnippetOutcome.Successful. -
checkSnippets
static ResultChecker checkSnippets(BiConsumer<? super ScriptResult, ? super Integer> snippetChecker) Create an instance that verifies that everySnippetOutcomes meets some requirement.The
snippetCheckerwill be invoked with the index of eachSnippetOutcome. It should throwResultCheckerExceptionusing its given parameters if the correspondingSnippetOutcomefails to meet the requirement.- Parameters:
snippetChecker- checks eachSnippetOutcome- Throws:
IllegalArgumentException- ifsnippetCheckeris null
-
returns
Create an instance that verifies that the lastSnippetOutcomewas a successful expression returning a value having the specified type.This is useful in scenarios where the purpose of the script is to produce some result. This checks that:
- The script was not empty, i.e., it contained at least one snippet
- Every snippet in the script was successful
- The final snippet was an expression having the specified type
- If
allowNullis false, the returned value is not null
ResultCheckerExceptionis thrown.- Parameters:
type- expected return typeallowNull- true to allow null values, otherwise false- Throws:
IllegalArgumentException- iftypeis null or primitive
-