Class Fail


  • public final class Fail
    extends java.lang.Object
    Common failures.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Fail()
      This constructor is protected to make it possible to subclass this class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void fail​(java.lang.String failureMessage)
      Throws an AssertionError with the given message.
      static void fail​(java.lang.String failureMessage, java.lang.Object... args)
      Throws an AssertionError with the given message built as String.format(String, Object...).
      static void fail​(java.lang.String failureMessage, java.lang.Throwable realCause)
      Throws an AssertionError with the given message and with the Throwable that caused the failure.
      static void failBecauseExceptionWasNotThrown​(java.lang.Class<? extends java.lang.Throwable> throwableClass)
      Throws an AssertionError with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      static void setRemoveAssertJRelatedElementsFromStackTrace​(boolean removeAssertJRelatedElementsFromStackTrace)
      Sets whether we remove elements related to AssertJ from assertion error stack trace.
      static void shouldHaveThrown​(java.lang.Class<? extends java.lang.Throwable> throwableClass)
      Throws an AssertionError with a message explaining that a Throwable of given class was expected to be thrown but had not been.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Fail

        protected Fail()
        This constructor is protected to make it possible to subclass this class. Since all its methods are static, there is no point on creating a new instance of it.
    • Method Detail

      • setRemoveAssertJRelatedElementsFromStackTrace

        public static void setRemoveAssertJRelatedElementsFromStackTrace​(boolean removeAssertJRelatedElementsFromStackTrace)
        Sets whether we remove elements related to AssertJ from assertion error stack trace.
        Parameters:
        removeAssertJRelatedElementsFromStackTrace - flag.
      • fail

        public static void fail​(java.lang.String failureMessage)
        Throws an AssertionError with the given message.
        Parameters:
        failureMessage - error message.
        Throws:
        java.lang.AssertionError - with the given message.
      • fail

        public static void fail​(java.lang.String failureMessage,
                                java.lang.Object... args)
        Throws an AssertionError with the given message built as String.format(String, Object...).
        Parameters:
        failureMessage - error message.
        args - Arguments referenced by the format specifiers in the format string.
        Throws:
        java.lang.AssertionError - with the given built message.
      • fail

        public static void fail​(java.lang.String failureMessage,
                                java.lang.Throwable realCause)
        Throws an AssertionError with the given message and with the Throwable that caused the failure.
        Parameters:
        failureMessage - the description of the failed assertion. It can be null.
        realCause - cause of the error.
        Throws:
        java.lang.AssertionError - with the given message and with the Throwable that caused the failure.
      • failBecauseExceptionWasNotThrown

        public static void failBecauseExceptionWasNotThrown​(java.lang.Class<? extends java.lang.Throwable> throwableClass)
        Throws an AssertionError 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:
        java.lang.AssertionError - with a message explaining that a Throwable of given class was expected to be thrown but had not been. shouldHaveThrown(Class) can be used as a replacement.
      • shouldHaveThrown

        public static void shouldHaveThrown​(java.lang.Class<? extends java.lang.Throwable> throwableClass)
        Throws an AssertionError 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:
        java.lang.AssertionError - with a message explaining that a Throwable of given class was expected to be thrown but had not been.