Package org.assertj.core.api
Class Fail
java.lang.Object
org.assertj.core.api.Fail
Common failures.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Fail()
Since all its methods are static and the class is final, there is no point on creating a new instance of it. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Throws anAssertionError
with the given message.static <T> T
Throws anAssertionError
with the given message built asString.format(String, Object...)
.static <T> T
Throws anAssertionError
with the given message and with theThrowable
that caused the failure.static <T> T
failBecauseExceptionWasNotThrown
(Class<? extends Throwable> throwableClass) Throws anAssertionError
with a message explaining that aThrowable
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 <T> T
shouldHaveThrown
(Class<? extends Throwable> throwableClass) Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.
-
Constructor Details
-
Fail
private Fail()Since all its methods are static and the class is final, there is no point on creating a new instance of it.
-
-
Method Details
-
setRemoveAssertJRelatedElementsFromStackTrace
public static void setRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace) Sets whether we remove elements related to AssertJ from assertion error stack trace.- Parameters:
removeAssertJRelatedElementsFromStackTrace
- flag.
-
fail
Throws anAssertionError
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.orElseGet(() -> fail("boom")));
. - Throws:
AssertionError
- with the given message.
-
fail
Throws anAssertionError
with the given message built asString.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.orElseGet(() -> fail("b%s", ""oom)));
. - Throws:
AssertionError
- with the given built message.
-
fail
Throws anAssertionError
with the given message and with theThrowable
that caused the failure.- Type Parameters:
T
- dummy return value type- Parameters:
failureMessage
- the description of the failed assertion. It can benull
.realCause
- cause of the error.- Returns:
- nothing, it's just to be used in
doSomething(optional.orElseGet(() -> fail("boom", cause)));
. - Throws:
AssertionError
- with the given message and with theThrowable
that caused the failure.
-
failBecauseExceptionWasNotThrown
Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Type Parameters:
T
- dummy return value type- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Returns:
- nothing, it's just to be used in
doSomething(optional.orElseGet(() -> failBecauseExceptionWasNotThrown(IOException.class)));
. - Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.shouldHaveThrown(Class)
can be used as a replacement.
-
shouldHaveThrown
Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Type Parameters:
T
- dummy return value type- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Returns:
- nothing, it's just to be used in
doSomething(optional.orElseGet(() -> shouldHaveThrown(IOException.class)));
. - Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.
-