Class BDDAssertions
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);
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractBooleanAssert<?>
then
(boolean actual) Creates a new instance of
.BooleanAssert
static AbstractBooleanArrayAssert<?>
then
(boolean[] actual) Creates a new instance of
.BooleanArrayAssert
static AbstractByteAssert<?>
then
(byte actual) Creates a new instance of
.ByteAssert
static AbstractByteArrayAssert<?>
then
(byte[] actual) Creates a new instance of
.ByteArrayAssert
static AbstractCharacterAssert<?>
then
(char actual) Creates a new instance of
.CharacterAssert
static AbstractCharArrayAssert<?>
then
(char[] actual) Creates a new instance of
.CharArrayAssert
static AbstractDoubleAssert<?>
then
(double actual) Creates a new instance of
.DoubleAssert
static AbstractDoubleArrayAssert<?>
then
(double[] actual) Creates a new instance of
.DoubleArrayAssert
static AbstractFloatAssert<?>
then
(float actual) Creates a new instance of
.FloatAssert
static AbstractFloatArrayAssert<?>
then
(float[] actual) Creates a new instance of
.FloatArrayAssert
static AbstractIntegerAssert<?>
then
(int actual) Creates a new instance of
.IntegerAssert
static AbstractIntArrayAssert<?>
then
(int[] actual) Creates a new instance of
.IntArrayAssert
static AbstractLongAssert<?>
then
(long actual) Creates a new instance of
.LongAssert
static AbstractLongArrayAssert<?>
then
(long[] actual) Creates a new instance of
.LongArrayAssert
static AbstractShortAssert<?>
then
(short actual) Creates a new instance of
.ShortAssert
static AbstractShortArrayAssert<?>
then
(short[] actual) Creates a new instance of
.ShortArrayAssert
static <ACTUAL extends Iterable<? extends ELEMENT>,
ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableIterableAssert<?,ACTUAL, ELEMENT, ELEMENT_ASSERT> Creates a new instance of
allowing to navigate to anyClassBasedNavigableIterableAssert
Iterable
element in order to perform assertions on it.static AbstractFileAssert<?>
Creates a new instance of
.FileAssert
static AbstractInputStreamAssert<?,
? extends InputStream> then
(InputStream actual) Creates a new instance of
.InputStreamAssert
static AbstractBooleanAssert<?>
Creates a new instance of
.BooleanAssert
static AbstractByteAssert<?>
Creates a new instance of
.ByteAssert
static AbstractCharacterAssert<?>
Creates a new instance of
.CharacterAssert
static AbstractCharSequenceAssert<?,
? extends CharSequence> then
(CharSequence actual) Creates a new instance of
.CharSequenceAssert
static AbstractClassAssert<?>
Creates a new instance ofClassAssert
static AbstractDoubleAssert<?>
Creates a new instance of
.DoubleAssert
static AbstractFloatAssert<?>
Creates a new instance of
.FloatAssert
static AbstractIntegerAssert<?>
Creates a new instance of
.IntegerAssert
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) Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableIterableAssert
Iterable
element in order to perform assertions on it.static <T> IterableAssert<T>
Creates a new instance of
.IterableAssert
static AbstractLongAssert<?>
Creates a new instance of
.LongAssert
static AbstractShortAssert<?>
Creates a new instance of
.ShortAssert
static AbstractCharSequenceAssert<?,
String> Creates a new instance of
.StringAssert
static AbstractThrowableAssert<?,
? extends Throwable> Creates a new instance of
.ThrowableAssert
static AbstractBigDecimalAssert<?>
then
(BigDecimal actual) Creates a new instance of
.BigDecimalAssert
static AbstractBigIntegerAssert<?>
then
(BigInteger actual) Creates a new instance of
.BigIntegerAssert
static AbstractUriAssert<?>
Creates a new instance of
.UriAssert
static AbstractUrlAssert<?>
Creates a new instance of
.UrlAssert
static AbstractPathAssert<?>
Creates a new instance ofPathAssert
static AbstractInstantAssert<?>
Creates a new instance of
.InstantAssert
static AbstractLocalDateAssert<?>
Creates a new instance of
.LocalDateAssert
static AbstractLocalDateTimeAssert<?>
then
(LocalDateTime actual) Creates a new instance of
.LocalDateTimeAssert
static AbstractLocalTimeAssert<?>
Creates a new instance of
.LocalTimeAssert
static AbstractOffsetDateTimeAssert<?>
then
(OffsetDateTime actual) Creates a new instance of
.OffsetTimeAssert
static AbstractOffsetTimeAssert<?>
then
(OffsetTime actual) Creates a new instance of
.OffsetTimeAssert
static AbstractZonedDateTimeAssert<?>
then
(ZonedDateTime actual) Creates a new instance of
.ZonedDateTimeAssert
static AtomicBooleanAssert
then
(AtomicBoolean actual) Create assertion forAtomicBoolean
.static AtomicIntegerAssert
then
(AtomicInteger actual) Create assertion forAtomicInteger
.static AtomicIntegerArrayAssert
then
(AtomicIntegerArray actual) Create assertion forAtomicIntegerArray
.static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT>
then
(AtomicIntegerFieldUpdater<OBJECT> actual) Create assertion forAtomicIntegerFieldUpdater
.static AtomicLongAssert
then
(AtomicLong actual) Create assertion forAtomicLong
.static AtomicLongArrayAssert
then
(AtomicLongArray actual) Create assertion forAtomicLongArray
.static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT>
then
(AtomicLongFieldUpdater<OBJECT> actual) Create assertion forAtomicLongFieldUpdater
.static <VALUE> AtomicMarkableReferenceAssert<VALUE>
then
(AtomicMarkableReference<VALUE> actual) Create assertion forAtomicMarkableReference
.static <VALUE> AtomicReferenceAssert<VALUE>
then
(AtomicReference<VALUE> actual) Create assertion forAtomicReference
.static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT>
then
(AtomicReferenceArray<ELEMENT> actual) Create assertion forAtomicReferenceArray
.static <FIELD,
OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> then
(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) Create assertion forAtomicReferenceFieldUpdater
.static <VALUE> AtomicStampedReferenceAssert<VALUE>
then
(AtomicStampedReference<VALUE> actual) Create assertion forAtomicStampedReference
.static <RESULT> CompletableFutureAssert<RESULT>
then
(CompletableFuture<RESULT> future) Create assertion forCompletableFuture
.static <RESULT> AbstractFutureAssert<?,
? extends Future<? extends RESULT>, RESULT> Creates a new instance ofFutureAssert
static AbstractDateAssert<?>
Creates a new instance of
.DateAssert
static DoublePredicateAssert
then
(DoublePredicate actual) Create assertion forDoublePredicate
.static IntPredicateAssert
then
(IntPredicate actual) Create assertion forIntPredicate
.static LongPredicateAssert
then
(LongPredicate actual) Create assertion forLongPredicate
.static <T> PredicateAssert<T>
Create assertion forPredicate
.static <T> IterableAssert<T>
Creates a new instance of
.IterableAssert
static <ELEMENT,
ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableListAssert<?,ACTUAL, ELEMENT, ELEMENT_ASSERT> Creates a new instance of
tallowing to navigate to anyClassBasedNavigableListAssert
List
element in order to perform assertions on it.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) Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableListAssert
List
element in order to perform assertions on it.static <T> ListAssert<T>
Creates a new instance of
.ListAssert
static <K,
V> MapAssert<K, V> Creates a new instance of
.MapAssert
static <VALUE> OptionalAssert<VALUE>
Create assertion forOptional
.static OptionalDoubleAssert
then
(OptionalDouble optional) Create assertion forOptionalDouble
.static OptionalIntAssert
then
(OptionalInt optional) Create assertion forOptionalInt
.static OptionalLongAssert
then
(OptionalLong optional) Create assertion forOptionalLong
.static <ELEMENT,
STREAM extends BaseStream<ELEMENT, STREAM>>
AbstractListAssert<?,List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> then
(BaseStream<? extends ELEMENT, STREAM> actual) Creates a new instance of
from the givenListAssert
BaseStream
.static <T> T
then
(AssertProvider<T> component) Delegates the creation of theAssert
to theAssertProvider.assertThat()
of the given component.static <T extends Comparable<? super T>>
AbstractComparableAssert<?,T> then
(T actual) Creates a new instance of
with standard comparison semantics.GenericComparableAssert
static <T> AbstractObjectArrayAssert<?,
T> then
(T[] actual) Creates a new instance of
.ObjectArrayAssert
static AbstractThrowableAssert<?,
? extends Throwable> thenCode
(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable) Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.static AbstractThrowableAssert<?,
? extends Throwable> thenThrownBy
(ThrowableAssert.ThrowingCallable shouldRaiseThrowable) Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.Methods inherited from class org.assertj.core.api.Assertions
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, 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
-
Constructor Details
-
BDDAssertions
protected BDDAssertions()Creates a newBDDAssertions
.
-
-
Method Details
-
then
Create assertion forPredicate
.- Type Parameters:
T
- the type of the value contained in thePredicate
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.5.0
-
then
Create assertion forIntPredicate
.- Returns:
- the created assertion object.
- Since:
- 3.5.0
-
then
Create assertion forLongPredicate
.- Returns:
- the created assertion object.
- Since:
- 3.5.0
-
then
Create assertion forDoublePredicate
.- Returns:
- the created assertion object.
- Since:
- 3.5.0
-
then
Create assertion forOptional
.- Type Parameters:
VALUE
- the type of the value contained in theOptional
.- Parameters:
optional
- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forOptionalInt
.- Parameters:
optional
- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forOptionalLong
.- Parameters:
optional
- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forOptionalDouble
.- Parameters:
optional
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.BigDecimalAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.BigIntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.BooleanArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ByteArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.CharArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance ofClassAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
with standard comparison semantics.GenericComparableAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.IterableAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
public static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT, FactoryBasedNavigableIterableAssert<?,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>> ACTUAL, thenELEMENT, ELEMENT_ASSERT> (Iterable<? extends ELEMENT> actual, AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableIterableAssert
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 givenAssertFactory<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");
- Parameters:
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.- Returns:
- the created assertion object.
-
then
public static <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT, ClassBasedNavigableIterableAssert<?,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>> ACTUAL, thenELEMENT, ELEMENT_ASSERT> (ACTUAL actual, Class<ELEMENT_ASSERT> assertClass) Creates a new instance of
allowing to navigate to anyClassBasedNavigableIterableAssert
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");
- Parameters:
actual
- the actual value.assertClass
- the class used to create the elements assert instance.- Returns:
- the created assertion object.
-
then
public static <ACTUAL extends List<? extends ELEMENT>,ELEMENT, FactoryBasedNavigableListAssert<?,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>> ACTUAL, thenELEMENT, ELEMENT_ASSERT> (List<? extends ELEMENT> actual, AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableListAssert
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 givenAssertFactory<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");
- Parameters:
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.- Returns:
- the created assertion object.
-
then
public static <ELEMENT,ACTUAL extends List<? extends ELEMENT>, ClassBasedNavigableListAssert<?,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>> ACTUAL, thenELEMENT, ELEMENT_ASSERT> (List<? extends ELEMENT> actual, Class<ELEMENT_ASSERT> assertClass) Creates a new instance of
tallowing to navigate to anyClassBasedNavigableListAssert
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");
- Parameters:
actual
- the actual value.assertClass
- the class used to create the elements assert instance.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.DoubleArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.FileAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance ofPathAssert
- Parameters:
actual
- the path to test- Returns:
- the created assertion object
-
then
public static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>, thenRESULT> (Future<RESULT> actual) Creates a new instance ofFutureAssert
- Parameters:
actual
- the future to test- Returns:
- the created assertion object
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of
.InputStreamAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.FloatArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.IntArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ListAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.LongArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ObjectAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ObjectArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.MapAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ShortArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.CharSequenceAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.StringAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.DateAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forAtomicBoolean
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicInteger
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicIntegerArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <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
Create assertion forAtomicLong
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Create assertion forAtomicLongArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <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
Create assertion forAtomicReference
.- Type Parameters:
VALUE
- the type of the value contained in theAtomicReference
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> then(AtomicReferenceArray<ELEMENT> actual) Create assertion forAtomicReferenceArray
.- Type Parameters:
ELEMENT
- the type of the value contained in theAtomicReferenceArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> then(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.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <VALUE> AtomicMarkableReferenceAssert<VALUE> then(AtomicMarkableReference<VALUE> actual) Create assertion forAtomicMarkableReference
.- Type Parameters:
VALUE
- the type of the value contained in theAtomicMarkableReference
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
public static <VALUE> AtomicStampedReferenceAssert<VALUE> then(AtomicStampedReference<VALUE> actual) Create assertion forAtomicStampedReference
.- Type Parameters:
VALUE
- the type of the value contained in theAtomicStampedReference
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
then
Creates a new instance of
.ThrowableAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion Throwable.
-
thenThrownBy
public static AbstractThrowableAssert<?,? extends Throwable> thenThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable) Allows to capture and then assert on aThrowable
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"); }
- Parameters:
shouldRaiseThrowable
- TheThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.- Returns:
- The captured exception or
null
if none was raised by the callable.
-
thenCode
public static AbstractThrowableAssert<?,? extends Throwable> thenCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable) Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.Example :
If the providedThrowingCallable callable = () -> { throw new Exception("boom!"); }; // assertion succeeds thenCode(callable).isInstanceOf(Exception.class) .hasMessageContaining("boom"); // assertion fails thenCode(callable).doesNotThrowAnyException();
ThrowableAssert.ThrowingCallable
does 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, useAssertions.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 :(- Parameters:
shouldRaiseOrNotThrowable
- TheThrowableAssert.ThrowingCallable
or lambda with the code that should raise the throwable.- Returns:
- The captured exception or
null
if none was raised by the callable. - Since:
- 3.7.0
-
then
Creates a new instance of
.LocalDateAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.LocalDateTimeAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.ZonedDateTimeAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.LocalTimeAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.OffsetTimeAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.InstantAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.7.0
-
then
Creates a new instance of
.UriAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.UrlAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Creates a new instance of
.OffsetTimeAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
then
Create assertion forCompletableFuture
.- Type Parameters:
RESULT
- the type of the value contained in theCompletableFuture
.- Parameters:
future
- the actual value.- Returns:
- the created assertion object.
-
then
Returns the given assertion. This method improves code readability by surrounding the given assertion withthen
.Consider for example the following MyButton and MyButtonAssert classes:
As MyButtonAssert implements AssertDelegateTarget, you can usepublic 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(); } }
then(buttonAssert).isBlinking();
instead ofbuttonAssert.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(); }
- Type Parameters:
T
- the generic type of the user-defined assert.- Parameters:
assertion
- the assertion to return.- Returns:
- the given assertion.
-
then
Delegates the creation of theAssert
to theAssertProvider.assertThat()
of the given component.Read the comments on
AssertProvider
for an example of its usage.- Parameters:
component
- the component that creates its own assert- Returns:
- the associated
Assert
of the given component
-
then
public static <ELEMENT,STREAM extends BaseStream<ELEMENT, AbstractListAssert<?,STREAM>> List<? extends ELEMENT>, thenELEMENT, ObjectAssert<ELEMENT>> (BaseStream<? extends ELEMENT, STREAM> actual) Creates a new instance of
from the givenListAssert
BaseStream
.Be aware that to create the returned
ListAssert
the given theBaseStream
is consumed so it won't be possible to use it again. Calling multiple methods on the returnedListAssert
is safe as it only interacts with theList
built from theBaseStream
.This method accepts
Stream
and primitive stream variantsIntStream
,LongStream
andDoubleStream
.- Parameters:
actual
- the actualBaseStream
value.- Returns:
- the created assertion object.
-