Package org.assertj.core.api
Class Fail
- java.lang.Object
-
- org.assertj.core.api.Fail
-
public final class Fail extends java.lang.ObjectCommon failures.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateFail()Since all its methods are static and the class is final, there is no point on creating a new instance of it.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tfail()Throws anAssertionErrorwith an empty message to be used in code like:static <T> Tfail(java.lang.String failureMessage)Throws anAssertionErrorwith the given message.static <T> Tfail(java.lang.String failureMessage, java.lang.Object... args)Throws anAssertionErrorwith the given message built asString.format(String, Object...).static <T> Tfail(java.lang.String failureMessage, java.lang.Throwable realCause)Throws anAssertionErrorwith the given message and with theThrowablethat caused the failure.static <T> Tfail(java.lang.Throwable realCause)Throws anAssertionErrorwith theThrowablethat caused the failure.static <T> TfailBecauseExceptionWasNotThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)Throws anAssertionErrorwith a message explaining that aThrowableof given class was expected to be thrown but had not been.static voidsetRemoveAssertJRelatedElementsFromStackTrace(boolean removeAssertJRelatedElementsFromStackTrace)Sets whether we remove elements related to AssertJ from assertion error stack trace.static <T> TshouldHaveThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)Throws anAssertionErrorwith a message explaining that aThrowableof given class was expected to be thrown but had not been.
-
-
-
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
@Contract("_ -> fail") public static <T> T fail(java.lang.String failureMessage)
Throws anAssertionErrorwith 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:
java.lang.AssertionError- with the given message.
-
fail
@Contract(" -> fail") public static <T> T fail()
Throws anAssertionErrorwith an empty message to be used in code like:doSomething(optional.orElseGet(() -> fail()));- Type Parameters:
T- dummy return value type- Returns:
- nothing, it's just to be used in
doSomething(optional.orElseGet(() -> fail()));. - Throws:
java.lang.AssertionError- with an empty message.- Since:
- 3.26.0
-
fail
@Contract("_, _ -> fail") public static <T> T fail(java.lang.String failureMessage, java.lang.Object... args)
Throws anAssertionErrorwith 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:
java.lang.AssertionError- with the given built message.
-
fail
@Contract("_, _ -> fail") public static <T> T fail(java.lang.String failureMessage, java.lang.Throwable realCause)
Throws anAssertionErrorwith the given message and with theThrowablethat 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:
java.lang.AssertionError- with the given message and with theThrowablethat caused the failure.
-
fail
@Contract("_ -> fail") public static <T> T fail(java.lang.Throwable realCause)
Throws anAssertionErrorwith theThrowablethat caused the failure.- Type Parameters:
T- dummy return value type- Parameters:
realCause- cause of the error.- Returns:
- nothing, it's just to be used in
doSomething(optional.orElseGet(() -> fail(cause)));. - Throws:
java.lang.AssertionError- with theThrowablethat caused the failure.
-
failBecauseExceptionWasNotThrown
@Contract("_ -> fail") public static <T> T failBecauseExceptionWasNotThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)
Throws anAssertionErrorwith a message explaining that aThrowableof 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:
java.lang.AssertionError- with a message explaining that aThrowableof given class was expected to be thrown but had not been.- See Also:
shouldHaveThrown(Class)
-
shouldHaveThrown
@Contract("_ -> fail") public static <T> T shouldHaveThrown(java.lang.Class<? extends java.lang.Throwable> throwableClass)
Throws anAssertionErrorwith a message explaining that aThrowableof 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:
java.lang.AssertionError- with a message explaining that aThrowableof given class was expected to be thrown but had not been.
-
-