Interface Descriptable<SELF>
- Type Parameters:
SELF- the "self" type of this assertion class.
- All Known Subinterfaces:
Assert<SELF,ACTUAL>
- All Known Implementing Classes:
Abstract2DArrayAssert,AbstractArrayAssert,AbstractAssert,AbstractAtomicFieldUpdaterAssert,AbstractAtomicReferenceAssert,AbstractBigDecimalAssert,AbstractBigDecimalScaleAssert,AbstractBigIntegerAssert,AbstractBooleanArrayAssert,AbstractBooleanAssert,AbstractByteArrayAssert,AbstractByteAssert,AbstractCharacterAssert,AbstractCharArrayAssert,AbstractCharSequenceAssert,AbstractClassAssert,AbstractCollectionAssert,AbstractComparableAssert,AbstractCompletableFutureAssert,AbstractDateAssert,AbstractDoubleArrayAssert,AbstractDoubleAssert,AbstractDurationAssert,AbstractEnumerableAssert,AbstractFileAssert,AbstractFileSizeAssert,AbstractFloatArrayAssert,AbstractFloatAssert,AbstractFutureAssert,AbstractInputStreamAssert,AbstractInstantAssert,AbstractIntArrayAssert,AbstractIntegerAssert,AbstractIterableAssert,AbstractIterableSizeAssert,AbstractIteratorAssert,AbstractListAssert,AbstractLocalDateAssert,AbstractLocalDateTimeAssert,AbstractLocalTimeAssert,AbstractLongAdderAssert,AbstractLongArrayAssert,AbstractLongAssert,AbstractMapAssert,AbstractMapSizeAssert,AbstractMatcherAssert,AbstractObjectArrayAssert,AbstractObjectAssert,AbstractOffsetDateTimeAssert,AbstractOffsetTimeAssert,AbstractOptionalAssert,AbstractOptionalDoubleAssert,AbstractOptionalIntAssert,AbstractOptionalLongAssert,AbstractPathAssert,AbstractPeriodAssert,AbstractPredicateAssert,AbstractShortArrayAssert,AbstractShortAssert,AbstractSpliteratorAssert,AbstractStringAssert,AbstractTemporalAssert,AbstractThrowableAssert,AbstractUniversalComparableAssert,AbstractUriAssert,AbstractUrlAssert,AbstractYearMonthAssert,AbstractZonedDateTimeAssert,AllOf,AnyOf,AtomicBooleanAssert,AtomicIntegerArrayAssert,AtomicIntegerAssert,AtomicIntegerFieldUpdaterAssert,AtomicLongArrayAssert,AtomicLongAssert,AtomicLongFieldUpdaterAssert,AtomicMarkableReferenceAssert,AtomicReferenceArrayAssert,AtomicReferenceAssert,AtomicReferenceFieldUpdaterAssert,AtomicStampedReferenceAssert,BigDecimalAssert,BigDecimalScaleAssert,BigIntegerAssert,Boolean2DArrayAssert,BooleanArrayAssert,BooleanAssert,Byte2DArrayAssert,ByteArrayAssert,ByteAssert,Char2DArrayAssert,CharacterAssert,CharArrayAssert,CharSequenceAssert,ClassAssert,ClassBasedNavigableIterableAssert,ClassBasedNavigableListAssert,CollectionAssert,CompletableFutureAssert,Condition,DateAssert,DoesNotHave,Double2DArrayAssert,DoubleArrayAssert,DoubleAssert,DoublePredicateAssert,DurationAssert,FactoryBasedNavigableIterableAssert,FactoryBasedNavigableListAssert,FileAssert,FileSizeAssert,Float2DArrayAssert,FloatArrayAssert,FloatAssert,FutureAssert,GenericComparableAssert,HamcrestCondition,InputStreamAssert,InstantAssert,Int2DArrayAssert,IntArrayAssert,IntegerAssert,IntPredicateAssert,IterableAssert,IterableSizeAssert,IteratorAssert,Join,ListAssert,LocalDateAssert,LocalDateTimeAssert,LocalTimeAssert,Long2DArrayAssert,LongAdderAssert,LongArrayAssert,LongAssert,LongPredicateAssert,MapAssert,MappedCondition,MapSizeAssert,MatcherAssert,Negative,NestableCondition,Not,NotThrownAssert,Object2DArrayAssert,ObjectArrayAssert,ObjectAssert,OffsetDateTimeAssert,OffsetTimeAssert,OptionalAssert,OptionalDoubleAssert,OptionalIntAssert,OptionalLongAssert,PathAssert,PeriodAssert,PredicateAssert,RecursiveAssertionAssert,RecursiveComparisonAssert,Short2DArrayAssert,ShortArrayAssert,ShortAssert,SoftThrowableAssertAlternative,SoftThrowableTypeAssert,SpliteratorAssert,StringAssert,TemporalAssert,ThrowableAssert,ThrowableAssertAlternative,ThrowableTypeAssert,UniversalComparableAssert,UriAssert,UrlAssert,VerboseCondition,YearMonthAssert,ZonedDateTimeAssert
- Author:
- Alex Ruiz, Yvonne Wang, Mikhail Mazursky
-
Method Summary
Modifier and TypeMethodDescriptiondefault SELFSets the description of the assertion that is going to be called after.default SELFLazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.default SELFas(Description description) Sets the description of the assertion that is going to be called after.default SELFdescribedAs(String description, Object... args) Sets the description of the assertion that is going to be called after.default SELFdescribedAs(Supplier<String> descriptionSupplier) Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.describedAs(Description description) Sets the description of the assertion that is going to be called after.
-
Method Details
-
as
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows
String.format(String, Object...)syntax.Example :
try { // set an incorrect age to Mr Frodo which is really 33 years old. frodo.setAge(50); // specify a test description (call as() before the assertion !), it supports String format syntax. assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33); } catch (AssertionError e) { assertThat(e).hasMessage("[check Frodo's age]\n expected: 33\n but was: 50"); }- Parameters:
description- the new description to set.args- optional parameter if description is a format String.- Returns:
thisobject.- Throws:
NullPointerException- if the description isnull.- See Also:
-
as
Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.The description must be set before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Example :
// set an incorrect age to Mr Frodo which we all know is 33 years old. frodo.setAge(50); // the lazy test description is not evaluated as the assertion succeeds assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(50); try { // the lazy test description is evaluated as the assertion fails assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(33); } catch (AssertionError e) { assertThat(e).hasMessage("[check Frodo's age]\n expected: 33\n but was: 50"); }- Parameters:
descriptionSupplier- the descriptionSupplier.- Returns:
thisobject.- Throws:
IllegalStateException- if the descriptionSupplier isnullwhen evaluated.
-
as
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
Stringby allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Parameters:
description- the new description to set.- Returns:
thisobject.- Throws:
NullPointerException- if the description isnull.- See Also:
-
describedAs
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for
since "as" is a keyword in Groovy.as(String, Object...)- Parameters:
description- the new description to set.args- optional parameter if description is a format String.- Returns:
thisobject.- Throws:
NullPointerException- if the description isnull.
-
describedAs
Lazily specifies the description of the assertion that is going to be called, the given description is not evaluated if the assertion succeeds.The description must be set before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Example :
// set an incorrect age to Mr Frodo which we all know is 33 years old. frodo.setAge(50); // the lazy test description is not evaluated as the assertion succeeds assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(50); try { // the lazy test description is evaluated as the assertion fails assertThat(frodo.getAge()).as(() -> "check Frodo's age").isEqualTo(33); } catch (AssertionError e) { assertThat(e).hasMessage("[check Frodo's age]\n expected: 33\n but was: 50"); }- Parameters:
descriptionSupplier- the descriptionSupplier.- Returns:
thisobject.- Throws:
IllegalStateException- if the descriptionSupplier isnullwhen evaluated.
-
describedAs
Sets the description of the assertion that is going to be called after.You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a
Stringby allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.- Parameters:
description- the new description to set.- Returns:
thisobject.- Throws:
NullPointerException- if the description isnull.
-