public class Java6AbstractStandardSoftAssertions extends AbstractSoftAssertions
AbstractStandardSoftAssertions
.AbstractStandardSoftAssertions
AbstractSoftAssertions.ThrowingRunnable
proxies
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 and Description |
---|
Java6AbstractStandardSoftAssertions() |
Modifier and Type | Method and Description |
---|---|
AtomicBooleanAssert |
assertThat(java.util.concurrent.atomic.AtomicBoolean actual)
Create assertion for
AtomicBoolean . |
AtomicIntegerAssert |
assertThat(java.util.concurrent.atomic.AtomicInteger actual)
Create assertion for
AtomicInteger . |
AtomicIntegerArrayAssert |
assertThat(java.util.concurrent.atomic.AtomicIntegerArray actual)
Create assertion for
AtomicIntegerArray . |
<OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> |
assertThat(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<OBJECT> actual)
Create assertion for
AtomicIntegerFieldUpdater . |
AtomicLongAssert |
assertThat(java.util.concurrent.atomic.AtomicLong actual)
Create assertion for
AtomicLong . |
AtomicLongArrayAssert |
assertThat(java.util.concurrent.atomic.AtomicLongArray actual)
Create assertion for
AtomicLongArray . |
<OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> |
assertThat(java.util.concurrent.atomic.AtomicLongFieldUpdater<OBJECT> actual)
Create assertion for
AtomicLongFieldUpdater . |
<VALUE> AtomicMarkableReferenceAssert<VALUE> |
assertThat(java.util.concurrent.atomic.AtomicMarkableReference<VALUE> actual)
Create assertion for
AtomicMarkableReference . |
<VALUE> AtomicReferenceAssert<VALUE> |
assertThat(java.util.concurrent.atomic.AtomicReference<VALUE> actual)
Create assertion for
AtomicReference . |
<ELEMENT> AtomicReferenceArrayAssert<ELEMENT> |
assertThat(java.util.concurrent.atomic.AtomicReferenceArray<ELEMENT> actual)
Create assertion for
AtomicReferenceArray . |
<FIELD,OBJECT> |
assertThat(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Create assertion for
AtomicReferenceFieldUpdater . |
<VALUE> AtomicStampedReferenceAssert<VALUE> |
assertThat(java.util.concurrent.atomic.AtomicStampedReference<VALUE> actual)
Create assertion for
AtomicStampedReference . |
BigDecimalAssert |
assertThat(java.math.BigDecimal actual)
Creates a new instance of
. |
BigIntegerAssert |
assertThat(java.math.BigInteger actual)
Creates a new instance of
. |
BooleanAssert |
assertThat(boolean actual)
Creates a new instance of
. |
BooleanAssert |
assertThat(java.lang.Boolean actual)
Creates a new instance of
. |
BooleanArrayAssert |
assertThat(boolean[] actual)
Creates a new instance of
. |
ByteAssert |
assertThat(byte actual)
Creates a new instance of
. |
ByteAssert |
assertThat(java.lang.Byte actual)
Creates a new instance of
. |
ByteArrayAssert |
assertThat(byte[] actual)
Creates a new instance of
. |
CharacterAssert |
assertThat(char actual)
Creates a new instance of
. |
CharArrayAssert |
assertThat(char[] actual)
Creates a new instance of
. |
CharacterAssert |
assertThat(java.lang.Character actual)
Creates a new instance of
. |
CharSequenceAssert |
assertThat(java.lang.CharSequence actual)
Creates a new instance of
. |
ProxyableClassAssert |
assertThat(java.lang.Class<?> actual)
Creates a new instance of
|
DateAssert |
assertThat(java.util.Date actual)
Creates a new instance of
. |
DoubleAssert |
assertThat(double actual)
Creates a new instance of
. |
DoubleAssert |
assertThat(java.lang.Double actual)
Creates a new instance of
. |
DoubleArrayAssert |
assertThat(double[] actual)
Creates a new instance of
. |
FileAssert |
assertThat(java.io.File actual)
Creates a new instance of
. |
FloatAssert |
assertThat(float actual)
Creates a new instance of
. |
FloatAssert |
assertThat(java.lang.Float actual)
Creates a new instance of
. |
FloatArrayAssert |
assertThat(float[] actual)
Creates a new instance of
. |
<RESULT> FutureAssert<RESULT> |
assertThat(java.util.concurrent.Future<RESULT> actual)
Creates a new instance of
. |
InputStreamAssert |
assertThat(java.io.InputStream actual)
Creates a new instance of
. |
IntegerAssert |
assertThat(int actual)
Creates a new instance of
. |
IntArrayAssert |
assertThat(int[] actual)
Creates a new instance of
. |
IntegerAssert |
assertThat(java.lang.Integer actual)
Creates a new instance of
. |
<T> ProxyableIterableAssert<T> |
assertThat(java.lang.Iterable<? extends T> actual)
Creates a new instance of
. |
<T> IteratorAssert<T> |
assertThat(java.util.Iterator<? extends T> actual)
Creates a new instance of
. |
<T> ProxyableListAssert<T> |
assertThat(java.util.List<? extends T> actual)
Creates a new instance of
. |
LongAssert |
assertThat(long actual)
Creates a new instance of
. |
LongAssert |
assertThat(java.lang.Long actual)
Creates a new instance of
. |
LongArrayAssert |
assertThat(long[] actual)
Creates a new instance of
. |
<K,V> ProxyableMapAssert<K,V> |
assertThat(java.util.Map<K,V> actual)
Creates a new instance of
. |
ShortAssert |
assertThat(short actual)
Creates a new instance of
. |
ShortAssert |
assertThat(java.lang.Short actual)
Creates a new instance of
. |
ShortArrayAssert |
assertThat(short[] actual)
Creates a new instance of
. |
StringAssert |
assertThat(java.lang.String actual)
Creates a new instance of
. |
CharSequenceAssert |
assertThat(java.lang.StringBuffer actual)
Creates a new instance of
from a StringBuffer . |
CharSequenceAssert |
assertThat(java.lang.StringBuilder actual)
Creates a new instance of
from a StringBuilder . |
<T> ProxyableObjectAssert<T> |
assertThat(T actual)
Creates a new instance of
. |
<T extends java.lang.Comparable<? super T>> |
assertThat(T actual)
Creates a new instance of
with
standard comparison semantics. |
<T> ProxyableObjectArrayAssert<T> |
assertThat(T[] actual)
Creates a new instance of
. |
ThrowableAssert |
assertThat(java.lang.Throwable actual)
Creates a new instance of
. |
UriAssert |
assertThat(java.net.URI actual)
Creates a new instance of
. |
AbstractUrlAssert<?> |
assertThat(java.net.URL actual)
Creates a new instance of
. |
AbstractThrowableAssert<?,? extends java.lang.Throwable> |
assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Allows to capture and then assert on a
Throwable more easily when used with Java 8 lambdas. |
<T> ProxyableObjectAssert<T> |
assertThatObject(T actual)
Creates a new instance of
for any object. |
AbstractThrowableAssert<?,? extends java.lang.Throwable> |
assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Allows to capture and then assert on a
Throwable more easily when used with Java 8 lambdas. |
AbstractThrowableAssert<?,? extends java.lang.Throwable> |
assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable,
java.lang.String description,
java.lang.Object... args)
Allows to capture and then assert on a
Throwable like assertThatThrownBy(ThrowingCallable) but this method
let you set the assertion description the same way you do with as(String, Object...) . |
check, decorateErrorsCollected, errorsCollected, fail, fail, fail, failBecauseExceptionWasNotThrown, proxy, shouldHaveThrown, wasSuccess
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
array, atomicIntegerFieldUpdater, atomicLongFieldUpdater, atomicMarkableReference, atomicReference, atomicReferenceArray, atomicReferenceFieldUpdater, atomicStampedReference, comparable, completableFuture, completionStage, future, iterable, iterator, list, map, optional, predicate, stream, type
public BigDecimalAssert assertThat(java.math.BigDecimal actual)
BigDecimalAssert
.actual
- the actual value.public BigIntegerAssert assertThat(java.math.BigInteger actual)
BigInteger
.actual
- the actual value.public BooleanAssert assertThat(boolean actual)
BooleanAssert
.actual
- the actual value.public BooleanAssert assertThat(java.lang.Boolean actual)
BooleanAssert
.actual
- the actual value.public BooleanArrayAssert assertThat(boolean[] actual)
BooleanArrayAssert
.actual
- the actual value.public ByteAssert assertThat(byte actual)
ByteAssert
.actual
- the actual value.public ByteAssert assertThat(java.lang.Byte actual)
ByteAssert
.actual
- the actual value.public ByteArrayAssert assertThat(byte[] actual)
ByteArrayAssert
.actual
- the actual value.public CharacterAssert assertThat(char actual)
CharacterAssert
.actual
- the actual value.public CharArrayAssert assertThat(char[] actual)
CharArrayAssert
.actual
- the actual value.public CharacterAssert assertThat(java.lang.Character actual)
CharacterAssert
.actual
- the actual value.public ProxyableClassAssert assertThat(java.lang.Class<?> actual)
ClassAssert
We don't return ClassAssert
as it has overridden methods to annotated with SafeVarargs
.
actual
- the actual value.public <T extends java.lang.Comparable<? super T>> AbstractComparableAssert<?,T> assertThat(T actual)
GenericComparableAssert
with
standard comparison semantics.T
- the actual type.actual
- the actual value.public <T> ProxyableIterableAssert<T> assertThat(java.lang.Iterable<? extends T> actual)
IterableAssert
.
We don't return IterableAssert
as it has overridden methods to annotated with SafeVarargs
.
T
- the actual element's type.actual
- the actual value.public <T> IteratorAssert<T> assertThat(java.util.Iterator<? extends T> actual)
IteratorAssert
.
This is a breaking change in version 3.12.0: this method used to return an ProxyableIterableAssert
.
T
- the actual element's type.actual
- the actual value.public DoubleAssert assertThat(double actual)
DoubleAssert
.actual
- the actual value.public DoubleAssert assertThat(java.lang.Double actual)
DoubleAssert
.actual
- the actual value.public DoubleArrayAssert assertThat(double[] actual)
DoubleArrayAssert
.actual
- the actual value.public FileAssert assertThat(java.io.File actual)
FileAssert
.actual
- the actual value.public <RESULT> FutureAssert<RESULT> assertThat(java.util.concurrent.Future<RESULT> actual)
FutureAssert
.RESULT
- the Future
element type.actual
- the actual valuepublic InputStreamAssert assertThat(java.io.InputStream actual)
InputStreamAssert
.actual
- the actual value.public FloatAssert assertThat(float actual)
FloatAssert
.actual
- the actual value.public FloatAssert assertThat(java.lang.Float actual)
FloatAssert
.actual
- the actual value.public FloatArrayAssert assertThat(float[] actual)
FloatArrayAssert
.actual
- the actual value.public IntegerAssert assertThat(int actual)
IntegerAssert
.actual
- the actual value.public IntArrayAssert assertThat(int[] actual)
IntArrayAssert
.actual
- the actual value.public IntegerAssert assertThat(java.lang.Integer actual)
IntegerAssert
.actual
- the actual value.public <T> ProxyableListAssert<T> assertThat(java.util.List<? extends T> actual)
ListAssert
.
We don't return IterableAssert
as it has overridden methods to annotated with SafeVarargs
.
T
- the actual element's type.actual
- the actual value.public LongAssert assertThat(long actual)
LongAssert
.actual
- the actual value.public LongAssert assertThat(java.lang.Long actual)
LongAssert
.actual
- the actual value.public LongArrayAssert assertThat(long[] actual)
LongArrayAssert
.actual
- the actual value.public <T> ProxyableObjectAssert<T> assertThat(T actual)
ObjectAssert
.T
- the type of the actual value.actual
- the actual value.public <T> ProxyableObjectArrayAssert<T> assertThat(T[] actual)
ObjectArrayAssert
.T
- the type values of the actual array.actual
- the actual value.public <K,V> ProxyableMapAssert<K,V> assertThat(java.util.Map<K,V> actual)
MapAssert
.
We don't return MapAssert
as it has overridden methods to annotated with SafeVarargs
.
K
- the type of keys in the map.V
- the type of values in the map.actual
- the actual value.public ShortAssert assertThat(short actual)
ShortAssert
.actual
- the actual value.public ShortAssert assertThat(java.lang.Short actual)
ShortAssert
.actual
- the actual value.public ShortArrayAssert assertThat(short[] actual)
ShortArrayAssert
.actual
- the actual value.public CharSequenceAssert assertThat(java.lang.CharSequence actual)
CharSequenceAssert
.actual
- the actual value.public CharSequenceAssert assertThat(java.lang.StringBuilder actual)
CharSequenceAssert
from a StringBuilder
.actual
- the actual value.public CharSequenceAssert assertThat(java.lang.StringBuffer actual)
CharSequenceAssert
from a StringBuffer
.actual
- the actual value.public StringAssert assertThat(java.lang.String actual)
StringAssert
.actual
- the actual value.public DateAssert assertThat(java.util.Date actual)
DateAssert
.actual
- the actual value.public AtomicBooleanAssert assertThat(java.util.concurrent.atomic.AtomicBoolean actual)
AtomicBoolean
.actual
- the actual value.public AtomicIntegerAssert assertThat(java.util.concurrent.atomic.AtomicInteger actual)
AtomicInteger
.actual
- the actual value.public AtomicIntegerArrayAssert assertThat(java.util.concurrent.atomic.AtomicIntegerArray actual)
AtomicIntegerArray
.actual
- the actual value.public <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> assertThat(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<OBJECT> actual)
AtomicIntegerFieldUpdater
.OBJECT
- the type of the object holding the updatable field.actual
- the actual value.public AtomicLongAssert assertThat(java.util.concurrent.atomic.AtomicLong actual)
AtomicLong
.actual
- the actual value.public AtomicLongArrayAssert assertThat(java.util.concurrent.atomic.AtomicLongArray actual)
AtomicLongArray
.actual
- the actual value.public <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> assertThat(java.util.concurrent.atomic.AtomicLongFieldUpdater<OBJECT> actual)
AtomicLongFieldUpdater
.OBJECT
- the type of the object holding the updatable field.actual
- the actual value.public <VALUE> AtomicReferenceAssert<VALUE> assertThat(java.util.concurrent.atomic.AtomicReference<VALUE> actual)
AtomicReference
.VALUE
- the type of object referred to by the AtomicReference
.actual
- the actual value.public <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> assertThat(java.util.concurrent.atomic.AtomicReferenceArray<ELEMENT> actual)
AtomicReferenceArray
.ELEMENT
- the type of object referred to by the AtomicReferenceArray
.actual
- the actual value.public <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> assertThat(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
AtomicReferenceFieldUpdater
.FIELD
- the type of the field which gets updated by the AtomicReferenceFieldUpdater
.OBJECT
- the type of the object holding the updatable field.actual
- the actual value.public <VALUE> AtomicMarkableReferenceAssert<VALUE> assertThat(java.util.concurrent.atomic.AtomicMarkableReference<VALUE> actual)
AtomicMarkableReference
.VALUE
- The type of object referred to by this referenceactual
- the actual value.public <VALUE> AtomicStampedReferenceAssert<VALUE> assertThat(java.util.concurrent.atomic.AtomicStampedReference<VALUE> actual)
AtomicStampedReference
.VALUE
- The type of object referred to by this referenceactual
- the actual value.public ThrowableAssert assertThat(java.lang.Throwable actual)
ThrowableAssert
.actual
- the actual value.public AbstractThrowableAssert<?,? extends java.lang.Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Throwable
more easily when used with Java 8 lambdas.
Java 8 example :
@Test
public void testException() {
SoftAssertions softly = new SoftAssertions();
softly.assertThatThrownBy(() -> { throw new Exception("boom!"); }).isInstanceOf(Exception.class)
.hasMessageContaining("boom");
}
Java 7 example :
SoftAssertions softly = new SoftAssertions();
softly.assertThatThrownBy(new ThrowingCallable() {
@Override
public Void call() throws Exception {
throw new Exception("boom!");
}
}).isInstanceOf(Exception.class)
.hasMessageContaining("boom");
shouldRaiseThrowable
- The ThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.null
if none was raised by the callable.public AbstractThrowableAssert<?,? extends java.lang.Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, java.lang.String description, java.lang.Object... args)
Throwable
like assertThatThrownBy(ThrowingCallable)
but this method
let you set the assertion description the same way you do with as(String, Object...)
.
Example:
@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");
}
If the provided 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.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);
shouldRaiseThrowable
- The ThrowableAssert.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.ThrowableAssert
.public AbstractThrowableAssert<?,? extends java.lang.Throwable> assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Throwable
more easily when used with Java 8 lambdas.
Example :
ThrowingCallable callable = () -> {
throw new Exception("boom!");
};
// assertion succeeds
assertThatCode(callable).isInstanceOf(Exception.class)
.hasMessageContaining("boom");
// assertion fails
assertThatCode(callable).doesNotThrowAnyException();
If the provided ThrowableAssert.ThrowingCallable
does not validate against next assertions, an error is immediately raised,
in that case the test description provided with as(String, Object...)
is not honored.assertThatCode(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 assertThat
because the java compiler reported it ambiguous when used directly with a lambda :(
shouldRaiseOrNotThrowable
- The ThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.null
if none was raised by the callable.public <T> ProxyableObjectAssert<T> assertThatObject(T actual)
ObjectAssert
for any object.
This overload is useful, when an overloaded method of assertThat(...) takes precedence over the generic assertThat(Object)
.
Example:
Cast necessary becauseassertThat(List)
"forgets" actual type:
assertThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));
No cast needed, but also no additional list assertions:
assertThatObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc"));
T
- the type of the actual value.actual
- the actual value.public UriAssert assertThat(java.net.URI actual)
UriAssert
.actual
- the actual value.public AbstractUrlAssert<?> assertThat(java.net.URL actual)
UrlAssert
.actual
- the actual value.