Package org.assertj.core.api
Class NotThrownAssert
- java.lang.Object
-
- org.assertj.core.api.NotThrownAssert
-
- All Implemented Interfaces:
Descriptable<NotThrownAssert>
public class NotThrownAssert extends Object implements Descriptable<NotThrownAssert>
Assertion class checking aThrowableAssert.ThrowingCallablethrows no exception.The class itself does not do much, it delegates the work to
ThrowableAssertafter callingisThrownBy(ThrowingCallable).- Since:
- 3.17.0
- See Also:
ThrowableTypeAssert
-
-
Field Summary
Fields Modifier and Type Field Description protected Descriptiondescription
-
Constructor Summary
Constructors Constructor Description NotThrownAssert()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NotThrownAssertdescribedAs(Description description)Sets the description of the assertion that is going to be called after.voidisThrownBy(ThrowableAssert.ThrowingCallable code)Assert that no exception of any type is thrown by thethrowingCallable.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.Descriptable
as, as, describedAs
-
-
-
-
Field Detail
-
description
protected Description description
-
-
Method Detail
-
isThrownBy
public void isThrownBy(ThrowableAssert.ThrowingCallable code)
Assert that no exception of any type is thrown by thethrowingCallable.Example:
assertThatNoException().isThrownBy(() -> { System.out.println("OK"); });- Parameters:
code- code not throwing any exception- Throws:
AssertionError- if the actual statement raised aThrowable.
-
describedAs
public NotThrownAssert describedAs(Description description)
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
Stringby allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Specified by:
describedAsin interfaceDescriptable<NotThrownAssert>- Parameters:
description- the new description to set.- Returns:
thisobject.
-
-