Class AssertionFailedErrorBuilder


  • public final class AssertionFailedErrorBuilder
    extends Object
    A builder for AssertionFailedErrors.

    This class is like an extended version of AssertionFailureBuilder. It adds the following additional features:

    • Providing prefixes for both expected and actual values
    • Providing multiple expected and actual values
    • Building reasons with value formatting

    Any method argument may be null unless specified otherwise.

    Author:
    Rob Spoor
    Since:
    2.0
    • Method Detail

      • assertionFailedError

        public static AssertionFailedErrorBuilder assertionFailedError()
        Creates a new AssertionFailedErrorBuilder.
        Returns:
        The created AssertionFailedErrorBuilder.
      • message

        public AssertionFailedErrorBuilder message​(Object message)
        Sets the user-defined message of the assertion.

        The message may be passed as a Supplier or plain string. If any other type is passed, it is converted to string in a null-safe manner.

        Parameters:
        message - The user-defined failure message.
        Returns:
        This object.
      • reason

        public AssertionFailedErrorBuilder reason​(String reason)
        Sets the reason why the assertion failed.
        Parameters:
        reason - The failure reason.
        Returns:
        This object.
      • reasonPattern

        public AssertionFailedErrorBuilder.ReasonBuilder reasonPattern​(String pattern)
        Returns a builder for the reason why the assertion failed.

        Note that each value added to the reason will be formatted before adding; therefore, each argument should be treated as a string.

        Parameters:
        pattern - The pattern for the reason, with the same syntax as String.format(String, Object...).
        Returns:
        A builder for the reason why the assertion failed.
        Throws:
        NullPointerException - If the given pattern is null.
      • expected

        public AssertionFailedErrorBuilder expected​(Object expected)
        Sets the expected value of the assertion.
        Parameters:
        expected - The expected value.
        Returns:
        This object.
      • expectedOneOf

        public AssertionFailedErrorBuilder expectedOneOf​(Object... expected)
        Sets the possible expected values of the assertion. This method will use prefix one of. To omit the prefix, use prefixed("").

        Note that the expected value of the assertion will be a list containing the expected values.

        Parameters:
        expected - The expected values.
        Returns:
        This object.
      • expectedOneOf

        public AssertionFailedErrorBuilder expectedOneOf​(Collection<?> expected)
        Sets the possible expected values of the assertion. This method will use prefix one of. To omit the prefix, use prefixed("").

        Note that the expected value of the assertion will be a list containing the expected values.

        Parameters:
        expected - The expected values.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given collection is null.
      • expectedMessage

        public AssertionFailedErrorBuilder expectedMessage​(String expected)
        Sets a message representing the expected value of the assertion. This message will be added to the final error message without any value indicators.
        Parameters:
        expected - The expected value message.
        Returns:
        This object.
      • actual

        public AssertionFailedErrorBuilder actual​(Object actual)
        Sets the actual value of the assertion.
        Parameters:
        actual - The actual value.
        Returns:
        This object.
      • actualValues

        public AssertionFailedErrorBuilder actualValues​(Object... actual)
        Sets the multiple actual values of the assertion.

        Note that the actual value of the assertion will be a list containing the actual values.

        Parameters:
        actual - The actual values.
        Returns:
        This object.
      • actualValues

        public AssertionFailedErrorBuilder actualValues​(Collection<?> actual)
        Sets the multiple actual values of the assertion.

        Note that the actual value of the assertion will be a list containing the actual values.

        Parameters:
        actual - The actual values.
        Returns:
        This object.
        Throws:
        NullPointerException - If the given collection is null.
      • prefixed

        public AssertionFailedErrorBuilder.PrefixedValues prefixed​(String prefix)
        Returns an object that can be used to set expected or actual values with a prefix.
        Parameters:
        prefix - The prefix to add before the expected or actual value in the generated failure message.
        Returns:
        An object that can be used to set expected or actual values with a prefix.
      • includeValuesInMessage

        public AssertionFailedErrorBuilder includeValuesInMessage​(boolean includeValuesInMessage)
        Sets whether or not to include the actual and expected values in the generated failure message.
        Parameters:
        includeValuesInMessage - true to include the actual and expected values, or false to omit them.
        Returns:
        This object.