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 of GuardrailResultAssert
R - The type of GuardrailResult
F - The type of GuardrailResult.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 GuardrailResults

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
    Modifier
    Constructor
    Description
    protected
    GuardrailResultAssert(R r, Class<A> resultType, Class<F> failureClass)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Asserts that the InputGuardrailResult contains exactly one GuardrailResult.Failure and verifies that this failure meets the specified requirements.
    Asserts that the actual InputGuardrailResult contains failures.
    Asserts that the actual object's GuardrailResult.Result matches the given expected result.
    hasSingleFailureWithMessage(String expectedFailureMessage)
    Asserts that the actual InputGuardrailResult contains exactly one failure with the specified message.
    hasSuccessfulText(String successfulText)
    Asserts that the actual GuardrailResult.Result contains the specified successful text.
    Asserts that the actual InputGuardrailResult represents a successful state.
    org.assertj.core.api.ListAssert<F>
    Returns a ListAssert for the failures of the actual GuardrailResult.

    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

      protected GuardrailResultAssert(R r, Class<A> resultType, Class<F> failureClass)
  • Method Details

    • hasResult

      public A hasResult(GuardrailResult.Result result)
      Asserts that the actual object's GuardrailResult.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

      public A hasSuccessfulText(String successfulText)
      Asserts that the actual GuardrailResult.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

      public A isSuccessful()
      Asserts that the actual InputGuardrailResult represents a successful state. A successful state is determined by having GuardrailResult.isSuccess().
      Returns:
      this assertion object for method chaining
      Throws:
      AssertionError - if the actual result is not successful as per the aforementioned criteria
    • hasFailures

      public A hasFailures()
      Asserts that the actual InputGuardrailResult 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

      public A hasSingleFailureWithMessage(String expectedFailureMessage)
      Asserts that the actual InputGuardrailResult 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

      public A assertSingleFailureSatisfies(Consumer<F> requirements)
      Asserts that the InputGuardrailResult contains exactly one GuardrailResult.Failure and verifies that this failure meets the specified requirements. The requirements are defined by the provided Consumer.
      Parameters:
      requirements - a Consumer that defines the assertions to be applied to the single failure. Must not be null.
      Returns:
      this assertion object for method chaining.
      Throws:
      NullPointerException - if the requirements is null.
      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 satisfy the specified requirements.
      See Also:
      • AbstractAssert.satisfies(Consumer[])
    • withFailures

      public org.assertj.core.api.ListAssert<F> withFailures()
      Returns a ListAssert for the failures of the actual GuardrailResult.