Interface Java6BDDSoftAssertionsProvider
- All Superinterfaces:
AfterAssertionErrorCollected,AssertionErrorCollector,SoftAssertionsProvider
- All Known Subinterfaces:
BDDSoftAssertionsProvider
- All Known Implementing Classes:
AutoCloseableBDDSoftAssertions,BDDSoftAssertions,Java6BDDSoftAssertions,Java6JUnitBDDSoftAssertions,JUnitBDDSoftAssertions,JUnitJupiterBDDSoftAssertions
BDDSoftAssertionsProvider.- Since:
- 2.5.0 / 3.5.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.assertj.core.api.SoftAssertionsProvider
SoftAssertionsProvider.ThrowingRunnable -
Method Summary
Modifier and TypeMethodDescriptiondefault BooleanAssertthen(boolean actual) Creates a new instance of.BooleanAssertdefault BooleanArrayAssertthen(boolean[] actual) Creates a new instance of.BooleanArrayAssertdefault Boolean2DArrayAssertthen(boolean[][] actual) Creates a new instance of.Boolean2DArrayAssertdefault ByteAssertthen(byte actual) Creates a new instance of.ByteAssertdefault ByteArrayAssertthen(byte[] actual) Creates a new instance of.ByteArrayAssertdefault Byte2DArrayAssertthen(byte[][] actual) Creates a new instance of.Byte2DArrayAssertdefault CharacterAssertthen(char actual) Creates a new instance of.CharacterAssertdefault CharArrayAssertthen(char[] actual) Creates a new instance of.CharArrayAssertdefault Char2DArrayAssertthen(char[][] actual) Creates a new instance of.Char2DArrayAssertdefault DoubleAssertthen(double actual) Creates a new instance of.DoubleAssertdefault DoubleArrayAssertthen(double[] actual) Creates a new instance of.DoubleArrayAssertdefault Double2DArrayAssertthen(double[][] actual) Creates a new instance of.Double2DArrayAssertdefault FloatAssertthen(float actual) Creates a new instance of.FloatAssertdefault FloatArrayAssertthen(float[] actual) Creates a new instance of.FloatArrayAssertdefault Float2DArrayAssertthen(float[][] actual) Creates a new instance of.Float2DArrayAssertdefault IntegerAssertthen(int actual) Creates a new instance of.IntegerAssertdefault IntArrayAssertthen(int[] actual) Creates a new instance of.IntArrayAssertdefault Int2DArrayAssertthen(int[][] actual) Creates a new instance of.Int2DArrayAssertdefault LongAssertthen(long actual) Creates a new instance of.LongAssertdefault LongArrayAssertthen(long[] actual) Creates a new instance of.LongArrayAssertdefault Long2DArrayAssertthen(long[][] actual) Creates a new instance of.Long2DArrayAssertdefault ShortAssertthen(short actual) Creates a new instance of.ShortAssertdefault ShortArrayAssertthen(short[] actual) Creates a new instance of.ShortArrayAssertdefault Short2DArrayAssertthen(short[][] actual) Creates a new instance of.Short2DArrayAssertdefault FileAssertCreates a new instance of.FileAssertdefault InputStreamAssertthen(InputStream actual) Creates a new instance of.InputStreamAssertdefault BooleanAssertCreates a new instance of.BooleanAssertdefault ByteAssertCreates a new instance of.ByteAssertdefault CharacterAssertCreates a new instance of.CharacterAssertdefault CharSequenceAssertthen(CharSequence actual) Creates a new instance of.CharSequenceAssertdefault ClassAssertCreates a new instance ofClassAssertdefault DoubleAssertCreates a new instance of.DoubleAssertdefault FloatAssertCreates a new instance of.FloatAssertdefault IntegerAssertCreates a new instance of.IntegerAssertdefault <T> IterableAssert<T> Creates a new instance of.IterableAssertdefault LongAssertCreates a new instance of.LongAssertdefault ShortAssertCreates a new instance of.ShortAssertdefault StringAssertCreates a new instance of.StringAssertdefault CharSequenceAssertthen(StringBuffer actual) Creates a new instance offrom aCharSequenceAssertStringBuffer.default CharSequenceAssertthen(StringBuilder actual) Creates a new instance offrom aCharSequenceAssertStringBuilder.default BigDecimalAssertthen(BigDecimal actual) Creates a new instance of.BigDecimalAssertdefault BigIntegerAssertthen(BigInteger actual) Creates a new instance of.BigIntegerAssertdefault UriAssertCreates a new instance of.UriAssertdefault AbstractUrlAssert<?> Creates a new instance of.UrlAssertdefault <T> CollectionAssert<T> then(Collection<? extends T> actual) Creates a new instance of.CollectionAssertdefault AtomicBooleanAssertthen(AtomicBoolean actual) Create assertion forAtomicBoolean.default AtomicIntegerAssertthen(AtomicInteger actual) Create assertion forAtomicInteger.default AtomicIntegerArrayAssertthen(AtomicIntegerArray actual) Create assertion forAtomicIntegerArray.default <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> then(AtomicIntegerFieldUpdater<OBJECT> actual) Create assertion forAtomicIntegerFieldUpdater.default AtomicLongAssertthen(AtomicLong actual) Create assertion forAtomicLong.default AtomicLongArrayAssertthen(AtomicLongArray actual) Create assertion forAtomicLongArray.default <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> then(AtomicLongFieldUpdater<OBJECT> actual) Create assertion forAtomicLongFieldUpdater.default <VALUE> AtomicMarkableReferenceAssert<VALUE> then(AtomicMarkableReference<VALUE> actual) Create assertion forAtomicMarkableReference.default <VALUE> AtomicReferenceAssert<VALUE> then(AtomicReference<VALUE> actual) Create assertion forAtomicReference.default <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> then(AtomicReferenceArray<ELEMENT> actual) Create assertion forAtomicReferenceArray.default <FIELD,OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> then(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) Create assertion forAtomicReferenceFieldUpdater.default <VALUE> AtomicStampedReferenceAssert<VALUE> then(AtomicStampedReference<VALUE> actual) Create assertion forAtomicStampedReference.default <RESULT> FutureAssert<RESULT> Creates a new instance of.FutureAssertdefault DateAssertCreates a new instance of.DateAssertdefault <T> IteratorAssert<T> Creates a new instance of.IteratorAssertdefault <T> ListAssert<T> Creates a new instance of.ListAssertdefault <K,V> MapAssert <K, V> Creates a new instance of.MapAssertdefault <T extends Comparable<? super T>>
AbstractComparableAssert<?, T> then(T actual) Creates a new instance ofwith standard comparison semantics.GenericComparableAssertdefault <T> ObjectArrayAssert<T> then(T[] actual) Creates a new instance of.ObjectArrayAssertdefault <T> Object2DArrayAssert<T> then(T[][] actual) Creates a new instance of.Object2DArrayAssertdefault CharSequenceAssertthenCharSequence(CharSequence actual) Creates a new instance of.CharSequenceAssertdefault AbstractThrowableAssert<?, ? extends Throwable> thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable) Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.default <E> AbstractCollectionAssert<?, Collection<? extends E>, E, ObjectAssert<E>> thenCollection(Collection<? extends E> actual) Creates a new instance of.CollectionAssertdefault <T> AbstractUniversalComparableAssert<?, T> thenComparable(Comparable<T> actual) Creates a new instance ofwith standard comparison semantics.UniversalComparableAssertdefault ThrowableTypeAssert<Exception> Alias forthenExceptionOfType(Class)forException.default <T extends Throwable>
ThrowableTypeAssert<T> thenExceptionOfType(Class<T> throwableType) Entry point to check that an exception of type T is thrown by a giventhrowingCallablewhich allows to chain assertions on the thrown exception.Alias forthenExceptionOfType(Class)forIllegalArgumentException.default ThrowableTypeAssert<IllegalStateException> Alias forthenExceptionOfType(Class)forIllegalStateException.Alias forthenExceptionOfType(Class)forIndexOutOfBoundsException.default ThrowableTypeAssert<IOException> Alias forthenExceptionOfType(Class)forIOException.default <ELEMENT> IterableAssert<ELEMENT> thenIterable(Iterable<? extends ELEMENT> actual) Creates a new instance of.IterableAssertdefault <ELEMENT> IteratorAssert<ELEMENT> thenIterator(Iterator<? extends ELEMENT> actual) Creates a new instance of.IteratorAssertdefault <ELEMENT> ListAssert<ELEMENT> Creates a new instance of.ListAssertdefault ThrowableTypeAssert<NullPointerException> Alias forthenExceptionOfType(Class)forNullPointerException.default <T> ObjectAssert<T> thenObject(T actual) Creates a new instance offor any object.ObjectAssertAlias forthenExceptionOfType(Class)forReflectiveOperationException.default ThrowableTypeAssert<RuntimeException> Alias forthenExceptionOfType(Class)forRuntimeException.default AbstractThrowableAssert<?, ? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable) Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.default AbstractThrowableAssert<?, ? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args) Allows to capture and then assert on aThrowablelikethenThrownBy(ThrowingCallable)but this method let you set the assertion description the same way you do withas(String, Object...).Methods inherited from interface org.assertj.core.api.AssertionErrorCollector
assertionErrorsCollected, collectAssertionError, getDelegate, onAssertionErrorCollected, setDelegate, succeeded, wasSuccessMethods inherited from interface org.assertj.core.api.SoftAssertionsProvider
assertAll, assertAlso, check, proxy
-
Method Details
-
then
Creates a new instance of.BigDecimalAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.BigIntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.BooleanArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Boolean2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ByteArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Byte2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.CharArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Char2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance ofClassAssertWe don't return
ClassAssertas it has overridden methods to annotated withSafeVarargs.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.CollectionAssert- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.21.0
-
thenCollection
default <E> AbstractCollectionAssert<?,Collection<? extends E>, thenCollectionE, ObjectAssert<E>> (Collection<? extends E> actual) Creates a new instance of.CollectionAssertUse this over
then(Collection)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Type Parameters:
E- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.23.0
-
then
Creates a new instance ofwith standard comparison semantics.GenericComparableAssert- Type Parameters:
T- the type of actual.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenComparable
Creates a new instance ofwith standard comparison semantics.UniversalComparableAssertUse this over
then(Comparable)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Type Parameters:
T- the type of actual.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.23.0
-
then
Creates a new instance of.IterableAssert- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenIterable
Creates a new instance of.IterableAssertUse this over
then(Iterable)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Type Parameters:
ELEMENT- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.23.0
-
then
Creates a new instance of.IteratorAssertThis is a breaking change in version 3.12.0: this method used to return an
IterableAssert.- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenIterator
Creates a new instance of.IteratorAssertUse this over
then(Iterator)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Type Parameters:
ELEMENT- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.23.0
-
then
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.DoubleArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Double2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.FileAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.FutureAssert- Type Parameters:
RESULT- the type of the value contained in theFuture.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of.InputStreamAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.FloatArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Float2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.IntArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Int2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ListAssert- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenList
Creates a new instance of.ListAssertUse this over
then(List)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Type Parameters:
ELEMENT- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.23.0
-
then
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.LongArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Long2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.ObjectAssert- Type Parameters:
T- the type of the actual value.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ObjectArrayAssert- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Object2DArrayAssert- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.MapAssertWe don't return
MapAssertas it has overridden methods to annotated withSafeVarargs.- Type Parameters:
K- the type of keys in the map.V- the type of values in the map.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.ShortArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.Short2DArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
Creates a new instance of.CharSequenceAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenCharSequence
Creates a new instance of.CharSequenceAssertUse this over
then(CharSequence)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesthenfor.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.25.0
-
then
Creates a new instance offrom aCharSequenceAssertStringBuilder.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
Creates a new instance offrom aCharSequenceAssertStringBuffer.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
Creates a new instance of.StringAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.DateAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forAtomicBoolean.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicInteger.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicIntegerArray.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> then(AtomicIntegerFieldUpdater<OBJECT> actual) Create assertion forAtomicIntegerFieldUpdater.- Type Parameters:
OBJECT- The type of the object holding the updatable field- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicLong.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicLongArray.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicLongFieldUpdater.- Type Parameters:
OBJECT- the type of the object holding the updatable field- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicReference.- Type Parameters:
VALUE- the type of object referred to by this reference- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicReferenceArray.- Type Parameters:
ELEMENT- the type of object referred to by theAtomicReferenceArray.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> then(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) Create assertion forAtomicReferenceFieldUpdater.- Type Parameters:
FIELD- The type of the fieldOBJECT- the type of the object holding the updatable field- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicMarkableReference.- Type Parameters:
VALUE- the type of object referred to by this reference- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicStampedReference.- Type Parameters:
VALUE- the type of value referred to by this reference- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of.ThrowableAssert- Type Parameters:
T- the type of the actual throwable.- Parameters:
actual- the actual value.- Returns:
- the created assertion Throwable.
-
thenThrownBy
default AbstractThrowableAssert<?,? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable) Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.Java 8 example :
Java 7 example :@Test default void testException() { BDDSoftAssertions softly = new BDDSoftAssertions(); softly.thenThrownBy(() -> { throw new Exception("boom!"); }).isInstanceOf(Exception.class) .hasMessageContaining("boom"); }
If the providedBDDSoftAssertions softly = new BDDSoftAssertions(); softly.thenThrownBy(new ThrowingCallable() { @Override default Void call() throws Exception { throw new Exception("boom!"); } }).isInstanceOf(Exception.class) .hasMessageContaining("boom");ThrowableAssert.ThrowingCallabledoes not raise an exception, an error is immediately thrown, in that case the test description provided withas(String, Object...)is not honored.
To use a test description, useAssertions.catchThrowable(ThrowableAssert.ThrowingCallable)as shown below:
Alternatively you can also use// assertion will fail but "display me" won't appear in the error softly.thenThrownBy(() -> {}).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error Throwable thrown = catchThrowable(() -> {}); softly.then(thrown).as("display me") .isInstanceOf(Exception.class);thenCode(ThrowingCallable)for the test description provided withas(String, Object...)to always be honored.- Parameters:
shouldRaiseThrowable- TheThrowableAssert.ThrowingCallableor lambda with the code that should raise the throwable.- Returns:
- The captured exception or
nullif none was raised by the callable.
-
thenThrownBy
default AbstractThrowableAssert<?,? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args) Allows to capture and then assert on aThrowablelikethenThrownBy(ThrowingCallable)but this method let you set the assertion description the same way you do withas(String, Object...).Example:
If the provided@Test default void testException() { BDDSoftAssertions softly = new BDDSoftAssertions(); // if this assertion failed (but it doesn't), the error message would start with [Test explosive code] softly.thenThrownBy(() -> { throw new IOException("boom!") }, "Test explosive code") .isInstanceOf(IOException.class) .hasMessageContaining("boom"); }ThrowingCallabledoes not raise an exception, an error is immediately thrown.The test description provided is honored but not the one with
as(String, Object...), example:// assertion will fail but "display me" won't appear in the error message softly.thenThrownBy(() -> {}).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error message softly.thenThrownBy(() -> {}, "display me") .isInstanceOf(Exception.class);- Parameters:
shouldRaiseThrowable- TheThrowableAssert.ThrowingCallableor lambda with the code that should raise the throwable.description- the new description to set.args- optional parameter if description is a format String.- Returns:
- the created
ThrowableAssert. - Since:
- 3.9.0
-
thenCode
default AbstractThrowableAssert<?,? extends Throwable> thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable) Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.Example :
Contrary toThrowingCallable callable = () -> { throw new Exception("boom!"); }; // assertion succeeds thenCode(callable).isInstanceOf(Exception.class) .hasMessageContaining("boom"); // assertion fails thenCode(callable).doesNotThrowAnyException();thenThrownBy(ThrowingCallable)the test description provided withas(String, Object...)is always honored as shown below.ThrowingCallable doNothing = () -> { // do nothing }; // assertion fails and "display me" appears in the assertion error thenCode(doNothing).as("display me") .isInstanceOf(Exception.class);This method was not named
thenbecause the java compiler reported it ambiguous when used directly with a lambda :(- Parameters:
shouldRaiseOrNotThrowable- TheThrowableAssert.ThrowingCallableor lambda with the code that should raise the throwable.- Returns:
- The captured exception or
nullif none was raised by the callable. - Since:
- 3.7.0
-
thenObject
Creates a new instance offor any object.ObjectAssertThis overload is useful, when an overloaded method of then(...) takes precedence over the generic
then(Object).Example:
Cast necessary becausethen(List)"forgets" actual type:
No cast needed, but also no additional list assertions:then(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));thenObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc"));- Type Parameters:
T- the type of the actual value.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.12.0
-
then
Creates a new instance of.UriAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of.UrlAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
thenExceptionOfType
Entry point to check that an exception of type T is thrown by a giventhrowingCallablewhich allows to chain assertions on the thrown exception.Example:
This method is more or less the same ofsoftly.thenExceptionOfType(IOException.class) .isThrownBy(() -> { throw new IOException("boom!"); }) .withMessage("boom!");thenThrownBy(ThrowingCallable)but in a more natural way.- Type Parameters:
T- the Throwable type.- Parameters:
throwableType- the Throwable type class.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0.
-
thenRuntimeException
Alias forthenExceptionOfType(Class)forRuntimeException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenNullPointerException
Alias forthenExceptionOfType(Class)forNullPointerException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenIllegalArgumentException
Alias forthenExceptionOfType(Class)forIllegalArgumentException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenIOException
Alias forthenExceptionOfType(Class)forIOException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenIllegalStateException
Alias forthenExceptionOfType(Class)forIllegalStateException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenException
Alias forthenExceptionOfType(Class)forException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenReflectiveOperationException
Alias forthenExceptionOfType(Class)forReflectiveOperationException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
thenIndexOutOfBoundsException
Alias forthenExceptionOfType(Class)forIndexOutOfBoundsException.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-