Class Java6Assertions
- java.lang.Object
-
- org.assertj.core.api.Java6Assertions
-
@Deprecated public class Java6Assertions extends Object
Deprecated.For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.Assertions compatible with Android. Duplicated from
Assertions
.- See Also:
Assertions
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Java6Assertions()
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Condition<T>
allOf(Iterable<? extends Condition<? super T>> conditions)
Deprecated.Creates a newAllOf
static <T> Condition<T>
allOf(Condition<? super T>... conditions)
Deprecated.Creates a newAllOf
static <T> Condition<T>
anyOf(Iterable<? extends Condition<? super T>> conditions)
Deprecated.Creates a newAnyOf
static <T> Condition<T>
anyOf(Condition<? super T>... conditions)
Deprecated.Only delegate toAnyOf.anyOf(Condition...)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useAnyOf
if you prefer).static AbstractBooleanAssert<?>
assertThat(boolean actual)
Deprecated.Creates a new instance of
.BooleanAssert
static AbstractBooleanArrayAssert<?>
assertThat(boolean[] actual)
Deprecated.Creates a new instance of
.BooleanArrayAssert
static Boolean2DArrayAssert
assertThat(boolean[][] actual)
Deprecated.Creates a new instance of
.Boolean2DArrayAssert
static AbstractByteAssert<?>
assertThat(byte actual)
Deprecated.Creates a new instance of
.ByteAssert
static AbstractByteArrayAssert<?>
assertThat(byte[] actual)
Deprecated.Creates a new instance of
.ByteArrayAssert
static Byte2DArrayAssert
assertThat(byte[][] actual)
Deprecated.Creates a new instance of
.Byte2DArrayAssert
static AbstractCharacterAssert<?>
assertThat(char actual)
Deprecated.Creates a new instance of
.CharacterAssert
static AbstractCharArrayAssert<?>
assertThat(char[] actual)
Deprecated.Creates a new instance of
.CharArrayAssert
static Char2DArrayAssert
assertThat(char[][] actual)
Deprecated.Creates a new instance of
.Char2DArrayAssert
static AbstractDoubleAssert<?>
assertThat(double actual)
Deprecated.Creates a new instance of
.DoubleAssert
static AbstractDoubleArrayAssert<?>
assertThat(double[] actual)
Deprecated.Creates a new instance of
.DoubleArrayAssert
static Double2DArrayAssert
assertThat(double[][] actual)
Deprecated.Creates a new instance of
.Double2DArrayAssert
static AbstractFloatAssert<?>
assertThat(float actual)
Deprecated.Creates a new instance of
.FloatAssert
static AbstractFloatArrayAssert<?>
assertThat(float[] actual)
Deprecated.Creates a new instance of
.FloatArrayAssert
static Float2DArrayAssert
assertThat(float[][] actual)
Deprecated.Creates a new instance of
.Float2DArrayAssert
static AbstractIntegerAssert<?>
assertThat(int actual)
Deprecated.Creates a new instance of
.IntegerAssert
static AbstractIntArrayAssert<?>
assertThat(int[] actual)
Deprecated.Creates a new instance of
.IntArrayAssert
static Int2DArrayAssert
assertThat(int[][] actual)
Deprecated.Creates a new instance of
.Int2DArrayAssert
static AbstractLongAssert<?>
assertThat(long actual)
Deprecated.Creates a new instance of
.LongAssert
static AbstractLongArrayAssert<?>
assertThat(long[] actual)
Deprecated.Creates a new instance of
.LongArrayAssert
static Long2DArrayAssert
assertThat(long[][] actual)
Deprecated.Creates a new instance of
.Long2DArrayAssert
static AbstractShortAssert<?>
assertThat(short actual)
Deprecated.Creates a new instance of
.ShortAssert
static AbstractShortArrayAssert<?>
assertThat(short[] actual)
Deprecated.Creates a new instance of
.ShortArrayAssert
static Short2DArrayAssert
assertThat(short[][] actual)
Deprecated.Creates a new instance of
.Short2DArrayAssert
static <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)
Deprecated.Creates a new instance of
allowing to navigate to anyClassBasedNavigableIterableAssert
Iterable
element in order to perform assertions on it.static AbstractFileAssert<?>
assertThat(File actual)
Deprecated.Creates a new instance of
.FileAssert
static AbstractInputStreamAssert<?,? extends InputStream>
assertThat(InputStream actual)
Deprecated.Creates a new instance of
.InputStreamAssert
static AbstractBooleanAssert<?>
assertThat(Boolean actual)
Deprecated.Creates a new instance of
.BooleanAssert
static AbstractByteAssert<?>
assertThat(Byte actual)
Deprecated.Creates a new instance of
.ByteAssert
static AbstractCharacterAssert<?>
assertThat(Character actual)
Deprecated.Creates a new instance of
.CharacterAssert
static AbstractCharSequenceAssert<?,? extends CharSequence>
assertThat(CharSequence actual)
Deprecated.Creates a new instance of
.CharSequenceAssert
static AbstractClassAssert<?>
assertThat(Class<?> actual)
Deprecated.Creates a new instance ofClassAssert
static AbstractDoubleAssert<?>
assertThat(Double actual)
Deprecated.Creates a new instance of
.DoubleAssert
static AbstractFloatAssert<?>
assertThat(Float actual)
Deprecated.Creates a new instance of
.FloatAssert
static AbstractIntegerAssert<?>
assertThat(Integer actual)
Deprecated.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>assertThat(Iterable<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Deprecated.Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableIterableAssert
Iterable
element in order to perform assertions on it.static <T> AbstractIterableAssert<?,Iterable<? extends T>,T,ObjectAssert<T>>
assertThat(Iterable<? extends T> actual)
Deprecated.Creates a new instance of
.IterableAssert
static AbstractLongAssert<?>
assertThat(Long actual)
Deprecated.Creates a new instance of
.LongAssert
static AbstractShortAssert<?>
assertThat(Short actual)
Deprecated.Creates a new instance of
.ShortAssert
static AbstractStringAssert<?>
assertThat(String actual)
Deprecated.Creates a new instance of
.StringAssert
static AbstractCharSequenceAssert<?,? extends CharSequence>
assertThat(StringBuffer actual)
Deprecated.Creates a new instance of
from aCharSequenceAssert
StringBuffer
.static AbstractCharSequenceAssert<?,? extends CharSequence>
assertThat(StringBuilder actual)
Deprecated.Creates a new instance of
from aCharSequenceAssert
StringBuilder
.static AbstractBigDecimalAssert<?>
assertThat(BigDecimal actual)
Deprecated.Creates a new instance of
.BigDecimalAssert
static AbstractBigIntegerAssert<?>
assertThat(BigInteger actual)
Deprecated.Creates a new instance of
.BigIntegerAssert
static AbstractUriAssert<?>
assertThat(URI actual)
Deprecated.Creates a new instance of
.UriAssert
static AbstractUrlAssert<?>
assertThat(URL actual)
Deprecated.Creates a new instance of
.UrlAssert
static <T> AbstractCollectionAssert<?,Collection<? extends T>,T,ObjectAssert<T>>
assertThat(Collection<? extends T> actual)
Deprecated.Creates a new instance of
.CollectionAssert
static AtomicBooleanAssert
assertThat(AtomicBoolean actual)
Deprecated.Create assertion forAtomicBoolean
.static AtomicIntegerAssert
assertThat(AtomicInteger actual)
Deprecated.Create assertion forAtomicInteger
.static AtomicIntegerArrayAssert
assertThat(AtomicIntegerArray actual)
Deprecated.Create int[] assertion forAtomicIntegerArray
.static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT>
assertThat(AtomicIntegerFieldUpdater<OBJECT> actual)
Deprecated.Create assertion forAtomicIntegerFieldUpdater
.static AtomicLongAssert
assertThat(AtomicLong actual)
Deprecated.Create assertion forAtomicLong
.static AtomicLongArrayAssert
assertThat(AtomicLongArray actual)
Deprecated.Create assertion forAtomicLongArray
.static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT>
assertThat(AtomicLongFieldUpdater<OBJECT> actual)
Deprecated.Create assertion forAtomicLongFieldUpdater
.static <VALUE> AtomicMarkableReferenceAssert<VALUE>
assertThat(AtomicMarkableReference<VALUE> actual)
Deprecated.Create assertion forAtomicMarkableReference
.static <VALUE> AtomicReferenceAssert<VALUE>
assertThat(AtomicReference<VALUE> actual)
Deprecated.Create assertion forAtomicReference
.static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT>
assertThat(AtomicReferenceArray<ELEMENT> actual)
Deprecated.Create assertion forAtomicReferenceArray
.static <FIELD,OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT>assertThat(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Deprecated.Create assertion forAtomicReferenceFieldUpdater
.static <VALUE> AtomicStampedReferenceAssert<VALUE>
assertThat(AtomicStampedReference<VALUE> actual)
Deprecated.Create assertion forAtomicStampedReference
.static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT>
assertThat(Future<RESULT> actual)
Deprecated.Create assertion forFuture
.static AbstractDateAssert<?>
assertThat(Date actual)
Deprecated.Creates a new instance of
.DateAssert
static <T> AbstractIteratorAssert<?,T>
assertThat(Iterator<? extends T> actual)
Deprecated.Creates a new instance of
.IteratorAssert
static <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)
Deprecated.Creates a new instance of
allowing 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>assertThat(List<? extends ELEMENT> actual, AssertFactory<ELEMENT,ELEMENT_ASSERT> assertFactory)
Deprecated.Creates a new instance of
allowing to navigate to anyFactoryBasedNavigableListAssert
List
element in order to perform assertions on it.static <T> AbstractListAssert<?,List<? extends T>,T,ObjectAssert<T>>
assertThat(List<? extends T> actual)
Deprecated.Creates a new instance of
.ListAssert
static <K,V>
MapAssert<K,V>assertThat(Map<K,V> actual)
Deprecated.Creates a new instance of
.MapAssert
static <T> T
assertThat(AssertProvider<T> component)
Deprecated.Delegates the creation of theAssert
to theAssertProvider.assertThat()
of the given component.static <T extends Comparable<? super T>>
AbstractComparableAssert<?,T>assertThat(T actual)
Deprecated.Creates a new instance of
with standard comparison semantics.GenericComparableAssert
static <T> AbstractObjectArrayAssert<?,T>
assertThat(T[] actual)
Deprecated.Creates a new instance of
.ObjectArrayAssert
static <T> Object2DArrayAssert<T>
assertThat(T[][] actual)
Deprecated.Creates a new instance of
.Object2DArrayAssert
static AbstractThrowableAssert<?,? extends Throwable>
assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Deprecated.Allows to capture and then assert on aThrowable
.<T> AbstractObjectAssert<?,T>
assertThatObject(T actual)
Deprecated.Creates a new instance of
for any object.ObjectAssert
static AbstractThrowableAssert<?,? extends Throwable>
assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Deprecated.Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.static AbstractThrowableAssert<?,? extends Throwable>
assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)
Deprecated.Allows to capture and then assert on aThrowable
likeassertThatThrownBy(ThrowingCallable)
but this method let you set the assertion description the same way you do withas(String, Object...)
.static Index
atIndex(int index)
Deprecated.Only delegate toIndex.atIndex(int)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useIndex
if you prefer).static Offset<Byte>
byLessThan(Byte value)
Deprecated.Assertions entry point for ByteOffset
to use with isCloseTo assertions.static Offset<Double>
byLessThan(Double value)
Deprecated.Alias foroffset(Double)
to use with isCloseTo assertions.static Offset<Float>
byLessThan(Float value)
Deprecated.Alias foroffset(Float)
to use with isCloseTo assertions.static Offset<Integer>
byLessThan(Integer value)
Deprecated.Assertions entry point for IntegerOffset
to use with isCloseTo assertions.static Offset<Long>
byLessThan(Long value)
Deprecated.Assertions entry point for LongOffset
to use with isCloseTo assertions.static Offset<Short>
byLessThan(Short value)
Deprecated.Assertions entry point for ShortOffset
to use with isCloseTo assertions.static Offset<BigDecimal>
byLessThan(BigDecimal value)
Deprecated.Assertions entry point for BigDecimalOffset
to use with isCloseTo assertions.static Offset<BigInteger>
byLessThan(BigInteger value)
Deprecated.Assertions entry point for BigIntegerOffset
to use with isCloseTo assertions.static Throwable
catchThrowable(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Deprecated.Allows to catch anThrowable
more easily when used with Java 8 lambdas.static <THROWABLE extends Throwable>
THROWABLEcatchThrowableOfType(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, Class<THROWABLE> type)
Deprecated.Allows catching aThrowable
of a specific type.static String
contentOf(File file)
Deprecated.Loads the text content of a file with the default character set, so that it can be passed toassertThat(String)
.static String
contentOf(File file, String charsetName)
Deprecated.Loads the text content of a file, so that it can be passed toassertThat(String)
.static String
contentOf(File file, Charset charset)
Deprecated.Loads the text content of a file, so that it can be passed toassertThat(String)
.static String
contentOf(URL url)
Deprecated.Loads the text content of a URL with the default character set, so that it can be passed toassertThat(String)
.static String
contentOf(URL url, String charsetName)
Deprecated.Loads the text content of a URL, so that it can be passed toassertThat(String)
.static String
contentOf(URL url, Charset charset)
Deprecated.Loads the text content of a URL, so that it can be passed toassertThat(String)
.static <T> DoesNotHave<T>
doesNotHave(Condition<? super T> condition)
Deprecated.Creates a new
.DoesNotHave
static <K,V>
MapEntry<K,V>entry(K key, V value)
Deprecated.Only delegate toMapEntry.entry(Object, Object)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useMapEntry
if you prefer).static Properties<Object>
extractProperty(String propertyName)
Deprecated.Only delegate toProperties.extractProperty(String)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useProperties
if you prefer).static <T> Properties<T>
extractProperty(String propertyName, Class<T> propertyType)
Deprecated.Only delegate toProperties.extractProperty(String)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useProperties
if you prefer).static void
fail(String failureMessage)
Deprecated.Throws anAssertionError
with the given message.static void
fail(String failureMessage, Object... args)
Deprecated.Throws anAssertionError
with the given message built asString.format(String, Object...)
.static void
fail(String failureMessage, Throwable realCause)
Deprecated.Throws anAssertionError
with the given message and with theThrowable
that caused the failure.static void
failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)
Deprecated.Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.static <E> Filters<E>
filter(E[] array)
Deprecated.Only delegate toFilters.filter(Object[])
so that Assertions offers a full feature entry point to all AssertJ features (but you can useFilters
if you prefer).static <E> Filters<E>
filter(Iterable<E> iterableToFilter)
Deprecated.Only delegate toFilters.filter(Object[])
so that Assertions offers a full feature entry point to all AssertJ features (but you can useFilters
if you prefer).static InFilter
in(Object... values)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches one of the given values.static List<String>
linesOf(File file)
Deprecated.Loads the text content of a file into a list of strings with the default charset, each string corresponding to a line.static List<String>
linesOf(File file, String charsetName)
Deprecated.Loads the text content of a file into a list of strings, each string corresponding to a line.static List<String>
linesOf(File file, Charset charset)
Deprecated.Loads the text content of a file into a list of strings, each string corresponding to a line.static List<String>
linesOf(URL url)
Deprecated.Loads the text content of a URL into a list of strings with the default charset, each string corresponding to a line.static List<String>
linesOf(URL url, String charsetName)
Deprecated.Loads the text content of a URL into a list of strings, each string corresponding to a line.static List<String>
linesOf(URL url, Charset charset)
Deprecated.Loads the text content of a URL into a list of strings, each string corresponding to a line.static NotFilter
not(Object valueNotToMatch)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches does not match the given value.static <T> Not<T>
not(Condition<? super T> condition)
Deprecated.Creates a new
.Not
static NotInFilter
notIn(Object... valuesNotToMatch)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches does not match any of the given values.static Offset<Double>
offset(Double value)
Deprecated.Assertions entry point for doubleOffset
.static Offset<Float>
offset(Float value)
Deprecated.Assertions entry point for floatOffset
.static void
registerCustomDateFormat(String userCustomDateFormatPattern)
Deprecated.Add the given date format to the ones used to parse date String in String based Date assertions likeAbstractDateAssert.isEqualTo(String)
.static void
registerCustomDateFormat(DateFormat userCustomDateFormat)
Deprecated.Add the given date format to the ones used to parse date String in String based Date assertions likeAbstractDateAssert.isEqualTo(String)
.static void
setAllowComparingPrivateFields(boolean allowComparingPrivateFields)
Deprecated.Globally sets whether the use of private fields is allowed for comparison.static void
setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
Deprecated.Globally sets whether
andIterableAssert#extracting(String)
should be allowed to extract private fields, if not and they try it fails with exception.ObjectArrayAssert#extracting(String)
static void
setLenientDateParsing(boolean value)
Deprecated.Instead of using default strict date/time parsing, it is possible to use lenient parsing mode for default date formats parser to interpret inputs that do not precisely match supported date formats (lenient parsing).static void
setMaxElementsForPrinting(int maxElementsForPrinting)
Deprecated.In error messages, sets the threshold for how many elements from one iterable/array/map will be included in the in the description.static void
setMaxLengthForSingleLineDescription(int maxLengthForSingleLineDescription)
Deprecated.In error messages, sets the threshold when iterable/array formatting will on one line (if their String description is less than this parameter) or it will be formatted with one element per line.static void
setMaxStackTraceElementsDisplayed(int maxStackTraceElementsDisplayed)
Deprecated.Sets how many stacktrace elements are included inThrowable
representation (by default this set to 3).static void
shouldHaveThrown(Class<? extends Throwable> throwableClass)
Deprecated.Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.static Tuple
tuple(Object... values)
Deprecated.Utility method to build nicely aTuple
when working withAbstractIterableAssert.extracting(String...)
orAbstractObjectArrayAssert.extracting(String...)
static void
useDefaultDateFormatsOnly()
Deprecated.Remove all registered custom date formats => use only the defaults date formats to parse string as date.static Offset<Byte>
within(Byte value)
Deprecated.Assertions entry point for ByteOffset
to use with isCloseTo assertions.static Offset<Double>
within(Double value)
Deprecated.Alias foroffset(Double)
to use with isCloseTo assertions.static Offset<Float>
within(Float value)
Deprecated.Alias foroffset(Float)
to use with isCloseTo assertions.static Offset<Integer>
within(Integer value)
Deprecated.Assertions entry point for IntegerOffset
to use with isCloseTo assertions.static Offset<Long>
within(Long value)
Deprecated.Assertions entry point for LongOffset
to use with isCloseTo assertions.static Offset<Short>
within(Short value)
Deprecated.Assertions entry point for ShortOffset
to use with isCloseTo assertions.static Offset<BigDecimal>
within(BigDecimal value)
Deprecated.Assertions entry point for BigDecimalOffset
to use with isCloseTo assertions.static Offset<BigInteger>
within(BigInteger value)
Deprecated.Assertions entry point for BigIntegerOffset
to use with isCloseTo assertions.static Percentage
withinPercentage(Double value)
Deprecated.Assertions entry point for DoublePercentage
to use with isCloseTo assertions for percentages.static Percentage
withinPercentage(Integer value)
Deprecated.Assertions entry point for IntegerPercentage
to use with isCloseTo assertions for percentages.static Percentage
withinPercentage(Long value)
Deprecated.Assertions entry point for LongPercentage
to use with isCloseTo assertions for percentages.
-
-
-
Method Detail
-
assertThat
public static AtomicBooleanAssert assertThat(AtomicBoolean actual)
Deprecated.Create assertion forAtomicBoolean
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static AtomicIntegerAssert assertThat(AtomicInteger actual)
Deprecated.Create assertion forAtomicInteger
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static AtomicIntegerArrayAssert assertThat(AtomicIntegerArray actual)
Deprecated.Create int[] assertion forAtomicIntegerArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> assertThat(AtomicIntegerFieldUpdater<OBJECT> actual)
Deprecated.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
-
assertThat
public static AtomicLongAssert assertThat(AtomicLong actual)
Deprecated.Create assertion forAtomicLong
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static AtomicLongArrayAssert assertThat(AtomicLongArray actual)
Deprecated.Create assertion forAtomicLongArray
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> assertThat(AtomicLongFieldUpdater<OBJECT> actual)
Deprecated.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
-
assertThat
public static <VALUE> AtomicReferenceAssert<VALUE> assertThat(AtomicReference<VALUE> actual)
Deprecated.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
-
assertThat
public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> assertThat(AtomicReferenceArray<ELEMENT> actual)
Deprecated.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
-
assertThat
public static <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> assertThat(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Deprecated.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
-
assertThat
public static <VALUE> AtomicMarkableReferenceAssert<VALUE> assertThat(AtomicMarkableReference<VALUE> actual)
Deprecated.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
-
assertThat
public static <VALUE> AtomicStampedReferenceAssert<VALUE> assertThat(AtomicStampedReference<VALUE> actual)
Deprecated.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
-
assertThat
public static AbstractBigDecimalAssert<?> assertThat(BigDecimal actual)
Deprecated.Creates a new instance of
.BigDecimalAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractBigIntegerAssert<?> assertThat(BigInteger actual)
Deprecated.Creates a new instance of
.BigIntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static AbstractUriAssert<?> assertThat(URI actual)
Deprecated.Creates a new instance of
.UriAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractUrlAssert<?> assertThat(URL actual)
Deprecated.Creates a new instance of
.UrlAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractBooleanAssert<?> assertThat(boolean actual)
Deprecated.Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractBooleanAssert<?> assertThat(Boolean actual)
Deprecated.Creates a new instance of
.BooleanAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractBooleanArrayAssert<?> assertThat(boolean[] actual)
Deprecated.Creates a new instance of
.BooleanArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Boolean2DArrayAssert assertThat(boolean[][] actual)
Deprecated.Creates a new instance of
.Boolean2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractByteAssert<?> assertThat(byte actual)
Deprecated.Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractByteAssert<?> assertThat(Byte actual)
Deprecated.Creates a new instance of
.ByteAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractByteArrayAssert<?> assertThat(byte[] actual)
Deprecated.Creates a new instance of
.ByteArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Byte2DArrayAssert assertThat(byte[][] actual)
Deprecated.Creates a new instance of
.Byte2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractCharacterAssert<?> assertThat(char actual)
Deprecated.Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractCharArrayAssert<?> assertThat(char[] actual)
Deprecated.Creates a new instance of
.CharArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Char2DArrayAssert assertThat(char[][] actual)
Deprecated.Creates a new instance of
.Char2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractCharacterAssert<?> assertThat(Character actual)
Deprecated.Creates a new instance of
.CharacterAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractClassAssert<?> assertThat(Class<?> actual)
Deprecated.Creates a new instance ofClassAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T extends Comparable<? super T>> AbstractComparableAssert<?,T> assertThat(T actual)
Deprecated.Creates a new instance of
with standard comparison semantics.GenericComparableAssert
- Type Parameters:
T
- the type of the actual value.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T> AbstractIterableAssert<?,Iterable<? extends T>,T,ObjectAssert<T>> assertThat(Iterable<? extends T> actual)
Deprecated.Creates a new instance of
.IterableAssert
- Type Parameters:
T
- the actual elements type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T> AbstractIteratorAssert<?,T> assertThat(Iterator<? extends T> actual)
Deprecated.Creates a new instance of
.IteratorAssert
Breaking change in version 3.12.0: this method does not return anymore an
IterableAssert
but anIteratorAssert
.
In order to access assertions fromIterableAssert
, useAbstractIteratorAssert.toIterable()
.IteratorAssert
instances have limited assertions because it does not consume iterator's elements.Examples:
Iterator<String> bestBasketBallPlayers = getBestBasketBallPlayers(); assertThat(bestBasketBallPlayers).hasNext() // Iterator assertion .toIterable() // switch to Iterable assertions .contains("Jordan", "Magic", "Lebron"); // Iterable assertion
- Type Parameters:
T
- the type of elements.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractDoubleAssert<?> assertThat(double actual)
Deprecated.Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractDoubleAssert<?> assertThat(Double actual)
Deprecated.Creates a new instance of
.DoubleAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractDoubleArrayAssert<?> assertThat(double[] actual)
Deprecated.Creates a new instance of
.DoubleArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Double2DArrayAssert assertThat(double[][] actual)
Deprecated.Creates a new instance of
.Double2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractFileAssert<?> assertThat(File actual)
Deprecated.Creates a new instance of
.FileAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> assertThat(Future<RESULT> actual)
Deprecated.Create assertion forFuture
.- Type Parameters:
RESULT
- the type of the value contained in theFuture
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 2.7.0 / 3.7.0
-
assertThat
public static AbstractInputStreamAssert<?,? extends InputStream> assertThat(InputStream actual)
Deprecated.Creates a new instance of
.InputStreamAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractFloatAssert<?> assertThat(float actual)
Deprecated.Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractFloatAssert<?> assertThat(Float actual)
Deprecated.Creates a new instance of
.FloatAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractFloatArrayAssert<?> assertThat(float[] actual)
Deprecated.Creates a new instance of
.FloatArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Float2DArrayAssert assertThat(float[][] actual)
Deprecated.Creates a new instance of
.Float2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractIntegerAssert<?> assertThat(int actual)
Deprecated.Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractIntArrayAssert<?> assertThat(int[] actual)
Deprecated.Creates a new instance of
.IntArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Int2DArrayAssert assertThat(int[][] actual)
Deprecated.Creates a new instance of
.Int2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractIntegerAssert<?> assertThat(Integer actual)
Deprecated.Creates a new instance of
.IntegerAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T> AbstractCollectionAssert<?,Collection<? extends T>,T,ObjectAssert<T>> assertThat(Collection<? extends T> actual)
Deprecated.Creates a new instance of
.CollectionAssert
- Type Parameters:
T
- the actual elements type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.21.0
-
assertThat
public static <T> AbstractListAssert<?,List<? extends T>,T,ObjectAssert<T>> assertThat(List<? extends T> actual)
Deprecated.Creates a new instance of
.ListAssert
- Type Parameters:
T
- the actual elements type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <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)
Deprecated.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() assertThat(hobbits, stringAssertFactory).first() .startsWith("fro") .endsWith("do");
- Type Parameters:
ACTUAL
- The actual typeELEMENT
- The actual elements typeELEMENT_ASSERT
- The actual elements AbstractAssert type- Parameters:
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.- Returns:
- the created assertion object.
-
assertThat
public static <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)
Deprecated.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() assertThat(hobbits, StringAssert.class).first() .startsWith("fro") .endsWith("do");
- Type Parameters:
ACTUAL
- The actual typeELEMENT
- The actual elements typeELEMENT_ASSERT
- The actual elements AbstractAssert type- Parameters:
actual
- the actual value.assertClass
- the class used to create the elements assert instance.- Returns:
- the created assertion object.
-
assertThat
public static <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)
Deprecated.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() assertThat(hobbits, stringAssertFactory).first() .startsWith("fro") .endsWith("do");
- Type Parameters:
ACTUAL
- The actual typeELEMENT
- The actual elements typeELEMENT_ASSERT
- The actual elements AbstractAssert type- Parameters:
actual
- the actual value.assertFactory
- the factory used to create the elements assert instance.- Returns:
- the created assertion object.
-
assertThat
public static <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)
Deprecated.Creates a new instance of
allowing 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() assertThat(hobbits, StringAssert.class).first() .startsWith("fro") .endsWith("do");
- Type Parameters:
ACTUAL
- The actual typeELEMENT
- The actual elements typeELEMENT_ASSERT
- The actual elements AbstractAssert type- Parameters:
actual
- the actual value.assertClass
- the class used to create the elements assert instance.- Returns:
- the created assertion object.
-
assertThat
public static AbstractLongAssert<?> assertThat(long actual)
Deprecated.Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractLongAssert<?> assertThat(Long actual)
Deprecated.Creates a new instance of
.LongAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractLongArrayAssert<?> assertThat(long[] actual)
Deprecated.Creates a new instance of
.LongArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Long2DArrayAssert assertThat(long[][] actual)
Deprecated.Creates a new instance of
.Long2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static <T> AbstractObjectAssert<?,T> assertThat(T actual)
Deprecated.Creates a new instance of
.ObjectAssert
- Type Parameters:
T
- the actual type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T extends AssertDelegateTarget> T assertThat(T assertion)
Deprecated.Returns the given assertion. This method improves code readability by surrounding the given assertion withassertThat
.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.assertThat assertThat(button.isBlinking()).isTrue(); } void isNotBlinking() { // standard assertion from core Assertions.assertThat assertThat(button.isBlinking()).isFalse(); } }
assertThat(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 assertThat assertThat(buttonAssert).isNotBlinking(); // same as : buttonAssert.isNotBlinking(); button.setBlinking(true); assertThat(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.
-
assertThat
public static <T> T assertThat(AssertProvider<T> component)
Deprecated.Delegates the creation of theAssert
to theAssertProvider.assertThat()
of the given component.Read the comments on
AssertProvider
for an example of its usage.- Type Parameters:
T
- the generic type of the assert provided by the component.- Parameters:
component
- the component that creates its own assert- Returns:
- the associated
Assert
of the given component
-
assertThat
public static <T> AbstractObjectArrayAssert<?,T> assertThat(T[] actual)
Deprecated.Creates a new instance of
.ObjectArrayAssert
- Type Parameters:
T
- the actual elements type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T> Object2DArrayAssert<T> assertThat(T[][] actual)
Deprecated.Creates a new instance of
.Object2DArrayAssert
- Type Parameters:
T
- the actual elements type- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static <K,V> MapAssert<K,V> assertThat(Map<K,V> actual)
Deprecated.Creates a new instance of
.MapAssert
Returned type is
MapAssert
as it overrides method to annotate them withSafeVarargs
avoiding annoying warnings.- Type Parameters:
K
- the type of keys in the map.V
- the type of values in the map.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractShortAssert<?> assertThat(short actual)
Deprecated.Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractShortAssert<?> assertThat(Short actual)
Deprecated.Creates a new instance of
.ShortAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractShortArrayAssert<?> assertThat(short[] actual)
Deprecated.Creates a new instance of
.ShortArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static Short2DArrayAssert assertThat(short[][] actual)
Deprecated.Creates a new instance of
.Short2DArrayAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
assertThat
public static AbstractCharSequenceAssert<?,? extends CharSequence> assertThat(CharSequence actual)
Deprecated.Creates a new instance of
.CharSequenceAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractCharSequenceAssert<?,? extends CharSequence> assertThat(StringBuilder actual)
Deprecated.Creates a new instance of
from aCharSequenceAssert
StringBuilder
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
assertThat
public static AbstractCharSequenceAssert<?,? extends CharSequence> assertThat(StringBuffer actual)
Deprecated.Creates a new instance of
from aCharSequenceAssert
StringBuffer
.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.11.0
-
assertThat
public static AbstractStringAssert<?> assertThat(String actual)
Deprecated.Creates a new instance of
.StringAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static AbstractDateAssert<?> assertThat(Date actual)
Deprecated.Creates a new instance of
.DateAssert
- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
-
assertThat
public static <T extends Throwable> AbstractThrowableAssert<?,T> assertThat(T actual)
Deprecated.Creates a new instance of
.ThrowableAssert
- Type Parameters:
T
- the type of the actual throwable.- Parameters:
actual
- the actual value.- Returns:
- the created
ThrowableAssert
.
-
assertThatThrownBy
public static AbstractThrowableAssert<?,? extends Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Deprecated.Allows to capture and then assert on aThrowable
more easily when used with Java 8 lambdas.Java 8 example :
@Test public void testException() { assertThatThrownBy(() -> { throw new Exception("boom!"); }).isInstanceOf(Exception.class) .hasMessageContaining("boom"); }
Java 7 example :
If the providedassertThatThrownBy(new ThrowingCallable() { @Override public void call() throws Exception { throw new Exception("boom!"); } }).isInstanceOf(Exception.class) .hasMessageContaining("boom");
ThrowableAssert.ThrowingCallable
does not raise an exception, an error is immediately thrown, in that case the test description provided withas(String, Object...)
is not honored.
To use a test description, usecatchThrowable(ThrowableAssert.ThrowingCallable)
as shown below.// assertion will fail but "display me" won't appear in the error assertThatThrownBy(() -> {}).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error Throwable thrown = catchThrowable(() -> {}); assertThat(thrown).as("display me") .isInstanceOf(Exception.class);
- 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.
-
assertThatThrownBy
public static AbstractThrowableAssert<?,? extends Throwable> assertThatThrownBy(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, String description, Object... args)
Deprecated.Allows to capture and then assert on aThrowable
likeassertThatThrownBy(ThrowingCallable)
but this method let you set the assertion description the same way you do withas(String, Object...)
.Example:
If the provided@Test public void testException() { // if this assertion failed (but it doesn't), the error message would start with [Test explosive code] assertThatThrownBy(() -> { throw new IOException("boom!") }, "Test explosive code") .isInstanceOf(IOException.class) .hasMessageContaining("boom"); }
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 assertThatThrownBy(() -> {}).as("display me") .isInstanceOf(Exception.class); // assertion will fail AND "display me" will appear in the error message assertThatThrownBy(() -> {}, "display me") .isInstanceOf(Exception.class);
- Parameters:
shouldRaiseThrowable
- TheThrowableAssert.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.- Returns:
- the created
ThrowableAssert
. - Since:
- 3.9.0
-
assertThatCode
public static AbstractThrowableAssert<?,? extends Throwable> assertThatCode(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
Deprecated.Allows to capture and then assert on aThrowable
.Example :
If the providedThrowingCallable callable = new ThrowingCallable() { @Override public void call() throws Throwable { 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 = new ThrowingCallable() { @Override public void call() throws Throwable { // 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
-
assertThatObject
public <T> AbstractObjectAssert<?,T> assertThatObject(T actual)
Deprecated.Creates a new instance of
for any object.ObjectAssert
This overload is useful, when an overloaded method of assertThat(...) takes precedence over the generic
assertThat(Object)
.Example:
Cast necessary because
assertThat(List)
"forgets" actual type:
No cast needed, but also no additional list assertions:assertThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));
assertThatObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc"));
- Type Parameters:
T
- the type of the actual value.- Parameters:
actual
- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.12.0
-
catchThrowable
public static Throwable catchThrowable(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
Deprecated.Allows to catch anThrowable
more easily when used with Java 8 lambdas.This caught
Throwable
can then be asserted.Java 8 example:
@Test public void testException() { // when Throwable thrown = catchThrowable(() -> { throw new Exception("boom!"); }); // then assertThat(thrown).isInstanceOf(Exception.class) .hasMessageContaining("boom"); }
Java 7 example:
@Test public void testException() { // when Throwable thrown = catchThrowable(new ThrowingCallable() { @Override public void call() throws Exception { throw new Exception("boom!"); } }) // then assertThat(thrown).isInstanceOf(Exception.class) .hasMessageContaining("boom"); }
- Parameters:
shouldRaiseThrowable
- The lambda with the code that should raise the exception.- Returns:
- The captured exception or
null
if none was raised by the callable.
-
catchThrowableOfType
public static <THROWABLE extends Throwable> THROWABLE catchThrowableOfType(ThrowableAssert.ThrowingCallable shouldRaiseThrowable, Class<THROWABLE> type)
Deprecated.Allows catching aThrowable
of a specific type.A call is made to
catchThrowable(ThrowingCallable)
, if no exception is throwncatchThrowableOfType
returns null, otherwise it checks that the caughtThrowable
has the specified type then casts it to it before returning it, making it convenient to perform subtype-specific assertions on the result.Example:
class CustomParseException extends Exception { int line; int column; public CustomParseException(String msg, int l, int c) { super(msg); line = l; column = c; } } CustomParseException e = catchThrowableOfType(() -> { throw new CustomParseException("boom!", 1, 5); }, CustomParseException.class); // assertions pass assertThat(e).hasMessageContaining("boom"); assertThat(e.line).isEqualTo(1); assertThat(e.column).isEqualTo(5); // fails as CustomParseException is not a RuntimeException catchThrowableOfType(() -> { throw new CustomParseException("boom!", 1, 5); }, RuntimeException.class);
- Type Parameters:
THROWABLE
- theThrowable
type.- Parameters:
shouldRaiseThrowable
- The lambda with the code that should raise the exception.type
- The type of exception that the code is expected to raise.- Returns:
- The captured exception or
null
if none was raised by the callable. - Since:
- 3.9.0
- See Also:
catchThrowable(ThrowableAssert.ThrowingCallable)
-
fail
public static void fail(String failureMessage)
Deprecated.Throws anAssertionError
with the given message.- Parameters:
failureMessage
- error message.- Throws:
AssertionError
- with the given message.
-
fail
public static void fail(String failureMessage, Object... args)
Deprecated.Throws anAssertionError
with the given message built asString.format(String, Object...)
.- Parameters:
failureMessage
- error message.args
- Arguments referenced by the format specifiers in the format string.- Throws:
AssertionError
- with the given built message.
-
fail
public static void fail(String failureMessage, Throwable realCause)
Deprecated.Throws anAssertionError
with the given message and with theThrowable
that caused the failure.- Parameters:
failureMessage
- the description of the failed assertion. It can benull
.realCause
- cause of the error.- Throws:
AssertionError
- with the given message and with theThrowable
that caused the failure.
-
failBecauseExceptionWasNotThrown
public static void failBecauseExceptionWasNotThrown(Class<? extends Throwable> throwableClass)
Deprecated.Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.Assertions.shouldHaveThrown(Class)
can be used as a replacement.- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.
-
shouldHaveThrown
public static void shouldHaveThrown(Class<? extends Throwable> throwableClass)
Deprecated.Throws anAssertionError
with a message explaining that aThrowable
of given class was expected to be thrown but had not been.- Parameters:
throwableClass
- the Throwable class that was expected to be thrown.- Throws:
AssertionError
- with a message explaining that aThrowable
of given class was expected to be thrown but had not been.
-
setMaxLengthForSingleLineDescription
public static void setMaxLengthForSingleLineDescription(int maxLengthForSingleLineDescription)
Deprecated.In error messages, sets the threshold when iterable/array formatting will on one line (if their String description is less than this parameter) or it will be formatted with one element per line.The following array will be formatted on one line as its length < 80:
whereas this array is formatted on multiple lines (one element per line):String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"); // formatted as: ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]
String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards! (Discworld)"); // formatted as: ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards! (Discworld)"]
- Parameters:
maxLengthForSingleLineDescription
- the maximum length for an iterable/array to be displayed on one line
-
setMaxElementsForPrinting
public static void setMaxElementsForPrinting(int maxElementsForPrinting)
Deprecated.In error messages, sets the threshold for how many elements from one iterable/array/map will be included in the in the description. E.q. When this method is called with a value of3
.The following array will be formatted entirely as it's length is <= 3:
whereas this array is formatted only with it's first 3 elements, followed byString[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"); // formatted as: ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice"]
...
:String[] greatBooks = array("A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", "Guards! Guards!"); // formatted as: ["A Game of Thrones", "The Lord of the Rings", "Assassin's Apprentice", ...]
- Parameters:
maxElementsForPrinting
- the maximum elements that would be printed from one iterable/array/map- Since:
- 2.6.0 / 3.6.0
-
setMaxStackTraceElementsDisplayed
public static void setMaxStackTraceElementsDisplayed(int maxStackTraceElementsDisplayed)
Deprecated.Sets how many stacktrace elements are included inThrowable
representation (by default this set to 3).Examples:
static class Test1 { static void boom() { Test2.boom2(); } static class Test2 { static void boom2() { throw new RuntimeException(); } } }
Test1.boom()
exception should be represented like this in error messages:java.lang.RuntimeException at org.assertj.core.presentation.Test1$Test2.boom2(StandardRepresentation_throwable_format_Test.java:35) at org.assertj.core.presentation.Test1.boom(StandardRepresentation_throwable_format_Test.java:40);java.lang.RuntimeException at org.assertj.core.presentation.Test1.lambda$1(StandardRepresentation_throwable_format_Test.java:63)org.assertj.core.util.Throwables_Description_Test$test1$test2.exception_layer_2(Throwables_Description_Test.java:24) ...(69 remaining lines not displayed - this can be changed with Assertions.setMaxStackTraceElementsDisplayed)org.assertj.core.util.Throwables_Description_Test$test1.exception_layer_1(Throwables_Description_Test.java:30)
- Parameters:
maxStackTraceElementsDisplayed
- the maximum number of lines for a stacktrace to be displayed on one throw.- Since:
- 3.19.0
- See Also:
Configuration
-
extractProperty
public static <T> Properties<T> extractProperty(String propertyName, Class<T> propertyType)
Deprecated.Only delegate toProperties.extractProperty(String)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useProperties
if you prefer).Typical usage is to chain
extractProperty
withfrom
method, see examples below :// extract simple property values having a java standard type (here String) assertThat(extractProperty("name", String.class).from(fellowshipOfTheRing)).contains(" Boromir", "Gandalf", "Frodo", "Legolas").doesNotContain("Sauron", "Elrond"); // extracting property works also with user's types (here Race) assertThat(extractProperty("race", String.class).from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC); // extract nested property on Race assertThat(extractProperty("race.name", String.class).from(fellowshipOfTheRing)).contains(" Hobbit", "Elf") .doesNotContain("Orc");
- Type Parameters:
T
- the type of value to extract.- Parameters:
propertyName
- the name of the property to be read from the elements of aIterable
. It may be a nested property (e.g. "address.street.number").propertyType
- the type of property to extract- Returns:
- the created
Properties
. - Throws:
NullPointerException
- if the given property name isnull
.IllegalArgumentException
- if the given property name is empty.
-
extractProperty
public static Properties<Object> extractProperty(String propertyName)
Deprecated.Only delegate toProperties.extractProperty(String)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useProperties
if you prefer).Typical usage is to chain
extractProperty
withfrom
method, see examples below :// extract simple property values, as no type has been defined the extracted property will be considered as Object // to define the real property type (here String) use extractProperty("name", String.class) instead. assertThat(extractProperty("name").from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", "Frodo", "Legolas") .doesNotContain("Sauron", "Elrond"); // extracting property works also with user's types (here Race), even though it will be considered as Object // to define the real property type (here String) use extractProperty("name", Race.class) instead. assertThat(extractProperty("race").from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC); // extract nested property on Race assertThat(extractProperty("race.name").from(fellowshipOfTheRing)).contains("Hobbit", "Elf").doesNotContain("Orc");
- Parameters:
propertyName
- the name of the property to be read from the elements of aIterable
. It may be a nested property (e.g. "address.street.number").- Returns:
- the created
Properties
. - Throws:
NullPointerException
- if the given property name isnull
.IllegalArgumentException
- if the given property name is empty.
-
tuple
public static Tuple tuple(Object... values)
Deprecated.Utility method to build nicely aTuple
when working withAbstractIterableAssert.extracting(String...)
orAbstractObjectArrayAssert.extracting(String...)
-
setAllowExtractingPrivateFields
public static void setAllowExtractingPrivateFields(boolean allowExtractingPrivateFields)
Deprecated.Globally sets whether
andIterableAssert#extracting(String)
should be allowed to extract private fields, if not and they try it fails with exception.ObjectArrayAssert#extracting(String)
- Parameters:
allowExtractingPrivateFields
- allow private fields extraction. Defaulttrue
.
-
setAllowComparingPrivateFields
public static void setAllowComparingPrivateFields(boolean allowComparingPrivateFields)
Deprecated.Globally sets whether the use of private fields is allowed for comparison. The following (incomplete) list of methods will be impacted by this change :-
AbstractIterableAssert.usingElementComparatorOnFields(java.lang.String...)
AbstractObjectAssert.isEqualToComparingFieldByField(Object)
false
and these methods try to compare private fields, it will fail with an exception.- Parameters:
allowComparingPrivateFields
- allow private fields comparison. Defaulttrue
.
-
-
entry
public static <K,V> MapEntry<K,V> entry(K key, V value)
Deprecated.Only delegate toMapEntry.entry(Object, Object)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useMapEntry
if you prefer).Typical usage is to call
entry
in MapAssertcontains
assertion, see examples below :Map<Ring, TolkienCharacter> ringBearers = ... // init omitted assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
- Type Parameters:
K
- the type of keys in the map.V
- the type of values in the map.- Parameters:
key
- the key of the entry to create.value
- the value of the entry to create.- Returns:
- the created
MapEntry
.
-
atIndex
public static Index atIndex(int index)
Deprecated.Only delegate toIndex.atIndex(int)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useIndex
if you prefer).Typical usage :
List<Ring> elvesRings = newArrayList(vilya, nenya, narya); assertThat(elvesRings).contains(vilya, atIndex(0)).contains(nenya, atIndex(1)).contains(narya, atIndex(2));
- Parameters:
index
- the value of the index.- Returns:
- the created
Index
. - Throws:
IllegalArgumentException
- if the given value is negative.
-
offset
public static Offset<Double> offset(Double value)
Deprecated.Assertions entry point for doubleOffset
.Typical usage :
assertThat(8.1).isEqualTo(8.0, offset(0.1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
offset
public static Offset<Float> offset(Float value)
Deprecated.Assertions entry point for floatOffset
.Typical usage :
assertThat(8.2f).isCloseTo(8.0f, offset(0.2f));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<Double> within(Double value)
Deprecated.Alias foroffset(Double)
to use with isCloseTo assertions.Typical usage :
assertThat(8.1).isCloseTo(8.0, within(0.1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<Float> within(Float value)
Deprecated.Alias foroffset(Float)
to use with isCloseTo assertions.Typical usage :
assertThat(8.2f).isCloseTo(8.0f, within(0.2f));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<BigDecimal> within(BigDecimal value)
Deprecated.Assertions entry point for BigDecimalOffset
to use with isCloseTo assertions.Typical usage :
assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), within(BigDecimal.ONE));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<BigInteger> within(BigInteger value)
Deprecated.Assertions entry point for BigIntegerOffset
to use with isCloseTo assertions.Typical usage :
assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), within(new BigInteger("2")));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.- Since:
- 2.7.0 / 3.7.0
-
within
public static Offset<Byte> within(Byte value)
Deprecated.Assertions entry point for ByteOffset
to use with isCloseTo assertions.Typical usage :
assertThat((byte) 10).isCloseTo((byte) 11, within((byte) 1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<Integer> within(Integer value)
Deprecated.Assertions entry point for IntegerOffset
to use with isCloseTo assertions.Typical usage :
assertThat(10).isCloseTo(11, within(1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<Short> within(Short value)
Deprecated.Assertions entry point for ShortOffset
to use with isCloseTo assertions.Typical usage :
assertThat(10).isCloseTo(11, within(1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
within
public static Offset<Long> within(Long value)
Deprecated.Assertions entry point for LongOffset
to use with isCloseTo assertions.Typical usage :
assertThat(5l).isCloseTo(7l, within(2l));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<Double> byLessThan(Double value)
Deprecated.Alias foroffset(Double)
to use with isCloseTo assertions.Typical usage :
assertThat(8.1).isCloseTo(8.0, byLessThan(0.1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<Float> byLessThan(Float value)
Deprecated.Alias foroffset(Float)
to use with isCloseTo assertions.Typical usage :
assertThat(8.2f).isCloseTo(8.0f, byLessThan(0.2f));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<BigDecimal> byLessThan(BigDecimal value)
Deprecated.Assertions entry point for BigDecimalOffset
to use with isCloseTo assertions.Typical usage :
assertThat(BigDecimal.TEN).isCloseTo(new BigDecimal("10.5"), byLessThan(BigDecimal.ONE));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<BigInteger> byLessThan(BigInteger value)
Deprecated.Assertions entry point for BigIntegerOffset
to use with isCloseTo assertions.Typical usage :
assertThat(BigInteger.TEN).isCloseTo(new BigInteger("11"), byLessThan(new BigInteger("2")));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.- Since:
- 2.7.0 / 3.7.0
-
byLessThan
public static Offset<Byte> byLessThan(Byte value)
Deprecated.Assertions entry point for ByteOffset
to use with isCloseTo assertions.Typical usage :
assertThat((byte) 10).isCloseTo((byte) 11, byLessThan((byte) 1));
- Parameters:
value
- the allowed offset- Returns:
- the created
Offset
.
-
byLessThan
public static Offset<Integer> byLessThan(Integer value)
Deprecated.Assertions entry point for IntegerOffset
to use with isCloseTo assertions.Typical usage :
assertThat(10).isCloseTo(11, byLessThan(1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<Short> byLessThan(Short value)
Deprecated.Assertions entry point for ShortOffset
to use with isCloseTo assertions.Typical usage :
assertThat(10).isCloseTo(11, byLessThan(1));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
byLessThan
public static Offset<Long> byLessThan(Long value)
Deprecated.Assertions entry point for LongOffset
to use with isCloseTo assertions.Typical usage :
assertThat(5l).isCloseTo(7l, byLessThan(2l));
- Parameters:
value
- the value of the offset.- Returns:
- the created
Offset
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
withinPercentage
public static Percentage withinPercentage(Double value)
Deprecated.Assertions entry point for DoublePercentage
to use with isCloseTo assertions for percentages.Typical usage :
assertThat(11.0).isCloseTo(10.0, withinPercentage(10.0));
- Parameters:
value
- the value of the percentage.- Returns:
- the created
Percentage
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
withinPercentage
public static Percentage withinPercentage(Integer value)
Deprecated.Assertions entry point for IntegerPercentage
to use with isCloseTo assertions for percentages.Typical usage :
assertThat(11).isCloseTo(10, withinPercentage(10));
- Parameters:
value
- the value of the percentage.- Returns:
- the created
Percentage
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
withinPercentage
public static Percentage withinPercentage(Long value)
Deprecated.Assertions entry point for LongPercentage
to use with isCloseTo assertions for percentages.Typical usage :
assertThat(11L).isCloseTo(10L, withinPercentage(10L));
- Parameters:
value
- the value of the percentage.- Returns:
- the created
Percentage
. - Throws:
NullPointerException
- if the given value isnull
.IllegalArgumentException
- if the given value is negative.
-
allOf
@SafeVarargs public static <T> Condition<T> allOf(Condition<? super T>... conditions)
Deprecated.Creates a newAllOf
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
conditions
- the conditions to evaluate.- Returns:
- the created
AllOf
. - Throws:
NullPointerException
- if the given array isnull
.NullPointerException
- if any of the elements in the given array isnull
.
-
allOf
public static <T> Condition<T> allOf(Iterable<? extends Condition<? super T>> conditions)
Deprecated.Creates a newAllOf
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
conditions
- the conditions to evaluate.- Returns:
- the created
AllOf
. - Throws:
NullPointerException
- if the given iterable isnull
.NullPointerException
- if any of the elements in the given iterable isnull
.
-
anyOf
@SafeVarargs public static <T> Condition<T> anyOf(Condition<? super T>... conditions)
Deprecated.Only delegate toAnyOf.anyOf(Condition...)
so that Assertions offers a full feature entry point to all AssertJ features (but you can useAnyOf
if you prefer).Typical usage (
jedi
andsith
areCondition
) :assertThat("Vader").is(anyOf(jedi, sith));
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
conditions
- the conditions to evaluate.- Returns:
- the created
AnyOf
. - Throws:
NullPointerException
- if the given array isnull
.NullPointerException
- if any of the elements in the given array isnull
.
-
anyOf
public static <T> Condition<T> anyOf(Iterable<? extends Condition<? super T>> conditions)
Deprecated.Creates a newAnyOf
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
conditions
- the conditions to evaluate.- Returns:
- the created
AnyOf
. - Throws:
NullPointerException
- if the given iterable isnull
.NullPointerException
- if any of the elements in the given iterable isnull
.
-
doesNotHave
public static <T> DoesNotHave<T> doesNotHave(Condition<? super T> condition)
Deprecated.Creates a new
.DoesNotHave
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
condition
- the condition to inverse.- Returns:
- The Not condition created.
-
not
public static <T> Not<T> not(Condition<? super T> condition)
Deprecated.Creates a new
.Not
- Type Parameters:
T
- the type of object the given condition accept.- Parameters:
condition
- the condition to inverse.- Returns:
- The Not condition created.
-
filter
public static <E> Filters<E> filter(E[] array)
Deprecated.Only delegate toFilters.filter(Object[])
so that Assertions offers a full feature entry point to all AssertJ features (but you can useFilters
if you prefer).Note that the given array is not modified, the filters are performed on an
Iterable
copy of the array.Typical usage with
Condition
:assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
and with filter language based on java bean property :
assertThat(filter(players).with("pointsPerGame").greaterThan(20).and("assistsPerGame") .greaterThan(7).get()).containsOnly(james, rose);
- Type Parameters:
E
- the array elements type.- Parameters:
array
- the array to filter.- Returns:
- the created
.Filters
- Throws:
NullPointerException
- if the given array isnull
.
-
filter
public static <E> Filters<E> filter(Iterable<E> iterableToFilter)
Deprecated.Only delegate toFilters.filter(Object[])
so that Assertions offers a full feature entry point to all AssertJ features (but you can useFilters
if you prefer).Note that the given
Iterable
is not modified, the filters are performed on a copy.Typical usage with
Condition
:assertThat(filter(players).being(potentialMVP).get()).containsOnly(james, rose);
and with filter language based on java bean property :
assertThat(filter(players).with("pointsPerGame").greaterThan(20) .and("assistsPerGame").greaterThan(7).get()) .containsOnly(james, rose);
- Type Parameters:
E
- the iterable elements type.- Parameters:
iterableToFilter
- theIterable
to filter.- Returns:
- the created
.Filters
- Throws:
NullPointerException
- if the given iterable isnull
.
-
in
public static InFilter in(Object... values)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches one of the given values.As often, an example helps:
Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); List<Employee> employees = newArrayList(yoda, luke, obiwan, noname); assertThat(employees).filteredOn("age", in(800, 26)) .containsOnly(yoda, obiwan, luke);
- Parameters:
values
- values to match (one match is sufficient)- Returns:
- the created "in" filter
-
notIn
public static NotInFilter notIn(Object... valuesNotToMatch)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches does not match any of the given values.As often, an example helps:
Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); List<Employee> employees = newArrayList(yoda, luke, obiwan, noname); assertThat(employees).filteredOn("age", notIn(800, 50)) .containsOnly(luke);
- Parameters:
valuesNotToMatch
- values not to match (none of the values must match)- Returns:
- the created "not in" filter
-
not
public static NotFilter not(Object valueNotToMatch)
Deprecated.Create aFilterOperator
to use infilteredOn(String, FilterOperation)
to express a filter keeping all Iterable elements whose property/field value matches does not match the given value.As often, an example helps:
Employee yoda = new Employee(1L, new Name("Yoda"), 800); Employee obiwan = new Employee(2L, new Name("Obiwan"), 800); Employee luke = new Employee(3L, new Name("Luke", "Skywalker"), 26); Employee noname = new Employee(4L, null, 50); List<Employee> employees = newArrayList(yoda, luke, obiwan, noname); assertThat(employees).filteredOn("age", not(800)) .containsOnly(luke, noname);
- Parameters:
valueNotToMatch
- the value not to match- Returns:
- the created "not" filter
-
contentOf
public static String contentOf(File file, Charset charset)
Deprecated.Loads the text content of a file, so that it can be passed toassertThat(String)
.Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
assertThat(File)
.- Parameters:
file
- the file.charset
- the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
public static String contentOf(File file, String charsetName)
Deprecated.Loads the text content of a file, so that it can be passed toassertThat(String)
.Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
assertThat(File)
.- Parameters:
file
- the file.charsetName
- the name of the character set to use.- Returns:
- the content of the file.
- Throws:
IllegalArgumentException
- if the given character set is not supported on this platform.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
public static String contentOf(File file)
Deprecated.Loads the text content of a file with the default character set, so that it can be passed toassertThat(String)
.Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with
assertThat(File)
.- Parameters:
file
- the file.- Returns:
- the content of the file.
- Throws:
UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(File file)
Deprecated.Loads the text content of a file into a list of strings with the default charset, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
file
- the file.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(File file, Charset charset)
Deprecated.Loads the text content of a file into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
file
- the file.charset
- the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(File file, String charsetName)
Deprecated.Loads the text content of a file into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
file
- the file.charsetName
- the name of the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
public static String contentOf(URL url, Charset charset)
Deprecated.Loads the text content of a URL, so that it can be passed toassertThat(String)
.Note that this will load the entire contents in memory.
- Parameters:
url
- the URL.charset
- the character set to use.- Returns:
- the content of the URL.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
public static String contentOf(URL url, String charsetName)
Deprecated.Loads the text content of a URL, so that it can be passed toassertThat(String)
.Note that this will load the entire contents in memory.
- Parameters:
url
- the URL.charsetName
- the name of the character set to use.- Returns:
- the content of the URL.
- Throws:
IllegalArgumentException
- if the given character set is not supported on this platform.UncheckedIOException
- if an I/O exception occurs.
-
contentOf
public static String contentOf(URL url)
Deprecated.Loads the text content of a URL with the default character set, so that it can be passed toassertThat(String)
.Note that this will load the entire file in memory; for larger files.
- Parameters:
url
- the URL.- Returns:
- the content of the file.
- Throws:
UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(URL url)
Deprecated.Loads the text content of a URL into a list of strings with the default charset, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
url
- the URL.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(URL url, Charset charset)
Deprecated.Loads the text content of a URL into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
url
- the URL.charset
- the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
linesOf
public static List<String> linesOf(URL url, String charsetName)
Deprecated.Loads the text content of a URL into a list of strings, each string corresponding to a line. The line endings are either \n, \r or \r\n.- Parameters:
url
- the URL.charsetName
- the name of the character set to use.- Returns:
- the content of the file.
- Throws:
NullPointerException
- if the given charset isnull
.UncheckedIOException
- if an I/O exception occurs.
-
setLenientDateParsing
public static void setLenientDateParsing(boolean value)
Deprecated.Instead of using default strict date/time parsing, it is possible to use lenient parsing mode for default date formats parser to interpret inputs that do not precisely match supported date formats (lenient parsing).With strict parsing, inputs must match exactly date/time format.
Example:
To revert to default strict date parsing, callfinal Date date = Dates.parse("2001-02-03"); final Date dateTime = parseDatetime("2001-02-03T04:05:06"); final Date dateTimeWithMs = parseDatetimeWithMs("2001-02-03T04:05:06.700"); Assertions.setLenientDateParsing(true); // assertions will pass assertThat(date).isEqualTo("2001-01-34"); assertThat(date).isEqualTo("2001-02-02T24:00:00"); assertThat(date).isEqualTo("2001-02-04T-24:00:00.000"); assertThat(dateTime).isEqualTo("2001-02-03T04:05:05.1000"); assertThat(dateTime).isEqualTo("2001-02-03T04:04:66"); assertThat(dateTimeWithMs).isEqualTo("2001-02-03T04:05:07.-300"); // assertions will fail assertThat(date).hasSameTimeAs("2001-02-04"); // different date assertThat(dateTime).hasSameTimeAs("2001-02-03 04:05:06"); // leniency does not help here
setLenientDateParsing(false)
.- Parameters:
value
- whether lenient parsing mode should be enabled or not
-
registerCustomDateFormat
public static void registerCustomDateFormat(DateFormat userCustomDateFormat)
Deprecated.Add the given date format to the ones used to parse date String in String based Date assertions likeAbstractDateAssert.isEqualTo(String)
.User date formats are used before default ones in the order they have been registered (first registered, first used).
AssertJ is gonna use any date formats registered with one of these methods :
AbstractDateAssert.withDateFormat(String)
AbstractDateAssert.withDateFormat(java.text.DateFormat)
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
Beware that AssertJ will use the newly registered format for all remaining Date assertions in the test suite
To revert to default formats only, call
useDefaultDateFormatsOnly()
orAbstractDateAssert.withDefaultDateFormatsOnly()
.Code examples:
Date date = ... // set to 2003 April the 26th assertThat(date).isEqualTo("2003-04-26"); try { // date with a custom format : failure since the default formats don't match. assertThat(date).isEqualTo("2003/04/26"); } catch (AssertionError e) { assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " + "[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]"); } // registering a custom date format to make the assertion pass registerCustomDateFormat(new SimpleDateFormat("yyyy/MM/dd")); // registerCustomDateFormat("yyyy/MM/dd") would work to. assertThat(date).isEqualTo("2003/04/26"); // the default formats are still available and should work assertThat(date).isEqualTo("2003-04-26");
- Parameters:
userCustomDateFormat
- the new Date format used for String based Date assertions.
-
registerCustomDateFormat
public static void registerCustomDateFormat(String userCustomDateFormatPattern)
Deprecated.Add the given date format to the ones used to parse date String in String based Date assertions likeAbstractDateAssert.isEqualTo(String)
.User date formats are used before default ones in the order they have been registered (first registered, first used).
AssertJ is gonna use any date formats registered with one of these methods :
AbstractDateAssert.withDateFormat(String)
AbstractDateAssert.withDateFormat(java.text.DateFormat)
registerCustomDateFormat(java.text.DateFormat)
registerCustomDateFormat(String)
Beware that AssertJ will use the newly registered format for all remaining Date assertions in the test suite
To revert to default formats only, call
useDefaultDateFormatsOnly()
orAbstractDateAssert.withDefaultDateFormatsOnly()
.Code examples:
Date date = ... // set to 2003 April the 26th assertThat(date).isEqualTo("2003-04-26"); try { // date with a custom format : failure since the default formats don't match. assertThat(date).isEqualTo("2003/04/26"); } catch (AssertionError e) { assertThat(e).hasMessage("Failed to parse 2003/04/26 with any of these date formats: " + "[yyyy-MM-dd'T'HH:mm:ss.SSS, yyyy-MM-dd'T'HH:mm:ss, yyyy-MM-dd]"); } // registering a custom date format to make the assertion pass registerCustomDateFormat("yyyy/MM/dd"); assertThat(date).isEqualTo("2003/04/26"); // the default formats are still available and should work assertThat(date).isEqualTo("2003-04-26");
- Parameters:
userCustomDateFormatPattern
- the new Date format pattern used for String based Date assertions.
-
useDefaultDateFormatsOnly
public static void useDefaultDateFormatsOnly()
Deprecated.Remove all registered custom date formats => use only the defaults date formats to parse string as date.Beware that the default formats are expressed in the current local timezone.
Defaults date format are:
yyyy-MM-dd'T'HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss.SSS
(forTimestamp
String representation support)yyyy-MM-dd'T'HH:mm:ss
yyyy-MM-dd
Example of valid string date representations:
2003-04-26T03:01:02.999
2003-04-26 03:01:02.999
2003-04-26T13:01:02
2003-04-26
-
-