Package org.assertj.core.api
Interface Java6BDDSoftAssertionsProvider
-
- All Superinterfaces:
AfterAssertionErrorCollected
,AssertionErrorCollector
,SoftAssertionsProvider
- All Known Subinterfaces:
BDDSoftAssertionsProvider
- All Known Implementing Classes:
AutoCloseableBDDSoftAssertions
,BDDSoftAssertions
,Java6BDDSoftAssertions
,Java6JUnitBDDSoftAssertions
,JUnitBDDSoftAssertions
,JUnitJupiterBDDSoftAssertions
public interface Java6BDDSoftAssertionsProvider extends SoftAssertionsProvider
AbstractBDDSoftAssertions compatible with Android. Duplicated fromBDDSoftAssertionsProvider
.- Since:
- 2.5.0 / 3.5.0
- See Also:
BDDSoftAssertionsProvider
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.assertj.core.api.SoftAssertionsProvider
SoftAssertionsProvider.ThrowingRunnable
-
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default BooleanAssert
then(boolean actual)
Creates a new instance of
.BooleanAssert
default BooleanArrayAssert
then(boolean[] actual)
Creates a new instance of
.BooleanArrayAssert
default Boolean2DArrayAssert
then(boolean[][] actual)
Creates a new instance of
.Boolean2DArrayAssert
default ByteAssert
then(byte actual)
Creates a new instance of
.ByteAssert
default ByteArrayAssert
then(byte[] actual)
Creates a new instance of
.ByteArrayAssert
default Byte2DArrayAssert
then(byte[][] actual)
Creates a new instance of
.Byte2DArrayAssert
default CharacterAssert
then(char actual)
Creates a new instance of
.CharacterAssert
default CharArrayAssert
then(char[] actual)
Creates a new instance of
.CharArrayAssert
default Char2DArrayAssert
then(char[][] actual)
Creates a new instance of
.Char2DArrayAssert
default DoubleAssert
then(double actual)
Creates a new instance of
.DoubleAssert
default DoubleArrayAssert
then(double[] actual)
Creates a new instance of
.DoubleArrayAssert
default Double2DArrayAssert
then(double[][] actual)
Creates a new instance of
.Double2DArrayAssert
default FloatAssert
then(float actual)
Creates a new instance of
.FloatAssert
default FloatArrayAssert
then(float[] actual)
Creates a new instance of
.FloatArrayAssert
default Float2DArrayAssert
then(float[][] actual)
Creates a new instance of
.Float2DArrayAssert
default IntegerAssert
then(int actual)
Creates a new instance of
.IntegerAssert
default IntArrayAssert
then(int[] actual)
Creates a new instance of
.IntArrayAssert
default Int2DArrayAssert
then(int[][] actual)
Creates a new instance of
.Int2DArrayAssert
default LongAssert
then(long actual)
Creates a new instance of
.LongAssert
default LongArrayAssert
then(long[] actual)
Creates a new instance of
.LongArrayAssert
default Long2DArrayAssert
then(long[][] actual)
Creates a new instance of
.Long2DArrayAssert
default ShortAssert
then(short actual)
Creates a new instance of
.ShortAssert
default ShortArrayAssert
then(short[] actual)
Creates a new instance of
.ShortArrayAssert
default Short2DArrayAssert
then(short[][] actual)
Creates a new instance of
.Short2DArrayAssert
default FileAssert
then(File actual)
Creates a new instance of
.FileAssert
default InputStreamAssert
then(InputStream actual)
Creates a new instance of
.InputStreamAssert
default BooleanAssert
then(Boolean actual)
Creates a new instance of
.BooleanAssert
default ByteAssert
then(Byte actual)
Creates a new instance of
.ByteAssert
default CharacterAssert
then(Character actual)
Creates a new instance of
.CharacterAssert
default CharSequenceAssert
then(CharSequence actual)
Creates a new instance of
.CharSequenceAssert
default ClassAssert
then(Class<?> actual)
Creates a new instance ofClassAssert
default DoubleAssert
then(Double actual)
Creates a new instance of
.DoubleAssert
default FloatAssert
then(Float actual)
Creates a new instance of
.FloatAssert
default IntegerAssert
then(Integer actual)
Creates a new instance of
.IntegerAssert
default <T> IterableAssert<T>
then(Iterable<? extends T> actual)
Creates a new instance of
.IterableAssert
default LongAssert
then(Long actual)
Creates a new instance of
.LongAssert
default ShortAssert
then(Short actual)
Creates a new instance of
.ShortAssert
default StringAssert
then(String actual)
Creates a new instance of
.StringAssert
default CharSequenceAssert
then(StringBuffer actual)
Creates a new instance of
from aCharSequenceAssert
StringBuffer
.default CharSequenceAssert
then(StringBuilder actual)
Creates a new instance of
from aCharSequenceAssert
StringBuilder
.default ThrowableAssert
then(Throwable actual)
Creates a new instance of
.ThrowableAssert
default BigDecimalAssert
then(BigDecimal actual)
Creates a new instance of
.BigDecimalAssert
default BigIntegerAssert
then(BigInteger actual)
Creates a new instance of
.BigIntegerAssert
default UriAssert
then(URI actual)
Creates a new instance of
.UriAssert
default UrlAssert
then(URL actual)
Creates a new instance of
.UrlAssert
default AtomicBooleanAssert
then(AtomicBoolean actual)
Create assertion forAtomicBoolean
.default AtomicIntegerAssert
then(AtomicInteger actual)
Create assertion forAtomicInteger
.default AtomicIntegerArrayAssert
then(AtomicIntegerArray actual)
Create assertion forAtomicIntegerArray
.default <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT>
then(AtomicIntegerFieldUpdater<OBJECT> actual)
Create assertion forAtomicIntegerFieldUpdater
.default AtomicLongAssert
then(AtomicLong actual)
Create assertion forAtomicLong
.default AtomicLongArrayAssert
then(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>
then(Future<RESULT> actual)
Creates a new instance of
.FutureAssert
default DateAssert
then(Date actual)
Creates a new instance of
.DateAssert
default <T> IteratorAssert<T>
then(Iterator<? extends T> actual)
Creates a new instance of
.IteratorAssert
default <T> ListAssert<T>
then(List<? extends T> actual)
Creates a new instance of
.ListAssert
default <K,V>
MapAssert<K,V>then(Map<K,V> actual)
Creates a new instance of
.MapAssert
default <T extends Comparable<? super T>>
GenericComparableAssert<T>then(T actual)
Creates a new instance of
with standard comparison semantics.GenericComparableAssert
default <T> ObjectArrayAssert<T>
then(T[] actual)
Creates a new instance of
.ObjectArrayAssert
default <T> Object2DArrayAssert<T>
then(T[][] actual)
Creates a new instance of
.Object2DArrayAssert
default ThrowableAssert
thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.default <T> ObjectAssert<T>
thenObject(T actual)
Creates a new instance of
for any object.ObjectAssert
default ThrowableAssert
thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.default ThrowableAssert
thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)
Allows to capture and then assert on aThrowable
likethenThrownBy(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, wasSuccess
-
Methods inherited from interface org.assertj.core.api.SoftAssertionsProvider
assertAll, assertAlso, check, proxy
-
-
-
-
Method Detail
-
then
default BigDecimalAssert then(BigDecimal actual)
Creates a new instance of
.BigDecimalAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default BigIntegerAssert then(BigInteger actual)
Creates a new instance of
.BigIntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default BooleanAssert then(boolean actual)
Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default BooleanAssert then(Boolean actual)
Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default BooleanArrayAssert then(boolean[] actual)
Creates a new instance of
.BooleanArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Boolean2DArrayAssert then(boolean[][] actual)
Creates a new instance of
.Boolean2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default ByteAssert then(byte actual)
Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default ByteAssert then(Byte actual)
Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default ByteArrayAssert then(byte[] actual)
Creates a new instance of
.ByteArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Byte2DArrayAssert then(byte[][] actual)
Creates a new instance of
.Byte2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default CharacterAssert then(char actual)
Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default CharArrayAssert then(char[] actual)
Creates a new instance of
.CharArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Char2DArrayAssert then(char[][] actual)
Creates a new instance of
.Char2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default CharacterAssert then(Character actual)
Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default ClassAssert then(Class<?> actual)
Creates a new instance ofClassAssert
We don't return
ClassAssert
as it has overridden methods to annotated withSafeVarargs
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <T extends Comparable<? super T>> GenericComparableAssert<T> then(T actual)
Creates a new instance of
with standard comparison semantics.GenericComparableAssert
- Type Parameters:
T
- the type of actual.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <T> IterableAssert<T> then(Iterable<? extends T> actual)
Creates a new instance of
.IterableAssert
- Type Parameters:
T
- the type of elements.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <T> IteratorAssert<T> then(Iterator<? extends T> actual)
Creates a new instance of
.IteratorAssert
This 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.
-
then
default DoubleAssert then(double actual)
Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default DoubleAssert then(Double actual)
Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default DoubleArrayAssert then(double[] actual)
Creates a new instance of
.DoubleArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Double2DArrayAssert then(double[][] actual)
Creates a new instance of
.Double2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default FileAssert then(File actual)
Creates a new instance of
.FileAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <RESULT> FutureAssert<RESULT> then(Future<RESULT> actual)
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
default InputStreamAssert then(InputStream actual)
Creates a new instance of
.InputStreamAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default FloatAssert then(float actual)
Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default FloatAssert then(Float actual)
Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default FloatArrayAssert then(float[] actual)
Creates a new instance of
.FloatArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Float2DArrayAssert then(float[][] actual)
Creates a new instance of
.Float2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default IntegerAssert then(int actual)
Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default IntArrayAssert then(int[] actual)
Creates a new instance of
.IntArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Int2DArrayAssert then(int[][] actual)
Creates a new instance of
.Int2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default IntegerAssert then(Integer actual)
Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <T> ListAssert<T> then(List<? extends T> actual)
Creates a new instance of
.ListAssert
- Type Parameters:
T
- the type of elements.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default LongAssert then(long actual)
Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default LongAssert then(Long actual)
Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default LongArrayAssert then(long[] actual)
Creates a new instance of
.LongArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Long2DArrayAssert then(long[][] actual)
Creates a new instance of
.Long2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default <T> ObjectAssert<T> then(T actual)
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
default <T> ObjectArrayAssert<T> then(T[] actual)
Creates a new instance of
.ObjectArrayAssert
- Type Parameters:
T
- the type of elements.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default <T> Object2DArrayAssert<T> then(T[][] actual)
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
default <K,V> MapAssert<K,V> then(Map<K,V> actual)
Creates a new instance of
.MapAssert
We don't return
MapAssert
as 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
default ShortAssert then(short actual)
Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default ShortAssert then(Short actual)
Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default ShortArrayAssert then(short[] actual)
Creates a new instance of
.ShortArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default Short2DArrayAssert then(short[][] actual)
Creates a new instance of
.Short2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
then
default CharSequenceAssert then(CharSequence actual)
Creates a new instance of
.CharSequenceAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default CharSequenceAssert then(StringBuilder actual)
Creates a new instance of
from aCharSequenceAssert
StringBuilder
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
default CharSequenceAssert then(StringBuffer actual)
Creates a new instance of
from aCharSequenceAssert
StringBuffer
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
default StringAssert then(String actual)
Creates a new instance of
.StringAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default DateAssert then(Date actual)
Creates a new instance of
.DateAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
default AtomicBooleanAssert then(AtomicBoolean actual)
Create assertion forAtomicBoolean
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default AtomicIntegerAssert then(AtomicInteger actual)
Create assertion forAtomicInteger
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default AtomicIntegerArrayAssert then(AtomicIntegerArray actual)
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
default AtomicLongAssert then(AtomicLong actual)
Create assertion forAtomicLong
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default AtomicLongArrayAssert then(AtomicLongArray actual)
Create assertion forAtomicLongArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
default <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> then(AtomicLongFieldUpdater<OBJECT> actual)
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
default <VALUE> AtomicReferenceAssert<VALUE> then(AtomicReference<VALUE> actual)
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
default <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> then(AtomicReferenceArray<ELEMENT> actual)
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
default <VALUE> AtomicMarkableReferenceAssert<VALUE> then(AtomicMarkableReference<VALUE> actual)
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
default <VALUE> AtomicStampedReferenceAssert<VALUE> then(AtomicStampedReference<VALUE> actual)
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
default ThrowableAssert then(Throwable actual)
Creates a new instance of
.ThrowableAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion Throwable.
-
thenThrownBy
default ThrowableAssert thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Allows to capture and then assert on aThrowable
more 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.ThrowingCallable
does 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.ThrowingCallable
or lambda with the code that should raise the throwable.- Returns:
- The captured exception or
null
if none was raised by the callable.
-
thenThrownBy
default ThrowableAssert thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)
Allows to capture and then assert on aThrowable
likethenThrownBy(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"); }
ThrowingCallable
does 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.ThrowingCallable
or 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 ThrowableAssert thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Allows to capture and then assert on aThrowable
more 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
then
because the java compiler reported it ambiguous when used directly with a lambda :(- Parameters:
shouldRaiseOrNotThrowable
- TheThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.- Returns:
- The captured exception or
null
if none was raised by the callable. - Since:
- 3.7.0
-
thenObject
default <T> ObjectAssert<T> thenObject(T actual)
Creates a new instance of
for any object.ObjectAssert
This 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
default UriAssert then(URI actual)
Creates a new instance of
.UriAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
-