Package org.assertj.core.api
Class Java6AbstractBDDSoftAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractSoftAssertions
-
- org.assertj.core.api.Java6AbstractBDDSoftAssertions
-
- All Implemented Interfaces:
InstanceOfAssertFactories
- Direct Known Subclasses:
AbstractBDDSoftAssertions,Java6BDDSoftAssertions,Java6JUnitBDDSoftAssertions
public class Java6AbstractBDDSoftAssertions extends AbstractSoftAssertions
AbstractBDDSoftAssertions compatible with Android. Duplicated fromAbstractBDDSoftAssertions.- Since:
- 2.5.0 / 3.5.0
- See Also:
AbstractBDDSoftAssertions
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.assertj.core.api.AbstractSoftAssertions
AbstractSoftAssertions.ThrowingRunnable
-
-
Field Summary
-
Fields inherited from class org.assertj.core.api.AbstractSoftAssertions
proxies
-
Fields inherited from interface org.assertj.core.api.InstanceOfAssertFactories
ARRAY, ATOMIC_BOOLEAN, ATOMIC_INTEGER, ATOMIC_INTEGER_ARRAY, ATOMIC_INTEGER_FIELD_UPDATER, ATOMIC_LONG, ATOMIC_LONG_ARRAY, ATOMIC_LONG_FIELD_UPDATER, ATOMIC_MARKABLE_REFERENCE, ATOMIC_REFERENCE, ATOMIC_REFERENCE_ARRAY, ATOMIC_REFERENCE_FIELD_UPDATER, ATOMIC_STAMPED_REFERENCE, BIG_DECIMAL, BIG_INTEGER, BOOLEAN, BOOLEAN_ARRAY, BYTE, BYTE_ARRAY, CHAR_ARRAY, CHAR_SEQUENCE, CHARACTER, CLASS, COMPLETABLE_FUTURE, COMPLETION_STAGE, DATE, DOUBLE, DOUBLE_ARRAY, DOUBLE_PREDICATE, DOUBLE_STREAM, FILE, FLOAT, FLOAT_ARRAY, FUTURE, INPUT_STREAM, INSTANT, INT_ARRAY, INT_PREDICATE, INT_STREAM, INTEGER, ITERABLE, ITERATOR, LIST, LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME, LONG, LONG_ARRAY, LONG_PREDICATE, LONG_STREAM, MAP, OFFSET_DATE_TIME, OFFSET_TIME, OPTIONAL, OPTIONAL_DOUBLE, OPTIONAL_INT, OPTIONAL_LONG, PATH, PREDICATE, SHORT, SHORT_ARRAY, STREAM, STRING, STRING_BUFFER, STRING_BUILDER, THROWABLE, URI_TYPE, URL_TYPE, ZONED_DATE_TIME
-
-
Constructor Summary
Constructors Constructor Description Java6AbstractBDDSoftAssertions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleanAssertthen(boolean actual)Creates a new instance of.BooleanAssertBooleanArrayAssertthen(boolean[] actual)Creates a new instance of.BooleanArrayAssertByteAssertthen(byte actual)Creates a new instance of.ByteAssertByteArrayAssertthen(byte[] actual)Creates a new instance of.ByteArrayAssertCharacterAssertthen(char actual)Creates a new instance of.CharacterAssertCharArrayAssertthen(char[] actual)Creates a new instance of.CharArrayAssertDoubleAssertthen(double actual)Creates a new instance of.DoubleAssertDoubleArrayAssertthen(double[] actual)Creates a new instance of.DoubleArrayAssertFloatAssertthen(float actual)Creates a new instance of.FloatAssertFloatArrayAssertthen(float[] actual)Creates a new instance of.FloatArrayAssertIntegerAssertthen(int actual)Creates a new instance of.IntegerAssertIntArrayAssertthen(int[] actual)Creates a new instance of.IntArrayAssertLongAssertthen(long actual)Creates a new instance of.LongAssertLongArrayAssertthen(long[] actual)Creates a new instance of.LongArrayAssertShortAssertthen(short actual)Creates a new instance of.ShortAssertShortArrayAssertthen(short[] actual)Creates a new instance of.ShortArrayAssertFileAssertthen(File actual)Creates a new instance of.FileAssertInputStreamAssertthen(InputStream actual)Creates a new instance of.InputStreamAssertBooleanAssertthen(Boolean actual)Creates a new instance of.BooleanAssertByteAssertthen(Byte actual)Creates a new instance of.ByteAssertCharacterAssertthen(Character actual)Creates a new instance of.CharacterAssertCharSequenceAssertthen(CharSequence actual)Creates a new instance of.CharSequenceAssertProxyableClassAssertthen(Class<?> actual)Creates a new instance ofClassAssertDoubleAssertthen(Double actual)Creates a new instance of.DoubleAssertFloatAssertthen(Float actual)Creates a new instance of.FloatAssertIntegerAssertthen(Integer actual)Creates a new instance of.IntegerAssert<T> ProxyableIterableAssert<T>then(Iterable<? extends T> actual)Creates a new instance of.IterableAssertLongAssertthen(Long actual)Creates a new instance of.LongAssertShortAssertthen(Short actual)Creates a new instance of.ShortAssertStringAssertthen(String actual)Creates a new instance of.StringAssertCharSequenceAssertthen(StringBuffer actual)Creates a new instance offrom aCharSequenceAssertStringBuffer.CharSequenceAssertthen(StringBuilder actual)Creates a new instance offrom aCharSequenceAssertStringBuilder.ThrowableAssertthen(Throwable actual)Creates a new instance of.ThrowableAssertBigDecimalAssertthen(BigDecimal actual)Creates a new instance of.BigDecimalAssertBigIntegerAssertthen(BigInteger actual)Creates a new instance of.BigIntegerAssertUriAssertthen(URI actual)Creates a new instance of.UriAssertAbstractUrlAssert<?>then(URL actual)Creates a new instance of.UrlAssertAtomicBooleanAssertthen(AtomicBoolean actual)Create assertion forAtomicBoolean.AtomicIntegerAssertthen(AtomicInteger actual)Create assertion forAtomicInteger.AtomicIntegerArrayAssertthen(AtomicIntegerArray actual)Create assertion forAtomicIntegerArray.<OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT>then(AtomicIntegerFieldUpdater<OBJECT> actual)Create assertion forAtomicIntegerFieldUpdater.AtomicLongAssertthen(AtomicLong actual)Create assertion forAtomicLong.AtomicLongArrayAssertthen(AtomicLongArray actual)Create assertion forAtomicLongArray.<OBJECT> AtomicLongFieldUpdaterAssert<OBJECT>then(AtomicLongFieldUpdater<OBJECT> actual)Create assertion forAtomicLongFieldUpdater.<VALUE> AtomicMarkableReferenceAssert<VALUE>then(AtomicMarkableReference<VALUE> actual)Create assertion forAtomicMarkableReference.<VALUE> AtomicReferenceAssert<VALUE>then(AtomicReference<VALUE> actual)Create assertion forAtomicReference.<ELEMENT> AtomicReferenceArrayAssert<ELEMENT>then(AtomicReferenceArray<ELEMENT> actual)Create assertion forAtomicReferenceArray.<FIELD,OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT>then(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)Create assertion forAtomicReferenceFieldUpdater.<VALUE> AtomicStampedReferenceAssert<VALUE>then(AtomicStampedReference<VALUE> actual)Create assertion forAtomicStampedReference.<RESULT> FutureAssert<RESULT>then(Future<RESULT> actual)Creates a new instance of.FutureAssertDateAssertthen(Date actual)Creates a new instance of.DateAssert<T> IteratorAssert<T>then(Iterator<? extends T> actual)Creates a new instance of.IteratorAssert<T> ProxyableListAssert<T>then(List<? extends T> actual)Creates a new instance of.ListAssert<K,V>
ProxyableMapAssert<K,V>then(Map<K,V> actual)Creates a new instance of.MapAssert<T extends Comparable<? super T>>
AbstractComparableAssert<?,T>then(T actual)Creates a new instance ofwith standard comparison semantics.GenericComparableAssert<T> ProxyableObjectArrayAssert<T>then(T[] actual)Creates a new instance of.ObjectArrayAssertAbstractThrowableAssert<?,? extends Throwable>thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.<T> ProxyableObjectAssert<T>thenObject(T actual)Creates a new instance offor any object.ObjectAssertAbstractThrowableAssert<?,? extends Throwable>thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.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 class org.assertj.core.api.AbstractSoftAssertions
check, decorateErrorsCollected, errorsCollected, fail, fail, fail, failBecauseExceptionWasNotThrown, proxy, shouldHaveThrown, wasSuccess
-
-
-
-
Method Detail
-
then
public BigDecimalAssert then(BigDecimal actual)
Creates a new instance of.BigDecimalAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public 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
public BooleanAssert then(boolean actual)
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public BooleanAssert then(Boolean actual)
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public BooleanArrayAssert then(boolean[] actual)
Creates a new instance of.BooleanArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ByteAssert then(byte actual)
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ByteAssert then(Byte actual)
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ByteArrayAssert then(byte[] actual)
Creates a new instance of.ByteArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public CharacterAssert then(char actual)
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public CharArrayAssert then(char[] actual)
Creates a new instance of.CharArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public CharacterAssert then(Character actual)
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ProxyableClassAssert then(Class<?> actual)
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
public <T extends Comparable<? super T>> AbstractComparableAssert<?,T> then(T actual)
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.
-
then
public <T> ProxyableIterableAssert<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
public <T> IteratorAssert<T> then(Iterator<? extends T> actual)
Creates a new instance of.IteratorAssertThis is a breaking change in version 3.12.0: this method used to return an
ProxyableIterableAssert.- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public DoubleAssert then(double actual)
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public DoubleAssert then(Double actual)
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public DoubleArrayAssert then(double[] actual)
Creates a new instance of.DoubleArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public FileAssert then(File actual)
Creates a new instance of.FileAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public <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
public InputStreamAssert then(InputStream actual)
Creates a new instance of.InputStreamAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public FloatAssert then(float actual)
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public FloatAssert then(Float actual)
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public FloatArrayAssert then(float[] actual)
Creates a new instance of.FloatArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public IntegerAssert then(int actual)
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public IntArrayAssert then(int[] actual)
Creates a new instance of.IntArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public IntegerAssert then(Integer actual)
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public <T> ProxyableListAssert<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
public LongAssert then(long actual)
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public LongAssert then(Long actual)
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public LongArrayAssert then(long[] actual)
Creates a new instance of.LongArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public <T> ProxyableObjectAssert<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
public <T> ProxyableObjectArrayAssert<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
public <K,V> ProxyableMapAssert<K,V> then(Map<K,V> actual)
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
public ShortAssert then(short actual)
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ShortAssert then(Short actual)
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public ShortArrayAssert then(short[] actual)
Creates a new instance of.ShortArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public CharSequenceAssert then(CharSequence actual)
Creates a new instance of.CharSequenceAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public CharSequenceAssert then(StringBuilder actual)
Creates a new instance offrom aCharSequenceAssertStringBuilder.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
public CharSequenceAssert then(StringBuffer actual)
Creates a new instance offrom aCharSequenceAssertStringBuffer.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
then
public StringAssert then(String actual)
Creates a new instance of.StringAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public DateAssert then(Date actual)
Creates a new instance of.DateAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public 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
public 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
public 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
public <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
public 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
public 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
public <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
public <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
public <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
public <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
public <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
public <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
public ThrowableAssert then(Throwable actual)
Creates a new instance of.ThrowableAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion Throwable.
-
thenThrownBy
public 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 public 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 public 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
public 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 public 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
public 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
public <T> ProxyableObjectAssert<T> thenObject(T actual)
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
public UriAssert then(URI actual)
Creates a new instance of.UriAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
then
public AbstractUrlAssert<?> then(URL actual)
Creates a new instance of.UrlAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
-