Package dev.langchain4j.test.guardrail
Class GuardrailResultAssert<A extends GuardrailResultAssert<A,R,F>,R extends GuardrailResult<R>,F extends GuardrailResult.Failure>
java.lang.Object
org.assertj.core.api.AbstractAssert<A,R>
org.assertj.core.api.AbstractObjectAssert<A,R>
dev.langchain4j.test.guardrail.GuardrailResultAssert<A,R,F>
- Type Parameters:
A
- The type ofGuardrailResultAssert
R
- The type ofGuardrailResult
F
- The type ofGuardrailResult.Failure
- All Implemented Interfaces:
org.assertj.core.api.Assert<A,
,R> org.assertj.core.api.Descriptable<A>
,org.assertj.core.api.ExtensionPoints<A,
R>
- Direct Known Subclasses:
InputGuardrailResultAssert
,OutputGuardrailResultAssert
public abstract sealed class GuardrailResultAssert<A extends GuardrailResultAssert<A,R,F>,R extends GuardrailResult<R>,F extends GuardrailResult.Failure>
extends org.assertj.core.api.AbstractObjectAssert<A,R>
permits InputGuardrailResultAssert, OutputGuardrailResultAssert
Custom assertions for
GuardrailResult
s
This follows the pattern described in https://assertj.github.io/doc/#assertj-core-custom-assertions-creation
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionassertSingleFailureSatisfies
(Consumer<F> requirements) Asserts that theInputGuardrailResult
contains exactly oneGuardrailResult.Failure
and verifies that this failure meets the specified requirements.Asserts that the actualInputGuardrailResult
contains failures.hasResult
(GuardrailResult.Result result) Asserts that the actual object'sGuardrailResult.Result
matches the given expected result.hasSingleFailureWithMessage
(String expectedFailureMessage) Asserts that the actualInputGuardrailResult
contains exactly one failure with the specified message.hasSuccessfulText
(String successfulText) Asserts that the actualGuardrailResult.Result
contains the specified successful text.Asserts that the actualInputGuardrailResult
represents a successful state.org.assertj.core.api.ListAssert
<F> Returns aListAssert
for the failures of the actualGuardrailResult
.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison
Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.assertj.core.api.Descriptable
as, describedAs, describedAs
-
Constructor Details
-
GuardrailResultAssert
-
-
Method Details
-
hasResult
Asserts that the actual object'sGuardrailResult.Result
matches the given expected result. If the result does not match, an assertion error is thrown with the actual and expected values.- Parameters:
result
- the expected result to compare against the actual object's result- Returns:
- this assertion object for method chaining
- Throws:
AssertionError
- if the actual result does not match the expected result
-
hasSuccessfulText
Asserts that the actualGuardrailResult.Result
contains the specified successful text. This method verifies that the actual instance is in a successful state and that the successful text matches the expected value. If the assertion fails, an error is thrown, detailing the mismatch.- Parameters:
successfulText
- the expected text for the successful state- Returns:
- this assertion object for method chaining
- Throws:
AssertionError
- if the actual object is not successful or if the successful text does not match the expected text
-
isSuccessful
Asserts that the actualInputGuardrailResult
represents a successful state. A successful state is determined by havingGuardrailResult.isSuccess()
.- Returns:
- this assertion object for method chaining
- Throws:
AssertionError
- if the actual result is not successful as per the aforementioned criteria
-
hasFailures
Asserts that the actualInputGuardrailResult
contains failures. The method validates that the object being asserted is not null and that there are failures present within the result.- Returns:
- this assertion object for method chaining
- Throws:
AssertionError
- if the actual object is null or if the failures are empty
-
hasSingleFailureWithMessage
Asserts that the actualInputGuardrailResult
contains exactly one failure with the specified message. If the assertion fails, an error is thrown detailing the problem.- Parameters:
expectedFailureMessage
- the expected message of the single failure- Returns:
- this assertion object for method chaining
- Throws:
AssertionError
- if the actual object is null, if there are no failures, if there is more than one failure, or if the single failure does not match the specified message
-
assertSingleFailureSatisfies
Asserts that theInputGuardrailResult
contains exactly oneGuardrailResult.Failure
and verifies that this failure meets the specified requirements. The requirements are defined by the providedConsumer
.- Parameters:
requirements
- aConsumer
that defines the assertions to be applied to the single failure. Must not benull
.- Returns:
- this assertion object for method chaining.
- Throws:
NullPointerException
- if therequirements
isnull
.AssertionError
- if the actual object isnull
, if there are no failures, if there is more than one failure, or if the single failure does not satisfy the specified requirements.- See Also:
-
withFailures
Returns aListAssert
for the failures of the actualGuardrailResult
.
-