public class BDDAssertions extends Assertions
The difference with the Assertions
class is that entry point methods are named then
instead of
assertThat
.
For example:
@Test
public void bdd_assertions_example() {
//given
List<BasketBallPlayer> bulls = new ArrayList<>();
//when
bulls.add(rose);
bulls.add(noah);
then(bulls).contains(rose, noah).doesNotContain(james);
}
Modifier | Constructor and Description |
---|---|
protected |
BDDAssertions()
Creates a new
BDDAssertions . |
Modifier and Type | Method and Description |
---|---|
static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> |
then(ACTUAL actual,
Class<ELEMENT_ASSERT> assertClass)
Creates a new instance of
allowing to navigate to any Iterable element
in order to perform assertions on it. |
static <T> T |
then(AssertProvider<T> component)
Delegates the creation of the
Assert to the AssertProvider.assertThat() of the given component. |
static AtomicBooleanAssert |
then(AtomicBoolean actual)
Create assertion for
AtomicBoolean . |
static AtomicIntegerAssert |
then(AtomicInteger actual)
Create assertion for
AtomicInteger . |
static AtomicIntegerArrayAssert |
then(AtomicIntegerArray actual)
Create assertion for
AtomicIntegerArray . |
static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> |
then(AtomicIntegerFieldUpdater<OBJECT> actual)
Create assertion for
AtomicIntegerFieldUpdater . |
static AtomicLongAssert |
then(AtomicLong actual)
Create assertion for
AtomicLong . |
static AtomicLongArrayAssert |
then(AtomicLongArray actual)
Create assertion for
AtomicLongArray . |
static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> |
then(AtomicLongFieldUpdater<OBJECT> actual)
Create assertion for
AtomicLongFieldUpdater . |
static <VALUE> AtomicMarkableReferenceAssert<VALUE> |
then(AtomicMarkableReference<VALUE> actual)
Create assertion for
AtomicMarkableReference . |
static <VALUE> AtomicReferenceAssert<VALUE> |
then(AtomicReference<VALUE> actual)
Create assertion for
AtomicReference . |
static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> |
then(AtomicReferenceArray<ELEMENT> actual)
Create assertion for
AtomicReferenceArray . |
static <FIELD,OBJECT> |
then(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Create assertion for
AtomicReferenceFieldUpdater . |
static <VALUE> AtomicStampedReferenceAssert<VALUE> |
then(AtomicStampedReference<VALUE> actual)
Create assertion for
AtomicStampedReference . |
static <ELEMENT,STREAM extends BaseStream<ELEMENT,STREAM>> |
then(BaseStream<? extends ELEMENT,STREAM> actual)
Creates a new instance of
from the given BaseStream . |
static AbstractBigDecimalAssert<?> |
then(BigDecimal actual)
Creates a new instance of
. |
static AbstractBigIntegerAssert<?> |
then(BigInteger actual)
Creates a new instance of
. |
static AbstractBooleanAssert<?> |
then(boolean actual)
Creates a new instance of
. |
static AbstractBooleanAssert<?> |
then(Boolean actual)
Creates a new instance of
. |
static AbstractBooleanArrayAssert<?> |
then(boolean[] actual)
Creates a new instance of
. |
static AbstractByteAssert<?> |
then(byte actual)
Creates a new instance of
. |
static AbstractByteAssert<?> |
then(Byte actual)
Creates a new instance of
. |
static AbstractByteArrayAssert<?> |
then(byte[] actual)
Creates a new instance of
. |
static AbstractCharacterAssert<?> |
then(char actual)
Creates a new instance of
. |
static AbstractCharArrayAssert<?> |
then(char[] actual)
Creates a new instance of
. |
static AbstractCharacterAssert<?> |
then(Character actual)
Creates a new instance of
. |
static AbstractCharSequenceAssert<?,? extends CharSequence> |
then(CharSequence actual)
Creates a new instance of
. |
static AbstractClassAssert<?> |
then(Class<?> actual)
Creates a new instance of
|
static <RESULT> CompletableFutureAssert<RESULT> |
then(CompletableFuture<RESULT> future)
Create assertion for
CompletableFuture . |
static AbstractDateAssert<?> |
then(Date actual)
Creates a new instance of
. |
static AbstractDoubleAssert<?> |
then(double actual)
Creates a new instance of
. |
static AbstractDoubleAssert<?> |
then(Double actual)
Creates a new instance of
. |
static AbstractDoubleArrayAssert<?> |
then(double[] actual)
Creates a new instance of
. |
static DoublePredicateAssert |
then(DoublePredicate actual)
Create assertion for
DoublePredicate . |
static AbstractFileAssert<?> |
then(File actual)
Creates a new instance of
. |
static AbstractFloatAssert<?> |
then(float actual)
Creates a new instance of
. |
static AbstractFloatAssert<?> |
then(Float actual)
Creates a new instance of
. |
static AbstractFloatArrayAssert<?> |
then(float[] actual)
Creates a new instance of
. |
static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> |
then(Future<RESULT> actual)
Creates a new instance of
FutureAssert |
static AbstractInputStreamAssert<?,? extends InputStream> |
then(InputStream actual)
Creates a new instance of
. |
static AbstractInstantAssert<?> |
then(Instant actual)
Creates a new instance of
. |
static AbstractIntegerAssert<?> |
then(int actual)
Creates a new instance of
. |
static AbstractIntArrayAssert<?> |
then(int[] actual)
Creates a new instance of
. |
static AbstractIntegerAssert<?> |
then(Integer actual)
Creates a new instance of
. |
static IntPredicateAssert |
then(IntPredicate actual)
Create assertion for
IntPredicate . |
static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> |
then(Iterable<? extends ELEMENT> actual,
AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Creates a new instance of
allowing to navigate to any Iterable element
in order to perform assertions on it. |
static <T> IterableAssert<T> |
then(Iterable<? extends T> actual)
Creates a new instance of
. |
static <T> IterableAssert<T> |
then(Iterator<? extends T> actual)
Creates a new instance of
. |
static <ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> |
then(List<? extends ELEMENT> actual,
AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Creates a new instance of
allowing to navigate to any List element
in order to perform assertions on it. |
static <ELEMENT,ACTUAL extends List<? extends ELEMENT>,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> |
then(List<? extends ELEMENT> actual,
Class<ELEMENT_ASSERT> assertClass)
Creates a new instance of
tallowing to navigate to any List element
in order to perform assertions on it. |
static <T> ListAssert<T> |
then(List<? extends T> actual)
Creates a new instance of
. |
static AbstractLocalDateAssert<?> |
then(LocalDate actual)
Creates a new instance of
. |
static AbstractLocalDateTimeAssert<?> |
then(LocalDateTime actual)
Creates a new instance of
. |
static AbstractLocalTimeAssert<?> |
then(LocalTime actual)
Creates a new instance of
. |
static AbstractLongAssert<?> |
then(long actual)
Creates a new instance of
. |
static AbstractLongAssert<?> |
then(Long actual)
Creates a new instance of
. |
static AbstractLongArrayAssert<?> |
then(long[] actual)
Creates a new instance of
. |
static LongPredicateAssert |
then(LongPredicate actual)
Create assertion for
LongPredicate . |
static <K,V> MapAssert<K,V> |
then(Map<K,V> actual)
Creates a new instance of
. |
static AbstractOffsetDateTimeAssert<?> |
then(OffsetDateTime actual)
Creates a new instance of
. |
static AbstractOffsetTimeAssert<?> |
then(OffsetTime actual)
Creates a new instance of
. |
static <VALUE> OptionalAssert<VALUE> |
then(Optional<VALUE> optional)
Create assertion for
Optional . |
static OptionalDoubleAssert |
then(OptionalDouble optional)
Create assertion for
OptionalDouble . |
static OptionalIntAssert |
then(OptionalInt optional)
Create assertion for
OptionalInt . |
static OptionalLongAssert |
then(OptionalLong optional)
Create assertion for
OptionalLong . |
static AbstractPathAssert<?> |
then(Path actual)
Creates a new instance of
PathAssert |
static <T> PredicateAssert<T> |
then(Predicate<T> actual)
Create assertion for
Predicate . |
static AbstractShortAssert<?> |
then(short actual)
Creates a new instance of
. |
static AbstractShortAssert<?> |
then(Short actual)
Creates a new instance of
. |
static AbstractShortArrayAssert<?> |
then(short[] actual)
Creates a new instance of
. |
static AbstractCharSequenceAssert<?,String> |
then(String actual)
Creates a new instance of
. |
static <T> AbstractObjectAssert<?,T> |
then(T actual)
Creates a new instance of
. |
static <T extends Comparable<? super T>> |
then(T actual)
Creates a new instance of
with
standard comparison semantics. |
static <T extends AssertDelegateTarget> |
then(T assertion)
Returns the given assertion.
|
static <T> AbstractObjectArrayAssert<?,T> |
then(T[] actual)
Creates a new instance of
. |
static AbstractThrowableAssert<?,? extends Throwable> |
then(Throwable actual)
Creates a new instance of
. |
static AbstractUriAssert<?> |
then(URI actual)
Creates a new instance of
. |
static AbstractUrlAssert<?> |
then(URL actual)
Creates a new instance of
. |
static AbstractZonedDateTimeAssert<?> |
then(ZonedDateTime actual)
Creates a new instance of
. |
static AbstractThrowableAssert<?,? extends Throwable> |
thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Allows to capture and then assert on a
Throwable more easily when used with Java 8 lambdas. |
static AbstractThrowableAssert<?,? extends Throwable> |
thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Allows to capture and then assert on a
Throwable more easily when used with Java 8 lambdas. |
allOf, allOf, anyOf, anyOf, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThat, assertThatCode, assertThatExceptionOfType, assertThatIllegalArgumentException, assertThatIllegalStateException, assertThatIOException, assertThatNullPointerException, assertThatThrownBy, atIndex, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, byLessThan, catchThrowable, contentOf, contentOf, contentOf, contentOf, contentOf, contentOf, doesNotHave, entry, extractProperty, extractProperty, fail, fail, fail, failBecauseExceptionWasNotThrown, filter, filter, from, in, linesOf, linesOf, linesOf, linesOf, linesOf, linesOf, not, not, notIn, offset, offset, registerCustomDateFormat, registerCustomDateFormat, registerFormatterForType, setAllowComparingPrivateFields, setAllowExtractingPrivateFields, setLenientDateParsing, setMaxElementsForPrinting, setMaxLengthForSingleLineDescription, setRemoveAssertJRelatedElementsFromStackTrace, shouldHaveThrown, tuple, useDefaultDateFormatsOnly, useDefaultRepresentation, useRepresentation, within, within, within, within, within, within, within, within, within, withinPercentage, withinPercentage, withinPercentage, withPrecision, withPrecision
protected BDDAssertions()
BDDAssertions
.public static <T> PredicateAssert<T> then(Predicate<T> actual)
Predicate
.T
- the type of the value contained in the Predicate
.actual
- the actual value.public static IntPredicateAssert then(IntPredicate actual)
IntPredicate
.public static LongPredicateAssert then(LongPredicate actual)
LongPredicate
.public static DoublePredicateAssert then(DoublePredicate actual)
DoublePredicate
.public static <VALUE> OptionalAssert<VALUE> then(Optional<VALUE> optional)
Optional
.VALUE
- the type of the value contained in the Optional
.optional
- the actual value.public static OptionalIntAssert then(OptionalInt optional)
OptionalInt
.optional
- the actual value.public static OptionalLongAssert then(OptionalLong optional)
OptionalLong
.optional
- the actual value.public static OptionalDoubleAssert then(OptionalDouble optional)
OptionalDouble
.optional
- the actual value.public static AbstractBigDecimalAssert<?> then(BigDecimal actual)
BigDecimalAssert
.actual
- the actual value.public static AbstractBigIntegerAssert<?> then(BigInteger actual)
BigIntegerAssert
.actual
- the actual value.public static AbstractBooleanAssert<?> then(boolean actual)
BooleanAssert
.actual
- the actual value.public static AbstractBooleanAssert<?> then(Boolean actual)
BooleanAssert
.actual
- the actual value.public static AbstractBooleanArrayAssert<?> then(boolean[] actual)
BooleanArrayAssert
.actual
- the actual value.public static AbstractByteAssert<?> then(byte actual)
ByteAssert
.actual
- the actual value.public static AbstractByteAssert<?> then(Byte actual)
ByteAssert
.actual
- the actual value.public static AbstractByteArrayAssert<?> then(byte[] actual)
ByteArrayAssert
.actual
- the actual value.public static AbstractCharacterAssert<?> then(char actual)
CharacterAssert
.actual
- the actual value.public static AbstractCharArrayAssert<?> then(char[] actual)
CharArrayAssert
.actual
- the actual value.public static AbstractCharacterAssert<?> then(Character actual)
CharacterAssert
.actual
- the actual value.public static AbstractClassAssert<?> then(Class<?> actual)
ClassAssert
actual
- the actual value.public static <T extends Comparable<? super T>> AbstractComparableAssert<?,T> then(T actual)
GenericComparableAssert
with
standard comparison semantics.actual
- the actual value.public static <T> IterableAssert<T> then(Iterable<? extends T> actual)
IterableAssert
.actual
- the actual value.public static <T> IterableAssert<T> then(Iterator<? extends T> actual)
actual
- the actual value.public static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> FactoryBasedNavigableIterableAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> then(Iterable<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
FactoryBasedNavigableIterableAssert
allowing to navigate to any Iterable
element
in order to perform assertions on it.
Navigational methods provided:
The available assertions after navigating to an element depend on the ELEMENT_ASSERT
parameter of the given
AssertFactory<ELEMENT, ELEMENT_ASSERT>
(AssertJ can't figure it out because of Java type erasure).
Example with String
element assertions:
Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
// build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
@Override
public StringAssert createAssert(String string) {
return new StringAssert(string);
}
};
// assertion succeeds with String assertions chained after first()
then(hobbits, stringAssertFactory).first()
.startsWith("fro")
.endsWith("do");
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.public static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> ClassBasedNavigableIterableAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> then(ACTUAL actual, Class<ELEMENT_ASSERT> assertClass)
ClassBasedNavigableIterableAssert
allowing to navigate to any Iterable
element
in order to perform assertions on it.
Navigational methods provided:
The available assertions after navigating to an element depend on the given assertClass
(AssertJ can't find the element assert type by itself because of Java type erasure).
Example with String
element assertions:
Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
// assertion succeeds with String assertions chained after first()
then(hobbits, StringAssert.class).first()
.startsWith("fro")
.endsWith("do");
actual
- the actual value.assertClass
- the class used to create the elements assert instance.public static <ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> FactoryBasedNavigableListAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> then(List<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
FactoryBasedNavigableListAssert
allowing to navigate to any List
element
in order to perform assertions on it.
Navigational methods provided:
The available assertions after navigating to an element depend on the ELEMENT_ASSERT
parameter of the given
AssertFactory<ELEMENT, ELEMENT_ASSERT>
(AssertJ can't figure it out because of Java type erasure).
Example with String
element assertions:
List<String> hobbits = newArrayList("frodo", "sam", "pippin");
// build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
@Override
public StringAssert createAssert(String string) {
return new StringAssert(string);
}
};
// assertion succeeds with String assertions chained after first()
then(hobbits, stringAssertFactory).first()
.startsWith("fro")
.endsWith("do");
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.public static <ELEMENT,ACTUAL extends List<? extends ELEMENT>,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> ClassBasedNavigableListAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> then(List<? extends ELEMENT> actual, Class<ELEMENT_ASSERT> assertClass)
ClassBasedNavigableListAssert
tallowing to navigate to any List
element
in order to perform assertions on it.
Navigational methods provided:
The available assertions after navigating to an element depend on the given assertClass
(AssertJ can't find the element assert type by itself because of Java type erasure).
Example with String
element assertions:
List<String> hobbits = newArrayList("frodo", "sam", "pippin");
// assertion succeeds with String assertions chained after first()
then(hobbits, StringAssert.class).first()
.startsWith("fro")
.endsWith("do");
actual
- the actual value.assertClass
- the class used to create the elements assert instance.public static AbstractDoubleAssert<?> then(double actual)
DoubleAssert
.actual
- the actual value.public static AbstractDoubleAssert<?> then(Double actual)
DoubleAssert
.actual
- the actual value.public static AbstractDoubleArrayAssert<?> then(double[] actual)
DoubleArrayAssert
.actual
- the actual value.public static AbstractFileAssert<?> then(File actual)
FileAssert
.actual
- the actual value.public static AbstractPathAssert<?> then(Path actual)
PathAssert
actual
- the path to testpublic static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> then(Future<RESULT> actual)
FutureAssert
actual
- the future to testpublic static AbstractInputStreamAssert<?,? extends InputStream> then(InputStream actual)
InputStreamAssert
.actual
- the actual value.public static AbstractFloatAssert<?> then(float actual)
FloatAssert
.actual
- the actual value.public static AbstractFloatAssert<?> then(Float actual)
FloatAssert
.actual
- the actual value.public static AbstractFloatArrayAssert<?> then(float[] actual)
FloatArrayAssert
.actual
- the actual value.public static AbstractIntegerAssert<?> then(int actual)
IntegerAssert
.actual
- the actual value.public static AbstractIntArrayAssert<?> then(int[] actual)
IntArrayAssert
.actual
- the actual value.public static AbstractIntegerAssert<?> then(Integer actual)
IntegerAssert
.actual
- the actual value.public static <T> ListAssert<T> then(List<? extends T> actual)
ListAssert
.actual
- the actual value.public static AbstractLongAssert<?> then(long actual)
LongAssert
.actual
- the actual value.public static AbstractLongAssert<?> then(Long actual)
LongAssert
.actual
- the actual value.public static AbstractLongArrayAssert<?> then(long[] actual)
LongArrayAssert
.actual
- the actual value.public static <T> AbstractObjectAssert<?,T> then(T actual)
ObjectAssert
.actual
- the actual value.public static <T> AbstractObjectArrayAssert<?,T> then(T[] actual)
ObjectArrayAssert
.actual
- the actual value.public static <K,V> MapAssert<K,V> then(Map<K,V> actual)
MapAssert
.actual
- the actual value.public static AbstractShortAssert<?> then(short actual)
ShortAssert
.actual
- the actual value.public static AbstractShortAssert<?> then(Short actual)
ShortAssert
.actual
- the actual value.public static AbstractShortArrayAssert<?> then(short[] actual)
ShortArrayAssert
.actual
- the actual value.public static AbstractCharSequenceAssert<?,? extends CharSequence> then(CharSequence actual)
CharSequenceAssert
.actual
- the actual value.public static AbstractCharSequenceAssert<?,String> then(String actual)
StringAssert
.actual
- the actual value.public static AbstractDateAssert<?> then(Date actual)
DateAssert
.actual
- the actual value.public static AtomicBooleanAssert then(AtomicBoolean actual)
AtomicBoolean
.actual
- the actual value.public static AtomicIntegerAssert then(AtomicInteger actual)
AtomicInteger
.actual
- the actual value.public static AtomicIntegerArrayAssert then(AtomicIntegerArray actual)
AtomicIntegerArray
.actual
- the actual value.public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> then(AtomicIntegerFieldUpdater<OBJECT> actual)
AtomicIntegerFieldUpdater
.OBJECT
- the type of the object holding the updatable field.actual
- the actual value.public static AtomicLongAssert then(AtomicLong actual)
AtomicLong
.actual
- the actual value.public static AtomicLongArrayAssert then(AtomicLongArray actual)
AtomicLongArray
.actual
- the actual value.public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> then(AtomicLongFieldUpdater<OBJECT> actual)
AtomicLongFieldUpdater
.OBJECT
- the type of the object holding the updatable field.actual
- the actual value.public static <VALUE> AtomicReferenceAssert<VALUE> then(AtomicReference<VALUE> actual)
AtomicReference
.VALUE
- the type of the value contained in the AtomicReference
.actual
- the actual value.public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> then(AtomicReferenceArray<ELEMENT> actual)
AtomicReferenceArray
.ELEMENT
- the type of the value contained in the AtomicReferenceArray
.actual
- the actual value.public static <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> then(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 static <VALUE> AtomicMarkableReferenceAssert<VALUE> then(AtomicMarkableReference<VALUE> actual)
AtomicMarkableReference
.VALUE
- the type of the value contained in the AtomicMarkableReference
.actual
- the actual value.public static <VALUE> AtomicStampedReferenceAssert<VALUE> then(AtomicStampedReference<VALUE> actual)
AtomicStampedReference
.VALUE
- the type of the value contained in the AtomicStampedReference
.actual
- the actual value.public static AbstractThrowableAssert<?,? extends Throwable> then(Throwable actual)
ThrowableAssert
.actual
- the actual value.public static AbstractThrowableAssert<?,? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Throwable
more easily when used with Java 8 lambdas.
Java 8 example :
@Test
public void testException() {
thenThrownBy(() -> { 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 static AbstractThrowableAssert<?,? extends Throwable> thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Throwable
more easily when used with Java 8 lambdas.
Example :
ThrowingCallable callable = () -> {
throw new Exception("boom!");
};
// assertion succeeds
thenCode(callable).isInstanceOf(Exception.class)
.hasMessageContaining("boom");
// assertion fails
thenCode(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.
To use a test description, use Assertions.catchThrowable(ThrowableAssert.ThrowingCallable)
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);
// assertion will fail AND "display me" will appear in the error
Throwable thrown = catchThrowable(doNothing);
thenCode(thrown).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 :(
shouldRaiseOrNotThrowable
- The ThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.null
if none was raised by the callable.public static AbstractLocalDateAssert<?> then(LocalDate actual)
LocalDateAssert
.actual
- the actual value.public static AbstractLocalDateTimeAssert<?> then(LocalDateTime actual)
LocalDateTimeAssert
.actual
- the actual value.public static AbstractZonedDateTimeAssert<?> then(ZonedDateTime actual)
ZonedDateTimeAssert
.actual
- the actual value.public static AbstractLocalTimeAssert<?> then(LocalTime actual)
LocalTimeAssert
.actual
- the actual value.public static AbstractOffsetTimeAssert<?> then(OffsetTime actual)
OffsetTimeAssert
.actual
- the actual value.public static AbstractInstantAssert<?> then(Instant actual)
InstantAssert
.actual
- the actual value.public static AbstractUriAssert<?> then(URI actual)
UriAssert
.actual
- the actual value.public static AbstractUrlAssert<?> then(URL actual)
UrlAssert
.actual
- the actual value.public static AbstractOffsetDateTimeAssert<?> then(OffsetDateTime actual)
OffsetTimeAssert
.actual
- the actual value.public static <RESULT> CompletableFutureAssert<RESULT> then(CompletableFuture<RESULT> future)
CompletableFuture
.RESULT
- the type of the value contained in the CompletableFuture
.future
- the actual value.public static <T extends AssertDelegateTarget> T then(T assertion)
then
.
Consider for example the following MyButton and MyButtonAssert classes:
public class MyButton extends JButton {
private boolean blinking;
public boolean isBlinking() { return this.blinking; }
public void setBlinking(boolean blink) { this.blinking = blink; }
}
private static class MyButtonAssert implements AssertDelegateTarget {
private MyButton button;
MyButtonAssert(MyButton button) { this.button = button; }
void isBlinking() {
// standard assertion from core Assertions.then
then(button.isBlinking()).isTrue();
}
void isNotBlinking() {
// standard assertion from core Assertions.then
then(button.isBlinking()).isFalse();
}
}
As MyButtonAssert implements AssertDelegateTarget, you can use then(buttonAssert).isBlinking();
instead of buttonAssert.isBlinking();
to have easier to read assertions:
@Test
public void AssertDelegateTarget_example() {
MyButton button = new MyButton();
MyButtonAssert buttonAssert = new MyButtonAssert(button);
// you can encapsulate MyButtonAssert assertions methods within then
then(buttonAssert).isNotBlinking(); // same as : buttonAssert.isNotBlinking();
button.setBlinking(true);
then(buttonAssert).isBlinking(); // same as : buttonAssert.isBlinking();
}
T
- the generic type of the user-defined assert.assertion
- the assertion to return.public static <T> T then(AssertProvider<T> component)
Assert
to the AssertProvider.assertThat()
of the given component.
Read the comments on AssertProvider
for an example of its usage.
component
- the component that creates its own assertAssert
of the given componentpublic static <ELEMENT,STREAM extends BaseStream<ELEMENT,STREAM>> AbstractListAssert<?,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> then(BaseStream<? extends ELEMENT,STREAM> actual)
ListAssert
from the given BaseStream
.
Be aware that to create the returned ListAssert
the given the BaseStream
is consumed so it won't be
possible to use it again. Calling multiple methods on the returned ListAssert
is safe as it only
interacts with the List
built from the BaseStream
.
This method accepts Stream
and primitive stream variants
IntStream
, LongStream
and DoubleStream
.
actual
- the actual BaseStream
value.Copyright © 2014–2017 AssertJ. All rights reserved.