Class Java6AbstractStandardSoftAssertions
- java.lang.Object
-
- org.assertj.core.api.AbstractSoftAssertions
-
- org.assertj.core.api.Java6AbstractStandardSoftAssertions
-
- All Implemented Interfaces:
InstanceOfAssertFactories
- Direct Known Subclasses:
AbstractStandardSoftAssertions,Java6JUnitSoftAssertions,Java6SoftAssertions
public class Java6AbstractStandardSoftAssertions extends AbstractSoftAssertions
AbstractStandardSoftAssertions compatible with Android. Duplicated fromAbstractStandardSoftAssertions.- Since:
- 2.5.0 / 3.5.0
- See Also:
AbstractStandardSoftAssertions
-
-
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 Java6AbstractStandardSoftAssertions()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleanAssertassertThat(boolean actual)Creates a new instance of.BooleanAssertBooleanArrayAssertassertThat(boolean[] actual)Creates a new instance of.BooleanArrayAssertByteAssertassertThat(byte actual)Creates a new instance of.ByteAssertByteArrayAssertassertThat(byte[] actual)Creates a new instance of.ByteArrayAssertCharacterAssertassertThat(char actual)Creates a new instance of.CharacterAssertCharArrayAssertassertThat(char[] actual)Creates a new instance of.CharArrayAssertDoubleAssertassertThat(double actual)Creates a new instance of.DoubleAssertDoubleArrayAssertassertThat(double[] actual)Creates a new instance of.DoubleArrayAssertFloatAssertassertThat(float actual)Creates a new instance of.FloatAssertFloatArrayAssertassertThat(float[] actual)Creates a new instance of.FloatArrayAssertIntegerAssertassertThat(int actual)Creates a new instance of.IntegerAssertIntArrayAssertassertThat(int[] actual)Creates a new instance of.IntArrayAssertLongAssertassertThat(long actual)Creates a new instance of.LongAssertLongArrayAssertassertThat(long[] actual)Creates a new instance of.LongArrayAssertShortAssertassertThat(short actual)Creates a new instance of.ShortAssertShortArrayAssertassertThat(short[] actual)Creates a new instance of.ShortArrayAssertFileAssertassertThat(File actual)Creates a new instance of.FileAssertInputStreamAssertassertThat(InputStream actual)Creates a new instance of.InputStreamAssertBooleanAssertassertThat(Boolean actual)Creates a new instance of.BooleanAssertByteAssertassertThat(Byte actual)Creates a new instance of.ByteAssertCharacterAssertassertThat(Character actual)Creates a new instance of.CharacterAssertCharSequenceAssertassertThat(CharSequence actual)Creates a new instance of.CharSequenceAssertProxyableClassAssertassertThat(Class<?> actual)Creates a new instance ofClassAssertDoubleAssertassertThat(Double actual)Creates a new instance of.DoubleAssertFloatAssertassertThat(Float actual)Creates a new instance of.FloatAssertIntegerAssertassertThat(Integer actual)Creates a new instance of.IntegerAssert<T> ProxyableIterableAssert<T>assertThat(Iterable<? extends T> actual)Creates a new instance of.IterableAssertLongAssertassertThat(Long actual)Creates a new instance of.LongAssertShortAssertassertThat(Short actual)Creates a new instance of.ShortAssertStringAssertassertThat(String actual)Creates a new instance of.StringAssertCharSequenceAssertassertThat(StringBuffer actual)Creates a new instance offrom aCharSequenceAssertStringBuffer.CharSequenceAssertassertThat(StringBuilder actual)Creates a new instance offrom aCharSequenceAssertStringBuilder.ThrowableAssertassertThat(Throwable actual)Creates a new instance of.ThrowableAssertBigDecimalAssertassertThat(BigDecimal actual)Creates a new instance of.BigDecimalAssertBigIntegerAssertassertThat(BigInteger actual)Creates a new instance of.BigIntegerUriAssertassertThat(URI actual)Creates a new instance of.UriAssertAbstractUrlAssert<?>assertThat(URL actual)Creates a new instance of.UrlAssertAtomicBooleanAssertassertThat(AtomicBoolean actual)Create assertion forAtomicBoolean.AtomicIntegerAssertassertThat(AtomicInteger actual)Create assertion forAtomicInteger.AtomicIntegerArrayAssertassertThat(AtomicIntegerArray actual)Create assertion forAtomicIntegerArray.<OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT>assertThat(AtomicIntegerFieldUpdater<OBJECT> actual)Create assertion forAtomicIntegerFieldUpdater.AtomicLongAssertassertThat(AtomicLong actual)Create assertion forAtomicLong.AtomicLongArrayAssertassertThat(AtomicLongArray actual)Create assertion forAtomicLongArray.<OBJECT> AtomicLongFieldUpdaterAssert<OBJECT>assertThat(AtomicLongFieldUpdater<OBJECT> actual)Create assertion forAtomicLongFieldUpdater.<VALUE> AtomicMarkableReferenceAssert<VALUE>assertThat(AtomicMarkableReference<VALUE> actual)Create assertion forAtomicMarkableReference.<VALUE> AtomicReferenceAssert<VALUE>assertThat(AtomicReference<VALUE> actual)Create assertion forAtomicReference.<ELEMENT> AtomicReferenceArrayAssert<ELEMENT>assertThat(AtomicReferenceArray<ELEMENT> actual)Create assertion forAtomicReferenceArray.<FIELD,OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT>assertThat(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)Create assertion forAtomicReferenceFieldUpdater.<VALUE> AtomicStampedReferenceAssert<VALUE>assertThat(AtomicStampedReference<VALUE> actual)Create assertion forAtomicStampedReference.<RESULT> FutureAssert<RESULT>assertThat(Future<RESULT> actual)Creates a new instance of.FutureAssertDateAssertassertThat(Date actual)Creates a new instance of.DateAssert<T> IteratorAssert<T>assertThat(Iterator<? extends T> actual)Creates a new instance of.IteratorAssert<T> ProxyableListAssert<T>assertThat(List<? extends T> actual)Creates a new instance of.ListAssert<K,V>
ProxyableMapAssert<K,V>assertThat(Map<K,V> actual)Creates a new instance of.MapAssert<T extends Comparable<? super T>>
AbstractComparableAssert<?,T>assertThat(T actual)Creates a new instance ofwith standard comparison semantics.GenericComparableAssert<T> ProxyableObjectArrayAssert<T>assertThat(T[] actual)Creates a new instance of.ObjectArrayAssertAbstractThrowableAssert<?,? extends Throwable>assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.<T> ProxyableObjectAssert<T>assertThatObject(T actual)Creates a new instance offor any object.ObjectAssertAbstractThrowableAssert<?,? extends Throwable>assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.AbstractThrowableAssert<?,? extends Throwable>assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)Allows to capture and then assert on aThrowablelikeassertThatThrownBy(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
-
assertThat
public BigDecimalAssert assertThat(BigDecimal actual)
Creates a new instance of.BigDecimalAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public BigIntegerAssert assertThat(BigInteger actual)
Creates a new instance of.BigInteger- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public BooleanAssert assertThat(boolean actual)
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public BooleanAssert assertThat(Boolean actual)
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public BooleanArrayAssert assertThat(boolean[] actual)
Creates a new instance of.BooleanArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ByteAssert assertThat(byte actual)
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ByteAssert assertThat(Byte actual)
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ByteArrayAssert assertThat(byte[] actual)
Creates a new instance of.ByteArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public CharacterAssert assertThat(char actual)
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public CharArrayAssert assertThat(char[] actual)
Creates a new instance of.CharArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public CharacterAssert assertThat(Character actual)
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ProxyableClassAssert assertThat(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.
-
assertThat
public <T extends Comparable<? super T>> AbstractComparableAssert<?,T> assertThat(T actual)
Creates a new instance ofwith standard comparison semantics.GenericComparableAssert- Type Parameters:
T- the actual type.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <T> ProxyableIterableAssert<T> assertThat(Iterable<? extends T> actual)
Creates a new instance of.IterableAssertWe don't return
IterableAssertas it has overridden methods to annotated withSafeVarargs.- Type Parameters:
T- the actual element's type.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <T> IteratorAssert<T> assertThat(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 actual element's type.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public DoubleAssert assertThat(double actual)
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public DoubleAssert assertThat(Double actual)
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public DoubleArrayAssert assertThat(double[] actual)
Creates a new instance of.DoubleArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public FileAssert assertThat(File actual)
Creates a new instance of.FileAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <RESULT> FutureAssert<RESULT> assertThat(Future<RESULT> actual)
Creates a new instance of.FutureAssert- Type Parameters:
RESULT- theFutureelement type.- Parameters:
actual- the actual value- Returns:
- the created assertion object
-
assertThat
public InputStreamAssert assertThat(InputStream actual)
Creates a new instance of.InputStreamAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public FloatAssert assertThat(float actual)
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public FloatAssert assertThat(Float actual)
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public FloatArrayAssert assertThat(float[] actual)
Creates a new instance of.FloatArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public IntegerAssert assertThat(int actual)
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public IntArrayAssert assertThat(int[] actual)
Creates a new instance of.IntArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public IntegerAssert assertThat(Integer actual)
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <T> ProxyableListAssert<T> assertThat(List<? extends T> actual)
Creates a new instance of.ListAssertWe don't return
IterableAssertas it has overridden methods to annotated withSafeVarargs.- Type Parameters:
T- the actual element's type.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public LongAssert assertThat(long actual)
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public LongAssert assertThat(Long actual)
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public LongArrayAssert assertThat(long[] actual)
Creates a new instance of.LongArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <T> ProxyableObjectAssert<T> assertThat(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.
-
assertThat
public <T> ProxyableObjectArrayAssert<T> assertThat(T[] actual)
Creates a new instance of.ObjectArrayAssert- Type Parameters:
T- the type values of the actual array.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <K,V> ProxyableMapAssert<K,V> assertThat(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.
-
assertThat
public ShortAssert assertThat(short actual)
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ShortAssert assertThat(Short actual)
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ShortArrayAssert assertThat(short[] actual)
Creates a new instance of.ShortArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public CharSequenceAssert assertThat(CharSequence actual)
Creates a new instance of.CharSequenceAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public CharSequenceAssert assertThat(StringBuilder actual)
Creates a new instance offrom aCharSequenceAssertStringBuilder.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
assertThat
public CharSequenceAssert assertThat(StringBuffer actual)
Creates a new instance offrom aCharSequenceAssertStringBuffer.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
assertThat
public StringAssert assertThat(String actual)
Creates a new instance of.StringAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public DateAssert assertThat(Date actual)
Creates a new instance of.DateAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public AtomicBooleanAssert assertThat(AtomicBoolean actual)
Create assertion forAtomicBoolean.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public AtomicIntegerAssert assertThat(AtomicInteger actual)
Create assertion forAtomicInteger.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public AtomicIntegerArrayAssert assertThat(AtomicIntegerArray actual)
Create assertion forAtomicIntegerArray.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> assertThat(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.
-
assertThat
public AtomicLongAssert assertThat(AtomicLong actual)
Create assertion forAtomicLong.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public AtomicLongArrayAssert assertThat(AtomicLongArray actual)
Create assertion forAtomicLongArray.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> assertThat(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.
-
assertThat
public <VALUE> AtomicReferenceAssert<VALUE> assertThat(AtomicReference<VALUE> actual)
Create assertion forAtomicReference.- Type Parameters:
VALUE- the type of object referred to by theAtomicReference.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> assertThat(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.
-
assertThat
public <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> assertThat(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Create assertion forAtomicReferenceFieldUpdater.- Type Parameters:
FIELD- the type of the field which gets updated by theAtomicReferenceFieldUpdater.OBJECT- the type of the object holding the updatable field.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public <VALUE> AtomicMarkableReferenceAssert<VALUE> assertThat(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.
-
assertThat
public <VALUE> AtomicStampedReferenceAssert<VALUE> assertThat(AtomicStampedReference<VALUE> actual)
Create assertion forAtomicStampedReference.- Type Parameters:
VALUE- The type of object referred to by this reference- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public ThrowableAssert assertThat(Throwable actual)
Creates a new instance of.ThrowableAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion Throwable.
-
assertThatThrownBy
public AbstractThrowableAssert<?,? extends Throwable> assertThatThrownBy(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() { SoftAssertions softly = new SoftAssertions(); softly.assertThatThrownBy(() -> { throw new Exception("boom!"); }).isInstanceOf(Exception.class) .hasMessageContaining("boom"); }SoftAssertions softly = new SoftAssertions(); softly.assertThatThrownBy(new ThrowingCallable() { @Override public Void call() throws Exception { throw new Exception("boom!"); } }).isInstanceOf(Exception.class) .hasMessageContaining("boom");- 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.
-
assertThatThrownBy
public AbstractThrowableAssert<?,? extends Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)
Allows to capture and then assert on aThrowablelikeassertThatThrownBy(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() { SoftAssertions softly = new SoftAssertions(); // if this assertion failed (but it doesn't), the error message would start with [Test explosive code] softly.assertThatThrownBy(() -> { 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.assertThatThrownBy(() -> {}).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error message softly.assertThatThrownBy(() -> {}, "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
-
assertThatCode
public AbstractThrowableAssert<?,? extends Throwable> assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Allows to capture and then assert on aThrowablemore easily when used with Java 8 lambdas.Example :
If the providedThrowingCallable callable = () -> { throw new Exception("boom!"); }; // assertion succeeds assertThatCode(callable).isInstanceOf(Exception.class) .hasMessageContaining("boom"); // assertion fails assertThatCode(callable).doesNotThrowAnyException();ThrowableAssert.ThrowingCallabledoes not validate against next assertions, an error is immediately raised, in that case the test description provided withas(String, Object...)is not honored.
To use a test description, useassertThatCode(ThrowableAssert.ThrowingCallable)as shown below.ThrowingCallable doNothing = () -> { // do nothing }; // assertion fails and "display me" appears in the assertion error assertThatCode(doNothing).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error Throwable thrown = catchThrowable(doNothing); assertThatCode(thrown).as("display me") .isInstanceOf(Exception.class);This method was not named
assertThatbecause 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
-
assertThatObject
public <T> ProxyableObjectAssert<T> assertThatObject(T actual)
Creates a new instance offor any object.ObjectAssertThis overload is useful, when an overloaded method of assertThat(...) takes precedence over the generic
assertThat(Object).Example:
Cast necessary becauseassertThat(List)"forgets" actual type:
No cast needed, but also no additional list assertions:assertThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));assertThatObject(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
-
assertThat
public UriAssert assertThat(URI actual)
Creates a new instance of.UriAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
public AbstractUrlAssert<?> assertThat(URL actual)
Creates a new instance of.UrlAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
-