Package org.assertj.core.api
Class Fail
- java.lang.Object
-
- org.assertj.core.api.Fail
-
public final class Fail extends Object
Common failures.- Author:
- Alex Ruiz, Yvonne Wang, Joel Costigliola
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFail()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 <T> Tfail(String failureMessage)Throws anAssertionErrorwith the given message.static <T> Tfail(String failureMessage, Object... args)Throws anAssertionErrorwith the given message built asString.format(String, Object...).static <T> Tfail(String failureMessage, Throwable realCause)Throws anAssertionErrorwith the given message and with theThrowablethat caused the failure.static <T> TfailBecauseExceptionWasNotThrown(Class<? extends 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(Class<? extends 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
public static <T> T fail(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.orElse(() -> fail("boom")));.
- Throws:
AssertionError- with the given message.
-
fail
public static <T> T fail(String failureMessage, 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.orElse(() -> fail("b%s", ""oom)));.
- Throws:
AssertionError- with the given built message.
-
fail
public static <T> T fail(String failureMessage, 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.orElse(() -> fail("boom", cause)));.
- Throws:
AssertionError- with the given message and with theThrowablethat caused the failure.
-
failBecauseExceptionWasNotThrown
public static <T> T failBecauseExceptionWasNotThrown(Class<? extends 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.orElse(() -> failBecauseExceptionWasNotThrown(IOException.class)));.
- Throws:
AssertionError- with a message explaining that aThrowableof given class was expected to be thrown but had not been.shouldHaveThrown(Class)can be used as a replacement.
-
shouldHaveThrown
public static <T> T shouldHaveThrown(Class<? extends 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.orElse(() -> shouldHaveThrown(IOException.class)));.
- Throws:
AssertionError- with a message explaining that aThrowableof given class was expected to be thrown but had not been.
-
-