Class AbstractSoftAssertions

java.lang.Object
org.assertj.core.api.DefaultAssertionErrorCollector
org.assertj.core.api.AbstractSoftAssertions
All Implemented Interfaces:
AfterAssertionErrorCollected, AssertionErrorCollector, InstanceOfAssertFactories, SoftAssertionsProvider
Direct Known Subclasses:
BDDSoftAssertions, Java6BDDSoftAssertions, Java6JUnitBDDSoftAssertions, Java6JUnitSoftAssertions, Java6SoftAssertions, JUnitBDDSoftAssertions, JUnitJupiterBDDSoftAssertions, JUnitJupiterSoftAssertions, JUnitSoftAssertions, SoftAssertions

public abstract class AbstractSoftAssertions extends DefaultAssertionErrorCollector implements SoftAssertionsProvider, InstanceOfAssertFactories
  • Field Details

  • Constructor Details

    • AbstractSoftAssertions

      protected AbstractSoftAssertions()
  • Method Details

    • assertAll

      public static void assertAll(AssertionErrorCollector collector)
    • assertAll

      public void assertAll()
      Description copied from interface: SoftAssertionsProvider
      Verifies that no soft assertions have failed.
      Specified by:
      assertAll in interface SoftAssertionsProvider
    • proxy

      public <SELF extends Assert<? extends SELF, ? extends ACTUAL>, ACTUAL> SELF proxy(Class<SELF> assertClass, Class<ACTUAL> actualClass, ACTUAL actual)
      Description copied from interface: SoftAssertionsProvider
      Creates a proxied assertion class of the given type. The returned value is an assertion object compatible with the supplied assertion class, but instead of throwing errors it will collect them and store.
      Specified by:
      proxy in interface SoftAssertionsProvider
      Type Parameters:
      SELF - The type of the assertion class
      ACTUAL - The type of the object-under-test
      Parameters:
      assertClass - Class instance for the assertion type.
      actualClass - Class instance for the type of the object-under-test.
      actual - The actual object-under-test.
      Returns:
      A proxied assertion class for the given object-under-test.
    • fail

      public <T> T fail(String failureMessage)
      Fails with the given message.
      Type Parameters:
      T - dummy return value type
      Parameters:
      failureMessage - error message.
      Returns:
      nothing, it's just to be used in doSomething(optional.orElse(() -> fail("boom")));.
      Since:
      2.6.0 / 3.6.0
    • fail

      public <T> T fail(String failureMessage, Object... args)
      Fails with the given message built like String.format(String, Object...).
      Type Parameters:
      T - dummy return value type
      Parameters:
      failureMessage - error message.
      args - Arguments referenced by the format specifiers in the format string.
      Returns:
      nothing, it's just to be used in doSomething(optional.orElse(() -> fail("boom")));.
      Since:
      2.6.0 / 3.6.0
    • fail

      public <T> T fail(String failureMessage, Throwable realCause)
      Fails with the given message and with the Throwable that caused the failure.
      Type Parameters:
      T - dummy return value type
      Parameters:
      failureMessage - error message.
      realCause - cause of the error.
      Returns:
      nothing, it's just to be used in doSomething(optional.orElse(() -> fail("boom")));.
      Since:
      2.6.0 / 3.6.0
    • failBecauseExceptionWasNotThrown

      public void failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)
      Fails with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      Parameters:
      throwableClass - the Throwable class that was expected to be thrown.
      Throws:
      AssertionError - with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      Since:
      2.6.0 / 3.6.0 Fail.shouldHaveThrown(Class) can be used as a replacement.
    • shouldHaveThrown

      public void shouldHaveThrown(Class<? extends Throwable> throwableClass)
      Fails with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      Parameters:
      throwableClass - the Throwable class that was expected to be thrown.
      Throws:
      AssertionError - with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      Since:
      2.6.0 / 3.6.0
    • assertionErrorsCollected

      public List<AssertionError> assertionErrorsCollected()
      Description copied from class: DefaultAssertionErrorCollector
      Returns a list of soft assertions collected errors. If a delegate has been set (see setDelegate(), then this method will return the result of the delegate's assertErrorsCollected().
      Specified by:
      assertionErrorsCollected in interface AssertionErrorCollector
      Overrides:
      assertionErrorsCollected in class DefaultAssertionErrorCollector
      Returns:
      A list of soft assertions collected errors.
    • errorsCollected

      public List<Throwable> errorsCollected()
      Returns a copy of list of soft assertions collected errors.
      Returns:
      a copy of list of soft assertions collected errors.
    • decorateErrorsCollected

      protected <T extends Throwable> List<T> decorateErrorsCollected(List<? extends T> errors)
      Modifies collected errors. Override to customize modification.
      Type Parameters:
      T - the supertype to use in the list return value
      Parameters:
      errors - list of errors to decorate
      Returns:
      decorated list
    • addLineNumberToErrorMessages

      private <T extends Throwable> List<T> addLineNumberToErrorMessages(List<? extends T> errors)
    • addLineNumberToErrorMessage

      private <T extends Throwable> T addLineNumberToErrorMessage(T error)
    • createNewInstanceWithLineNumberInErrorMessage

      private <T extends Throwable> T createNewInstanceWithLineNumberInErrorMessage(T error, StackTraceElement testStackTraceElement) throws ReflectiveOperationException
      Throws:
      ReflectiveOperationException
    • buildErrorMessageWithLineNumber

      private String buildErrorMessageWithLineNumber(String originalErrorMessage, StackTraceElement testStackTraceElement)
    • simpleClassNameOf

      private String simpleClassNameOf(StackTraceElement testStackTraceElement)
    • getFirstStackTraceElementFromTest

      private StackTraceElement getFirstStackTraceElementFromTest(StackTraceElement[] stacktrace)
    • isProxiedAssertionClass

      private boolean isProxiedAssertionClass(String className)