Package org.assertj.core.api
Interface WithAssertions
-
public interface WithAssertions
A unified entry point to all non-deprecated assertions from both the new Java 8 core API and the pre-Java 8 core API. As a convenience, the methods are defined in an interface so that no static imports are necessary if the test class implements this interface. Based on an idea by David Gageot : http://blog.javabien.net/2014/04/23/what-if-assertj-used-java-8/- Author:
- Alan Rothkopf
-
-
Method Summary
-
-
-
Method Detail
-
offset
default Offset<Float> offset(Float value)
Delegate call toAssertions.offset(Float)
-
offset
default Offset<Double> offset(Double value)
Delegate call toAssertions.offset(Double)
-
entry
default <K,V> MapEntry<K,V> entry(K key, V value)
Delegate call toAssertions.entry(Object, Object)
-
fail
default void fail(String failureMessage)
Delegate call toAssertions.fail(String)
-
fail
default void fail(String failureMessage, Throwable realCause)
Delegate call toAssertions.fail(String,Throwable)
-
not
default <T> Not<T> not(Condition<? super T> condition)
Delegate call toAssertions.not(Condition)
-
allOf
default <T> Condition<T> allOf(Iterable<? extends Condition<? super T>> conditions)
Delegate call toAssertions.allOf(Iterable)
-
allOf
default <T> Condition<T> allOf(Condition<? super T>... conditions)
Delegate call toAssertions.allOf(Condition[])
-
assertThat
default <T> AbstractObjectArrayAssert<?,T> assertThat(T[] actual)
Delegate call toAssertions.assertThat(Object[])
-
assertThat
default <T extends AssertDelegateTarget> T assertThat(T assertion)
Delegate call toAssertions.assertThat(AssertDelegateTarget)
-
assertThat
default <K,V> MapAssert<K,V> assertThat(Map<K,V> actual)
Delegate call toAssertions.assertThat(Map)
-
assertThat
default AbstractShortAssert<?> assertThat(short actual)
Delegate call toAssertions.assertThat(short)
-
assertThat
default AbstractLongAssert<?> assertThat(long actual)
Delegate call toAssertions.assertThat(long)
-
assertThat
default AbstractLongAssert<?> assertThat(Long actual)
Delegate call toAssertions.assertThat(Long)
-
assertThat
default AbstractLongArrayAssert<?> assertThat(long[] actual)
Delegate call toAssertions.assertThat(long[])
-
assertThat
default <T> AbstractObjectAssert<?,T> assertThat(T actual)
Delegate call toAssertions.assertThat(Object)
-
assertThat
default AbstractCharSequenceAssert<?,String> assertThat(String actual)
Delegate call toAssertions.assertThat(String)
-
assertThat
default AbstractDateAssert<?> assertThat(Date actual)
Delegate call toAssertions.assertThat(Date)
-
assertThat
default AbstractThrowableAssert<?,? extends Throwable> assertThat(Throwable actual)
Delegate call toAssertions.assertThat(Throwable)
-
assertThat
default AbstractBigDecimalAssert<?> assertThat(BigDecimal actual)
Delegate call toAssertions.assertThat(BigDecimal)
-
assertThat
default AbstractBigIntegerAssert<?> assertThat(BigInteger actual)
Creates a new instance of
.BigIntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
default AtomicBooleanAssert assertThat(AtomicBoolean actual)
Create assertion forAtomicBoolean
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default AtomicIntegerAssert assertThat(AtomicInteger actual)
Create assertion forAtomicInteger
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default AtomicIntegerArrayAssert assertThat(AtomicIntegerArray actual)
Create int[] assertion forAtomicIntegerArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default <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
default AtomicLongAssert assertThat(AtomicLong actual)
Create assertion forAtomicLong
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default AtomicLongArrayAssert assertThat(AtomicLongArray actual)
Create assertion forAtomicLongArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default <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
default <VALUE> AtomicReferenceAssert<VALUE> assertThat(AtomicReference<VALUE> actual)
Create assertion forAtomicReference
.- Type Parameters:
VALUE
- the type of the value contained in theAtomicReference
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
default <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> assertThat(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.
-
assertThat
default <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
default <VALUE> AtomicMarkableReferenceAssert<VALUE> assertThat(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.
-
assertThat
default <VALUE> AtomicStampedReferenceAssert<VALUE> assertThat(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.
-
assertThat
default AbstractCharSequenceAssert<?,? extends CharSequence> assertThat(CharSequence actual)
Delegate call toAssertions.assertThat(CharSequence)
-
assertThat
default AbstractShortArrayAssert<?> assertThat(short[] actual)
Delegate call toAssertions.assertThat(short[])
-
assertThat
default AbstractShortAssert<?> assertThat(Short actual)
Delegate call toAssertions.assertThat(Short)
-
assertThat
default AbstractClassAssert<?> assertThat(Class<?> actual)
Delegate call toAssertions.assertThat(Class)
-
assertThat
default AbstractCharacterAssert<?> assertThat(Character actual)
Delegate call toAssertions.assertThat(Character)
-
assertThat
default AbstractCharArrayAssert<?> assertThat(char[] actual)
Delegate call toAssertions.assertThat(char[])
-
assertThat
default AbstractCharacterAssert<?> assertThat(char actual)
Delegate call toAssertions.assertThat(char)
-
assertThat
default <T extends Comparable<? super T>> AbstractComparableAssert<?,T> assertThat(T actual)
Delegate call toAssertions.assertThat(Comparable)
-
assertThat
default <T> IterableAssert<T> assertThat(Iterable<? extends T> actual)
Delegate call toAssertions.assertThat(Iterable)
-
assertThat
default <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> FactoryBasedNavigableIterableAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> assertThat(Iterable<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Delegate call toAssertions.assertThat(Iterable, AssertFactory)
-
assertThat
default <T> IterableAssert<T> assertThat(Iterator<? extends T> actual)
Delegate call toAssertions.assertThat(Iterator)
-
assertThat
default <ACTUAL extends Iterable<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> ClassBasedNavigableIterableAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> assertThat(ACTUAL actual, Class<ELEMENT_ASSERT> assertClass)
Delegate call toAssertions.assertThat(Iterable, Class)
-
assertThat
default AbstractBooleanAssert<?> assertThat(Boolean actual)
Delegate call toAssertions.assertThat(Boolean)
-
assertThat
default AbstractBooleanArrayAssert<?> assertThat(boolean[] actual)
Delegate call toAssertions.assertThat(boolean)
-
assertThat
default AbstractByteAssert<?> assertThat(byte actual)
Delegate call toAssertions.assertThat(byte)
-
assertThat
default AbstractByteAssert<?> assertThat(Byte actual)
Delegate call toAssertions.assertThat(Byte)
-
assertThat
default AbstractByteArrayAssert<?> assertThat(byte[] actual)
Delegate call toAssertions.assertThat(byte[])
-
assertThat
default AbstractBooleanAssert<?> assertThat(boolean actual)
Delegate call toAssertions.assertThat(boolean)
-
assertThat
default AbstractFloatAssert<?> assertThat(float actual)
Delegate call toAssertions.assertThat(float)
-
assertThat
default AbstractInputStreamAssert<?,? extends InputStream> assertThat(InputStream actual)
Delegate call toAssertions.assertThat(InputStream)
-
assertThat
default AbstractFileAssert<?> assertThat(File actual)
Delegate call toAssertions.assertThat(File)
-
assertThat
default <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> assertThat(Future<RESULT> actual)
Delegate call toAssertions.assertThat(Future)
- Since:
- 3.7.0
-
assertThat
default AbstractPathAssert<?> assertThat(Path actual)
Delegate call toAssertions.assertThat(Path)
-
assertThat
default AbstractIntArrayAssert<?> assertThat(int[] actual)
Delegate call toAssertions.assertThat(int[])
-
assertThat
default AbstractFloatAssert<?> assertThat(Float actual)
Delegate call toAssertions.assertThat(Float)
-
assertThat
default AbstractIntegerAssert<?> assertThat(int actual)
Delegate call toAssertions.assertThat(int)
-
assertThat
default AbstractFloatArrayAssert<?> assertThat(float[] actual)
Delegate call toAssertions.assertThat(float[])
-
assertThat
default AbstractIntegerAssert<?> assertThat(Integer actual)
Delegate call toAssertions.assertThat(Integer)
-
assertThat
default AbstractDoubleAssert<?> assertThat(double actual)
Delegate call toAssertions.assertThat(double)
-
assertThat
default AbstractDoubleAssert<?> assertThat(Double actual)
Delegate call toAssertions.assertThat(Double)
-
assertThat
default <T> ListAssert<? extends T> assertThat(List<? extends T> actual)
Delegate call toAssertions.assertThat(List)
-
assertThat
default <ELEMENT,ACTUAL extends List<? extends ELEMENT>,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> ClassBasedNavigableListAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual, Class<ELEMENT_ASSERT> assertClass)
Delegate call toAssertions.assertThat(List, Class)
)}
-
assertThat
default <ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> FactoryBasedNavigableListAssert<?,ACTUAL,ELEMENT,ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Delegate call toAssertions.assertThat(List, AssertFactory)
)}
-
assertThat
default <ELEMENT,STREAM extends BaseStream<ELEMENT,STREAM>> AbstractListAssert<?,? extends List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> assertThat(BaseStream<? extends ELEMENT,STREAM> actual)
Delegate call toAssertions.assertThat(List)
-
assertThat
default AbstractDoubleArrayAssert<?> assertThat(double[] actual)
Delegate call toAssertions.assertThat(double[])
-
extractProperty
default Properties<Object> extractProperty(String propertyName)
Delegate call toAssertions.extractProperty(String)
-
extractProperty
default <T> Properties<T> extractProperty(String propertyName, Class<T> propertyType)
Delegate call toAssertions.extractProperty(String,Class)
-
tuple
default Tuple tuple(Object... values)
Delegate call toAssertions.tuple(Object[])
-
atIndex
default Index atIndex(int actual)
Delegate call toAssertions.atIndex(int)
-
within
default Offset<Double> within(Double actual)
Delegate call toAssertions.within(Double)
-
within
default Offset<BigDecimal> within(BigDecimal actual)
Delegate call toAssertions.within(BigDecimal)
-
within
default Offset<Float> within(Float actual)
Delegate call toAssertions.within(Float)
-
anyOf
default <T> Condition<T> anyOf(Iterable<? extends Condition<? super T>> conditions)
Delegate call toAssertions.anyOf(Iterable)
-
anyOf
default <T> Condition<T> anyOf(Condition<? super T>... conditions)
Delegate call toAssertions.anyOf(Condition[])
-
doesNotHave
default <T> DoesNotHave<T> doesNotHave(Condition<? super T> condition)
Delegate call toAssertions.doesNotHave(Condition)
-
contentOf
default String contentOf(File file, String charsetName)
Delegate call toAssertions.contentOf(File,String)
-
contentOf
default String contentOf(File actual)
Delegate call toAssertions.contentOf(File)
-
contentOf
default String contentOf(File file, Charset charset)
Delegate call toAssertions.contentOf(File,Charset)
-
linesOf
default List<String> linesOf(File actual)
Delegate call toAssertions.linesOf(File)
-
linesOf
default List<String> linesOf(File file, String charsetName)
Delegate call toAssertions.linesOf(File,String)
-
linesOf
default List<String> linesOf(File actual, Charset arg1)
Delegate call toAssertions.linesOf(File,Charset)
-
setRemoveAssertJRelatedElementsFromStackTrace
default void setRemoveAssertJRelatedElementsFromStackTrace(boolean actual)
Delegate call toAssertions.setRemoveAssertJRelatedElementsFromStackTrace(boolean)
-
failBecauseExceptionWasNotThrown
default void failBecauseExceptionWasNotThrown(Class<? extends Throwable> exceptionClass)
-
setAllowExtractingPrivateFields
default void setAllowExtractingPrivateFields(boolean actual)
Delegate call toAssertions.setAllowExtractingPrivateFields(boolean)
-
registerCustomDateFormat
default void registerCustomDateFormat(DateFormat actual)
Delegate call toAssertions.registerCustomDateFormat(DateFormat)
-
registerCustomDateFormat
default void registerCustomDateFormat(String actual)
Delegate call toAssertions.registerCustomDateFormat(String)
-
useDefaultDateFormatsOnly
default void useDefaultDateFormatsOnly()
Delegate call toAssertions.useDefaultDateFormatsOnly()
-
assertThat
default AbstractZonedDateTimeAssert<?> assertThat(ZonedDateTime actual)
Delegate call toAssertions.assertThat(ZonedDateTime)
-
assertThat
default <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletableFuture<RESULT> future)
Delegate call toAssertions.assertThat(CompletableFuture)
-
assertThat
default <VALUE> OptionalAssert<VALUE> assertThat(Optional<VALUE> optional)
Delegate call toAssertions.assertThat(Optional)
-
assertThat
default OptionalDoubleAssert assertThat(OptionalDouble optional)
Delegate call toAssertions.assertThat(java.util.OptionalDouble)
-
assertThat
default OptionalIntAssert assertThat(OptionalInt optional)
Delegate call toAssertions.assertThat(java.util.OptionalInt)
-
assertThat
default OptionalLongAssert assertThat(OptionalLong optional)
Delegate call toAssertions.assertThat(java.util.OptionalLong)
-
assertThat
default AbstractLocalDateTimeAssert<?> assertThat(LocalDateTime localDateTime)
Delegate call toAssertions.assertThat(LocalDateTime)
-
assertThat
default AbstractLocalDateAssert<?> assertThat(LocalDate localDate)
Delegate call toAssertions.assertThat(LocalDate)
-
assertThat
default AbstractLocalTimeAssert<?> assertThat(LocalTime localTime)
Delegate call toAssertions.assertThat(LocalTime)
-
assertThat
default AbstractInstantAssert<?> assertThat(Instant actual)
Delegate call toAssertions.assertThat(java.time.Instant)
- Since:
- 3.7.0
-
assertThat
default AbstractOffsetTimeAssert<?> assertThat(OffsetTime offsetTime)
Delegate call toAssertions.assertThat(OffsetTime)
-
assertThat
default AbstractOffsetDateTimeAssert<?> assertThat(OffsetDateTime offsetDateTime)
Delegate call toAssertions.assertThat(OffsetDateTime)
-
assertThatThrownBy
default AbstractThrowableAssert<?,? extends Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Delegate call toAssertions.assertThatThrownBy(ThrowableAssert.ThrowingCallable)
-
assertThatCode
default AbstractThrowableAssert<?,? extends Throwable> assertThatCode(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 assertThatCode(callable).isInstanceOf(Exception.class) .hasMessageContaining("boom"); // assertion fails assertThatCode(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, usecatchThrowable(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 :(- 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
-
catchThrowable
default Throwable catchThrowable(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Delegate call toAssertions.catchThrowable(ThrowableAssert.ThrowingCallable)
-
assertThatExceptionOfType
default <T extends Throwable> ThrowableTypeAssert<T> assertThatExceptionOfType(Class<? extends T> exceptionType)
Entry point to check that an exception of type T is thrown by a giventhrowingCallable
which allows to chain assertions on the thrown exception.Example:
This method is more or less the same ofassertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); }) .withMessage("boom!");
assertThatThrownBy(ThrowableAssert.ThrowingCallable)
but in a more natural way.- Parameters:
exceptionType
- the actual value.- Returns:
- the created
ThrowableTypeAssert
.
-
assertThat
default <T> PredicateAssert<T> assertThat(Predicate<T> actual)
Delegate call toAssertions.assertThat(Predicate)
-
assertThat
default IntPredicateAssert assertThat(IntPredicate actual)
Delegate call toAssertions.assertThat(IntPredicate)
-
assertThat
default LongPredicateAssert assertThat(LongPredicate actual)
Delegate call toAssertions.assertThat(LongPredicate)
-
assertThat
default DoublePredicateAssert assertThat(DoublePredicate actual)
Delegate call toAssertions.assertThat(DoublePredicate)
-
assertThat
default AbstractUrlAssert<?> assertThat(URL actual)
Delegate call toAssertions.assertThat(URL)
-
assertThat
default AbstractUriAssert<?> assertThat(URI actual)
Delegate call toAssertions.assertThat(URI)
-
assertThat
default <T> T assertThat(AssertProvider<T> component)
Delegate call toAssertions.assertThat(AssertProvider)
-
filter
default <E> Filters<E> filter(E[] array)
Delegate call toAssertions.filter(Object[])
-
filter
default <E> Filters<E> filter(Iterable<E> iterableToFilter)
Delegate call toAssertions.filter(Iterable)
-
-