Class Assertions
For example:
int removed = employees.removeFired();assertThat(removed).isZero(); List<Employee> newEmployees = employees.hired(TODAY);assertThat(newEmployees).hasSize(6);
- Author:
- Alex Ruiz, Yvonne Wang, David DIDIER, Ted Young, Joel Costigliola, Matthieu Baechler, Mikhail Mazursky, Nicolas François
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Condition<T>Creates a newAllOfstatic <T> Condition<T>Creates a newAllOfstatic <T> Condition<T>Creates a newAnyOfstatic <T> Condition<T>Only delegate toAnyOf.anyOf(Condition...)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useAnyOfif you prefer).static BooleanAssertassertThat(boolean actual) Creates a new instance of.BooleanAssertstatic BooleanArrayAssertassertThat(boolean[] actual) Creates a new instance of.BooleanArrayAssertstatic ByteAssertassertThat(byte actual) Creates a new instance of.ByteAssertstatic ByteArrayAssertassertThat(byte[] actual) Creates a new instance of.ByteArrayAssertstatic CharacterAssertassertThat(char actual) Creates a new instance of.CharacterAssertstatic CharArrayAssertassertThat(char[] actual) Creates a new instance of.CharArrayAssertstatic DoubleAssertassertThat(double actual) Creates a new instance of.DoubleAssertstatic DoubleArrayAssertassertThat(double[] actual) Creates a new instance of.DoubleArrayAssertstatic FloatAssertassertThat(float actual) Creates a new instance of.FloatAssertstatic FloatArrayAssertassertThat(float[] actual) Creates a new instance of.FloatArrayAssertstatic IntegerAssertassertThat(int actual) Creates a new instance of.IntegerAssertstatic IntArrayAssertassertThat(int[] actual) Creates a new instance of.IntArrayAssertstatic LongAssertassertThat(long actual) Creates a new instance of.LongAssertstatic LongArrayAssertassertThat(long[] actual) Creates a new instance of.LongArrayAssertstatic ShortAssertassertThat(short actual) Creates a new instance of.ShortAssertstatic ShortArrayAssertassertThat(short[] actual) Creates a new instance of.ShortArrayAssertstatic FileAssertassertThat(File actual) Creates a new instance of.FileAssertstatic InputStreamAssertassertThat(InputStream actual) Creates a new instance of.InputStreamAssertstatic BooleanAssertassertThat(Boolean actual) Creates a new instance of.BooleanAssertstatic ByteAssertassertThat(Byte actual) Creates a new instance of.ByteAssertstatic CharacterAssertassertThat(Character actual) Creates a new instance of.CharacterAssertstatic DoubleAssertassertThat(Double actual) Creates a new instance of.DoubleAssertstatic FloatAssertassertThat(Float actual) Creates a new instance of.FloatAssertstatic IntegerAssertassertThat(Integer actual) Creates a new instance of.IntegerAssertstatic <T> IterableAssert<T>assertThat(Iterable<T> actual) Creates a new instance of.IterableAssertstatic LongAssertassertThat(Long actual) Creates a new instance of.LongAssertstatic ShortAssertassertThat(Short actual) Creates a new instance of.ShortAssertstatic StringAssertassertThat(String actual) Creates a new instance of.StringAssertstatic ThrowableAssertassertThat(Throwable actual) Creates a new instance of.ThrowableAssertstatic BigDecimalAssertassertThat(BigDecimal actual) Creates a new instance of.BigDecimalAssertstatic DateAssertassertThat(Date actual) Creates a new instance of.DateAssertstatic <T> ListAssert<T>assertThat(List<T> actual) Creates a new instance of.ListAssertstatic <K,V> MapAssert<K, V> assertThat(Map<K, V> actual) Creates a new instance of.MapAssertstatic <T> ObjectAssert<T>assertThat(T actual) Creates a new instance of.ObjectAssertstatic <T> ObjectArrayAssert<T>assertThat(T[] actual) Creates a new instance of.ObjectArrayAssertstatic IndexatIndex(int index) Only delegate toIndex.atIndex(int)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useIndexif you prefer).static StringLoads the text content of a file with the default character set, so that it can be passed toassertThat(String).static StringLoads the text content of a file, so that it can be passed toassertThat(String).static StringLoads the text content of a file, so that it can be passed toassertThat(String).static <T> DoesNotHave<T>doesNotHave(Condition<? super T> condition) Creates a newDoesNotHave.static MapEntryOnly delegate toMapEntry.entry(Object, Object)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useMapEntryif you prefer).static Properties<Object>extractProperty(String propertyName) Only delegate toProperties.extractProperty(String)so that Assertions offers a full feature entry point to all Fest Assert features (but you can usePropertiesif you prefer).static <T> Properties<T>extractProperty(String propertyName, Class<T> propertyType) Only delegate toProperties.extractProperty(String)so that Assertions offers a full feature entry point to all Fest Assert features (but you can usePropertiesif you prefer).static voidOnly delegate toFail.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 voidOnly delegate toFail.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 voidfailBecauseExceptionWasNotThrown(Class<? extends Exception> exceptionClass) Only delegate toFail.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 <E> Filters<E>filter(E[] array) Only delegate toFilters.filter(Object[])so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFiltersif you prefer).static <E> Filters<E>Only delegate toFilters.filter(Object[])so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFiltersif you prefer).static <T> Not<T>Creates a newNot.Only delegate toOffset.offset(Double)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useOffsetif you prefer).Only delegate toOffset.offset(Float)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useOffsetif you prefer).static voidsetRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace) Only delegate toFail.setRemoveFestRelatedElementsFromStackTrace(boolean)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFailif you prefer).
-
Constructor Details
-
Assertions
protected Assertions()Creates a newAssertions.
-
-
Method Details
-
assertThat
Creates a new instance of.BigDecimalAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.BooleanArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ByteArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.CharacterAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IterableAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DoubleAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DoubleArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FileAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.InputStreamAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.FloatArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.IntegerAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ListAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.LongArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ObjectAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ObjectArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.MapAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ShortArrayAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.StringAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.DateAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
-
assertThat
Creates a new instance of.ThrowableAssert- Parameters:
actual- the actual value.- Returns:
- the created assertion Throwable.
-
setRemoveFestRelatedElementsFromStackTrace
public static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace) Only delegate toFail.setRemoveFestRelatedElementsFromStackTrace(boolean)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFailif you prefer). -
fail
Only delegate toFail.fail(String)so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer). -
fail
Only delegate toFail.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). -
failBecauseExceptionWasNotThrown
Only delegate toFail.failBecauseExceptionWasNotThrown(Class)so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer). -
extractProperty
Only delegate toProperties.extractProperty(String)so that Assertions offers a full feature entry point to all Fest Assert features (but you can usePropertiesif you prefer).Typical usage is to chain
extractPropertywithfrommethod, 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"); -
extractProperty
Only delegate toProperties.extractProperty(String)so that Assertions offers a full feature entry point to all Fest Assert features (but you can usePropertiesif you prefer).Typical usage is to chain
extractPropertywithfrommethod, 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"); -
entry
Only delegate toMapEntry.entry(Object, Object)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useMapEntryif you prefer).Typical usage is to call
entryin MapAssertcontainsassertion, see examples below :assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
-
atIndex
Only delegate toIndex.atIndex(int)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useIndexif you prefer).Typical usage :
List
elvesRings = newArrayList(vilya, nenya, narya); assertThat(elvesRings).contains(vilya, atIndex(0)).contains(nenya, atIndex(1)).contains(narya, atIndex(2)); -
offset
Only delegate toOffset.offset(Double)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useOffsetif you prefer).Typical usage :
assertThat(8.1).isEqualTo(8.0, offset(0.1));
-
offset
Only delegate toOffset.offset(Float)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useOffsetif you prefer).Typical usage :
assertThat(8.2f).isEqualTo(8.0f, offset(0.2f));
-
allOf
Creates a newAllOf- 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.
-
allOf
Creates a newAllOf- 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.
-
anyOf
Only delegate toAnyOf.anyOf(Condition...)so that Assertions offers a full feature entry point to all Fest Assert features (but you can useAnyOfif you prefer).Typical usage (
jediandsithareCondition) :assertThat("Vader").is(anyOf(jedi, sith)); -
anyOf
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
Creates a newDoesNotHave.- Parameters:
condition- the condition to inverse.- Returns:
- The Not condition created.
-
not
Creates a newNot.- Parameters:
condition- the condition to inverse.- Returns:
- The Not condition created.
-
filter
Only delegate toFilters.filter(Object[])so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFiltersif you prefer).Note that the given array is not modified, the filters are performed on an
Iterablecopy 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); -
filter
Only delegate toFilters.filter(Object[])so that Assertions offers a full feature entry point to all Fest Assert features (but you can useFiltersif you prefer).Note that the given
Iterableis 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); -
contentOf
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.org.fest.util.FilesException- if an I/O exception occurs.
-
contentOf
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.org.fest.util.FilesException- if an I/O exception occurs.
-
contentOf
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:
org.fest.util.FilesException- if an I/O exception occurs.
-