|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.fest.assertions.api.Assertions
public class Assertions
Entry point for assertion methods for different data types. Each method in this class is a static factory for the type-specific assertion objects. The purpose of this class is to make test code more readable.
For example:
int removed = employees.removeFired();assertThat
(removed).isZero
(); List<Employee> newEmployees = employees.hired(TODAY);assertThat
(newEmployees).hasSize
(6);
Constructor Summary | |
---|---|
protected |
Assertions()
Creates a new Assertions . |
Method Summary | ||
---|---|---|
static
|
anyOf(Collection<Condition<T>> conditions)
Creates a new
|
|
static
|
anyOf(Condition<T>... conditions)
Only delegate to AnyOf.anyOf(Condition...) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use AnyOf if you prefer). |
|
static BigDecimalAssert |
assertThat(BigDecimal actual)
Creates a new instance of . |
|
static BooleanAssert |
assertThat(boolean actual)
Creates a new instance of . |
|
static BooleanAssert |
assertThat(Boolean actual)
Creates a new instance of . |
|
static BooleanArrayAssert |
assertThat(boolean[] actual)
Creates a new instance of . |
|
static ImageAssert |
assertThat(BufferedImage actual)
Creates a new instance of . |
|
static ByteAssert |
assertThat(byte actual)
Creates a new instance of . |
|
static ByteAssert |
assertThat(Byte actual)
Creates a new instance of . |
|
static ByteArrayAssert |
assertThat(byte[] actual)
Creates a new instance of . |
|
static CharacterAssert |
assertThat(char actual)
Creates a new instance of . |
|
static CharArrayAssert |
assertThat(char[] actual)
Creates a new instance of . |
|
static CharacterAssert |
assertThat(Character actual)
Creates a new instance of . |
|
static DateAssert |
assertThat(Date actual)
Creates a new instance of . |
|
static DoubleAssert |
assertThat(double actual)
Creates a new instance of . |
|
static DoubleAssert |
assertThat(Double actual)
Creates a new instance of . |
|
static DoubleArrayAssert |
assertThat(double[] actual)
Creates a new instance of . |
|
static FileAssert |
assertThat(File actual)
Creates a new instance of . |
|
static FloatAssert |
assertThat(float actual)
Creates a new instance of . |
|
static FloatAssert |
assertThat(Float actual)
Creates a new instance of . |
|
static FloatArrayAssert |
assertThat(float[] actual)
Creates a new instance of . |
|
static InputStreamAssert |
assertThat(InputStream actual)
Creates a new instance of . |
|
static IntegerAssert |
assertThat(int actual)
Creates a new instance of . |
|
static IntArrayAssert |
assertThat(int[] actual)
Creates a new instance of . |
|
static IntegerAssert |
assertThat(Integer actual)
Creates a new instance of . |
|
static IterableAssert |
assertThat(Iterable<?> actual)
Creates a new instance of . |
|
static ListAssert |
assertThat(List<?> actual)
Creates a new instance of . |
|
static LongAssert |
assertThat(long actual)
Creates a new instance of . |
|
static LongAssert |
assertThat(Long actual)
Creates a new instance of . |
|
static LongArrayAssert |
assertThat(long[] actual)
Creates a new instance of . |
|
static MapAssert |
assertThat(Map<?,?> actual)
Creates a new instance of . |
|
static ObjectAssert |
assertThat(Object actual)
Creates a new instance of . |
|
static ObjectArrayAssert |
assertThat(Object[] actual)
Creates a new instance of . |
|
static ShortAssert |
assertThat(short actual)
Creates a new instance of . |
|
static ShortAssert |
assertThat(Short actual)
Creates a new instance of . |
|
static ShortArrayAssert |
assertThat(short[] actual)
Creates a new instance of . |
|
static StringAssert |
assertThat(String actual)
Creates a new instance of . |
|
static ThrowableAssert |
assertThat(Throwable actual)
Creates a new instance of . |
|
static Index |
atIndex(int index)
Only delegate to Index.atIndex(int) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Index if you prefer). |
|
static MapEntry |
entry(Object key,
Object value)
Only delegate to MapEntry.entry(Object, Object) so that Assertions offers a full feature entry point to all
Fest Assert features (but you can use MapEntry if you prefer). |
|
static Properties |
extractProperty(String propertyName)
Only delegate to Properties.extractProperty(String) so that Assertions offers a full feature entry point to
all Fest Assert features (but you can use Properties if you prefer). |
|
static void |
fail(String failureMessage)
Only delegate to Fail.fail(String) so that Assertions offers a full feature entry point to all Fest Assert
features (but you can use Fail if you prefer). |
|
static void |
fail(String failureMessage,
Throwable realCause)
Only delegate to Fail.fail(String, Throwable) so that Assertions offers a full feature entry point to all
Fest Assert features (but you can use Fail if you prefer). |
|
static void |
failBecauseExceptionWasNotThrown(Class<? extends Exception> exceptionClass)
Only delegate to Fail.failBecauseExceptionWasNotThrown(Class) so that Assertions offers a full feature
entry point to all Fest Assert features (but you can use Fail if you prefer). |
|
static
|
filter(E[] array)
Only delegate to Filters.filter(Object[]) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Filters if you prefer). |
|
static
|
filter(Iterable<E> iterableToFilter)
Only delegate to Filters.filter(Object[]) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Filters if you prefer). |
|
static Offset<Double> |
offset(Double value)
Only delegate to Offset.offset(Double) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Offset if you prefer). |
|
static Offset<Float> |
offset(Float value)
Only delegate to Offset.offset(Float) so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Offset if you prefer). |
|
static void |
setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)
Only delegate to Fail.setRemoveFestRelatedElementsFromStackTrace(boolean) so that Assertions offers a full
feature entry point to all Fest Assert features (but you can use Fail if you prefer). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected Assertions()
Assertions
.
Method Detail |
---|
public static BigDecimalAssert assertThat(BigDecimal actual)
BigDecimalAssert
.
actual
- the actual value.
public static BooleanAssert assertThat(boolean actual)
BooleanAssert
.
actual
- the actual value.
public static BooleanAssert assertThat(Boolean actual)
BooleanAssert
.
actual
- the actual value.
public static BooleanArrayAssert assertThat(boolean[] actual)
BooleanArrayAssert
.
actual
- the actual value.
public static ImageAssert assertThat(BufferedImage actual)
ImageAssert
. To read an image from the file system use
ImageReader.readImageFrom(String)
.
actual
- the actual value.
public static ByteAssert assertThat(byte actual)
ByteAssert
.
actual
- the actual value.
public static ByteAssert assertThat(Byte actual)
ByteAssert
.
actual
- the actual value.
public static ByteArrayAssert assertThat(byte[] actual)
ByteArrayAssert
.
actual
- the actual value.
public static CharacterAssert assertThat(char actual)
CharacterAssert
.
actual
- the actual value.
public static CharArrayAssert assertThat(char[] actual)
CharArrayAssert
.
actual
- the actual value.
public static CharacterAssert assertThat(Character actual)
CharacterAssert
.
actual
- the actual value.
public static IterableAssert assertThat(Iterable<?> actual)
IterableAssert
.
actual
- the actual value.
public static DoubleAssert assertThat(double actual)
DoubleAssert
.
actual
- the actual value.
public static DoubleAssert assertThat(Double actual)
DoubleAssert
.
actual
- the actual value.
public static DoubleArrayAssert assertThat(double[] actual)
DoubleArrayAssert
.
actual
- the actual value.
public static FileAssert assertThat(File actual)
FileAssert
.
actual
- the actual value.
public static InputStreamAssert assertThat(InputStream actual)
InputStreamAssert
.
actual
- the actual value.
public static FloatAssert assertThat(float actual)
FloatAssert
.
actual
- the actual value.
public static FloatAssert assertThat(Float actual)
FloatAssert
.
actual
- the actual value.
public static FloatArrayAssert assertThat(float[] actual)
FloatArrayAssert
.
actual
- the actual value.
public static IntegerAssert assertThat(int actual)
IntegerAssert
.
actual
- the actual value.
public static IntArrayAssert assertThat(int[] actual)
IntArrayAssert
.
actual
- the actual value.
public static IntegerAssert assertThat(Integer actual)
IntegerAssert
.
actual
- the actual value.
public static ListAssert assertThat(List<?> actual)
ListAssert
.
actual
- the actual value.
public static LongAssert assertThat(long actual)
LongAssert
.
actual
- the actual value.
public static LongAssert assertThat(Long actual)
LongAssert
.
actual
- the actual value.
public static LongArrayAssert assertThat(long[] actual)
LongArrayAssert
.
actual
- the actual value.
public static ObjectAssert assertThat(Object actual)
ObjectAssert
.
actual
- the actual value.
public static ObjectArrayAssert assertThat(Object[] actual)
ObjectArrayAssert
.
actual
- the actual value.
public static MapAssert assertThat(Map<?,?> actual)
MapAssert
.
actual
- the actual value.
public static ShortAssert assertThat(short actual)
ShortAssert
.
actual
- the actual value.
public static ShortAssert assertThat(Short actual)
ShortAssert
.
actual
- the actual value.
public static ShortArrayAssert assertThat(short[] actual)
ShortArrayAssert
.
actual
- the actual value.
public static StringAssert assertThat(String actual)
StringAssert
.
actual
- the actual value.
public static DateAssert assertThat(Date actual)
DateAssert
.
actual
- the actual value.
public static ThrowableAssert assertThat(Throwable actual)
ThrowableAssert
.
actual
- the actual value.
public static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)
Fail.setRemoveFestRelatedElementsFromStackTrace(boolean)
so that Assertions offers a full
feature entry point to all Fest Assert features (but you can use Fail
if you prefer).
public static void fail(String failureMessage)
Fail.fail(String)
so that Assertions offers a full feature entry point to all Fest Assert
features (but you can use Fail if you prefer).
public static void fail(String failureMessage, Throwable realCause)
Fail.fail(String, Throwable)
so that Assertions offers a full feature entry point to all
Fest Assert features (but you can use Fail if you prefer).
public static void failBecauseExceptionWasNotThrown(Class<? extends Exception> exceptionClass)
Fail.failBecauseExceptionWasNotThrown(Class)
so that Assertions offers a full feature
entry point to all Fest Assert features (but you can use Fail if you prefer).
public static Properties extractProperty(String propertyName)
Properties.extractProperty(String)
so that Assertions offers a full feature entry point to
all Fest Assert features (but you can use Properties
if you prefer).
Typical usage is to chain extractProperty
with from
method, see examples below :
// extract simple property values having a java standard type (here String) assertThat(extractProperty("name").from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", "Frodo", "Legolas") .doesNotContain("Sauron", "Elrond"); // extracting property works also with user's types (here Race) 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");
public static MapEntry entry(Object key, Object value)
MapEntry.entry(Object, Object)
so that Assertions offers a full feature entry point to all
Fest Assert features (but you can use MapEntry
if you prefer).
Typical usage is to call entry
in MapAssert contains
assertion, see examples below :
assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
public static Index atIndex(int index)
Index.atIndex(int)
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Index
if you prefer).
Typical usage :
ListelvesRings = list(vilya, nenya, narya); assertThat(elvesRings).contains(vilya, atIndex(0)).contains(nenya, atIndex(1)).contains(narya, atIndex(2));
public static Offset<Double> offset(Double value)
Offset.offset(Double)
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Offset
if you prefer).
Typical usage :
assertThat(8.1).isEqualTo(8.0, offset(0.1));
public static Offset<Float> offset(Float value)
Offset.offset(Float)
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Offset
if you prefer).
Typical usage :
assertThat(8.2f).isEqualTo(8.0f, offset(0.2f));
public static <T> Condition<T> anyOf(Condition<T>... conditions)
AnyOf.anyOf(Condition...)
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use AnyOf
if you prefer).
Typical usage (jedi
and sith
are Condition
) :
assertThat("Vader").is(anyOf(jedi, sith));
public static <T> Condition<T> anyOf(Collection<Condition<T>> conditions)
AnyOf
T
- the type of object the given condition accept.conditions
- the conditions to evaluate.
AnyOf
.
NullPointerException
- if the given collection is null
.
NullPointerException
- if any of the elements in the given collection is null
.public static <E> Filters<E> filter(E[] array)
Filters.filter(Object[])
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Filters
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);
public static <E> Filters<E> filter(Iterable<E> iterableToFilter)
Filters.filter(Object[])
so that Assertions offers a full feature entry point to all Fest
Assert features (but you can use Filters
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);
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |