Package nl.pim16aap2.testing.logging
Record Class LogAssertionsUtil.ThrowableSpec
java.lang.Object
java.lang.Record
nl.pim16aap2.testing.logging.LogAssertionsUtil.ThrowableSpec
- Record Components:
expectedType- The expected type of the exception.expectedMessage- The expected message of the exception.stringCompareMethod- The method to use when comparing the expected and actual messages.
- Enclosing class:
LogAssertionsUtil
public static record LogAssertionsUtil.ThrowableSpec(Class<?> expectedType, @Nullable String expectedMessage, LogAssertionsUtil.MessageComparisonMethod stringCompareMethod)
extends Record
Represents a specification for an expected exception.
This is used to specify the expected type of an exception and its message.
If the message is null, it will not be checked when comparing this specification to a throwable.
-
Constructor Summary
ConstructorsConstructorDescriptionThrowableSpec(Class<?> expectedType) Creates a new instance of the exception specification.ThrowableSpec(Class<?> expectedType, @Nullable String expectedMessage) Creates a new instance of the exception specification.ThrowableSpec(Class<?> expectedType, @Nullable String expectedMessage, LogAssertionsUtil.MessageComparisonMethod stringCompareMethod) Creates an instance of aThrowableSpecrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.@Nullable StringReturns the value of theexpectedMessagerecord component.Class<?> Returns the value of theexpectedTyperecord component.final inthashCode()Returns a hash code value for this object.booleanChecks whether the throwable matches the specification.booleanmessageMatches(@Nullable String message) Checks whether the message matches the expected message.static LogAssertionsUtil.ThrowableSpec[]Creates an array of ThrowableSpecs from the provided classes.Returns the value of thestringCompareMethodrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ThrowableSpec
Creates a new instance of the exception specification.Defaults to
LogAssertionsUtil.MessageComparisonMethod.EQUALSfor the message comparison.- Parameters:
expectedType- The expected type of the exception.expectedMessage- The expected message of the exception.
-
ThrowableSpec
Creates a new instance of the exception specification.Sets the expected message to null, meaning it will not be checked when comparing this specification to a throwable.
- Parameters:
expectedType- The expected type of the exception.
-
ThrowableSpec
public ThrowableSpec(Class<?> expectedType, @Nullable @Nullable String expectedMessage, LogAssertionsUtil.MessageComparisonMethod stringCompareMethod) Creates an instance of aThrowableSpecrecord class.- Parameters:
expectedType- the value for theexpectedTyperecord componentexpectedMessage- the value for theexpectedMessagerecord componentstringCompareMethod- the value for thestringCompareMethodrecord component
-
-
Method Details
-
matches
@Contract(value="null -> false", pure=true) public boolean matches(@Nullable @Nullable Throwable throwable) Checks whether the throwable matches the specification.- Parameters:
throwable- The throwable to check.- Returns:
- True if the throwable matches the specification, false otherwise.
-
messageMatches
Checks whether the message matches the expected message.If the expected message is null, this method will always return true.
- Parameters:
message- The message to check.- Returns:
- True if the message matches, false otherwise.
-
of
Creates an array of ThrowableSpecs from the provided classes.See
ThrowableSpec(Class).- Parameters:
classes- The classes to create the ThrowableSpecs from.- Returns:
- The array of ThrowableSpecs.
-
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. All components in this record class are compared withObjects::equals(Object,Object). -
expectedType
Returns the value of theexpectedTyperecord component.- Returns:
- the value of the
expectedTyperecord component
-
expectedMessage
Returns the value of theexpectedMessagerecord component.- Returns:
- the value of the
expectedMessagerecord component
-
stringCompareMethod
Returns the value of thestringCompareMethodrecord component.- Returns:
- the value of the
stringCompareMethodrecord component
-