Package io.karatelabs.core
Record Class MatchRunEvent
java.lang.Object
java.lang.Record
io.karatelabs.core.MatchRunEvent
- All Implemented Interfaces:
RunEvent
public record MatchRunEvent(RunEventType type, Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime scenarioRuntime, long timeStamp)
extends Record
implements RunEvent
Assertion-level events (MATCH_EXIT).
Enables commercial extensions to capture what a test actually asserted — the expression strings as written, the evaluated values and the match outcome — for reports like assertion evidence or assertion-strength grading.
Fired by the match keyword, the karate.match("...") JS API (both route through
StepExecutor.evalMatchString) and the assert keyword. An assert carries no
Match.Type: its actualExpr() is the asserted expression, actual() the
evaluated boolean, and expected is absent.
Usage with pattern matching:
listener = event -> switch (event) {
case MatchRunEvent e when e.type() == MATCH_EXIT -> {
Step step = e.getCurrentStep();
boolean pass = e.result().pass;
// Process assertion data
yield true;
}
default -> true;
};
The return value of a listener is ignored — the assertion has already been evaluated.
-
Constructor Summary
ConstructorsConstructorDescriptionMatchRunEvent(RunEventType type, Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime scenarioRuntime, long timeStamp) Creates an instance of aMatchRunEventrecord class. -
Method Summary
Modifier and TypeMethodDescriptionactual()Returns the value of theactualrecord component.Returns the value of theactualExprrecord component.final booleanIndicates whether some other object is "equal to" this one.static MatchRunEventexit(Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime sr) Creates a MATCH_EXIT event fired after the match is evaluated.expected()Returns the value of theexpectedrecord component.Returns the value of theexpectedExprrecord component.Convenience method to get the currently executing step.longReturns the timestamp when this event occurred (epoch milliseconds).getType()Returns the event type.final inthashCode()Returns a hash code value for this object.Returns the value of thematchTyperecord component.result()Returns the value of theresultrecord component.Returns the value of thescenarioRuntimerecord component.longReturns the value of thetimeStamprecord component.toJson()Serializes this event to a map for JSONL output.final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.
-
Constructor Details
-
MatchRunEvent
public MatchRunEvent(RunEventType type, Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime scenarioRuntime, long timeStamp) Creates an instance of aMatchRunEventrecord class.- Parameters:
type- the value for thetyperecord componentmatchType- the value for thematchTyperecord componentactualExpr- the value for theactualExprrecord componentexpectedExpr- the value for theexpectedExprrecord componentactual- the value for theactualrecord componentexpected- the value for theexpectedrecord componentresult- the value for theresultrecord componentscenarioRuntime- the value for thescenarioRuntimerecord componenttimeStamp- the value for thetimeStamprecord component
-
-
Method Details
-
exit
public static MatchRunEvent exit(Match.Type matchType, String actualExpr, String expectedExpr, Object actual, Object expected, Result result, ScenarioRuntime sr) Creates a MATCH_EXIT event fired after the match is evaluated. Fires for a failed match too, before the keyword path throws. -
getType
Description copied from interface:RunEventReturns the event type. -
getTimeStamp
public long getTimeStamp()Description copied from interface:RunEventReturns the timestamp when this event occurred (epoch milliseconds).- Specified by:
getTimeStampin interfaceRunEvent
-
toJson
Description copied from interface:RunEventSerializes this event to a map for JSONL output. -
getCurrentStep
Convenience method to get the currently executing step. Use this to correlate an assertion to the step that made it. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
matchType
Returns the value of thematchTyperecord component.- Returns:
- the value of the
matchTyperecord component
-
actualExpr
Returns the value of theactualExprrecord component.- Returns:
- the value of the
actualExprrecord component
-
expectedExpr
Returns the value of theexpectedExprrecord component.- Returns:
- the value of the
expectedExprrecord component
-
actual
Returns the value of theactualrecord component.- Returns:
- the value of the
actualrecord component
-
expected
Returns the value of theexpectedrecord component.- Returns:
- the value of the
expectedrecord component
-
result
Returns the value of theresultrecord component.- Returns:
- the value of the
resultrecord component
-
scenarioRuntime
Returns the value of thescenarioRuntimerecord component.- Returns:
- the value of the
scenarioRuntimerecord component
-
timeStamp
public long timeStamp()Returns the value of thetimeStamprecord component.- Returns:
- the value of the
timeStamprecord component
-